My paypal sdk version is ^1.13
I'm having errors in my paypal implementation. I followed this tutorial https://www.youtube.com/watch?v=BD1dOWIABe0
<?php
require 'vendor/autoload.php';
use PayPal\Api\Payer;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Amount;
use PayPal\Api\Transaction;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Payment;
use PayPal\Api\Details;
use PayPal\Rest\ApiContext;
Use PayPal\Auth\OAuthTokenCredential;
if(!isset($_POST['product'], $_POST['price'])){
die();
}
$clientId = 'client-id';
$clientSecret = 'client-secret';
$apiContext = new ApiContext(
new OAuthTokenCredential(
$clientId,
$clientSecret
)
);
$product = $_POST['product'];
$price = $_POST['price'];
$tax = 2.00;
$total = $price + $tax;
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$item = new Item();
$item->setName($product)
->setCurrency('USD')
->setQuantity(1)
->setPrice($price);
$itemList = new ItemList();
$itemList->setItems([$item]);
$details = new Details();
$details->setShipping($tax)
->setSubtotal($price)
->setTax(2.00);
$amount = new Amount();
$amount->setCurrency('USD')
->setTotal($total)
->setDetails($product);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($itemList)
->setDescription('dsds')
->setInvoiceNumber(uniqid());
$baseUrl = "http://www.localhost/xc";
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("$baseUrl/pay.php?success=true")
->setCancelUrl("$baseUrl/pay.php?success=false");
$payment = new Payment();
$payment->setIntent('sale')
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions([$transaction]);
try{
$payment->create($apiContext);
}
catch(PayPal\Exception\PayPalConnectionException $ex){
echo $ex;
die($ex);
}
echo $approvalUral = $payment->getApprovalLink();
I've tried to search about the error but I can't seem to find an answer so I need some help. What have I done wrong ? Do I need to downgrade ? because the video in tutorial made 2 years ago so I think I need to downgrade but is it possible ?
exception 'PayPal\Exception\PayPalConnectionException' with message 'Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment.' in C:\xampp\htdocs\ladea\vendor\paypal\rest-api-sdk-php\lib\PayPal\Core\PayPalHttpConnection.php:202
Stack trace:
#0 C:\xampp\htdocs\ladea\vendor\paypal\rest-api-sdk-php\lib\PayPal\Transport\PayPalRestCall.php(78): PayPal\Core\PayPalHttpConnection->execute('{"intent":"sale...')
#1 C:\xampp\htdocs\ladea\vendor\paypal\rest-api-sdk-php\lib\PayPal\Common\PayPalResourceModel.php(104): PayPal\Transport\PayPalRestCall->execute(Array, '/v1/payments/pa...', 'POST', '{"intent":"sale...', NULL)
#2 C:\xampp\htdocs\ladea\vendor\paypal\rest-api-sdk-php\lib\PayPal\Api\Payment.php(577): PayPal\Common\PayPalResourceModel::executeCall('/v1/payments/pa...', 'POST', '{"intent":"sale...', NULL, Object(PayPal\Rest\ApiContext), NULL)
#3 C:\xampp\htdocs\ladea\checkout.php(78): PayPal\Api\Payment->create(Object(PayPal\Rest\ApiContext))
#4 {main}exception 'PayPal\Exception\PayPalConnectionException' with message 'Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment.' in C:\xampp\htdocs\ladea\vendor\paypal\rest-api-sdk-php\lib\PayPal\Core\PayPalHttpConnection.php:202 Stack trace: #0 C:\xampp\htdocs\ladea\vendor\paypal\rest-api-sdk-php\lib\PayPal\Transport\PayPalRestCall.php(78): PayPal\Core\PayPalHttpConnection->execute('{"intent":"sale...') #1 C:\xampp\htdocs\ladea\vendor\paypal\rest-api-sdk-php\lib\PayPal\Common\PayPalResourceModel.php(104): PayPal\Transport\PayPalRestCall->execute(Array, '/v1/payments/pa...', 'POST', '{"intent":"sale...', NULL) #2 C:\xampp\htdocs\ladea\vendor\paypal\rest-api-sdk-php\lib\PayPal\Api\Payment.php(577): PayPal\Common\PayPalResourceModel::executeCall('/v1/payments/pa...', 'POST', '{"intent":"sale...', NULL, Object(PayPal\Rest\ApiContext), NULL) #3 C:\xampp\htdocs\ladea\checkout.php(78): PayPal\Api\Payment->create(Object(PayPal\Rest\ApiContext)) #4 {main}
Thank you and Regards.