I am using paypal php sdk. I have the following code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require __DIR__ . '/vendor/PayPal-PHP-SDK/autoload.php';
$dev_ClientID = 'xxxxxxxxxx';
$dev_ClientSecret = 'xxxxxxxxxx';
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
$dev_ClientID
,$dev_ClientSecret
)
);
$payer = new \PayPal\Api\Payer();
$payer->setPaymentMethod('paypal');
$amount = new \PayPal\Api\Amount();
$amount->setTotal('1.00');
$amount->setCurrency('USD');
$transaction = new \PayPal\Api\Transaction();
$transaction->setAmount($amount);
$redirectUrls = new \PayPal\Api\RedirectUrls();
$redirectUrls->setReturnUrl("https://www.somedomain.com/paypal_success.php")
->setCancelUrl("https://www.somedomain.com/paypal_cancel.php");
// Create the WebProfile
$presentation = new \PayPal\Api\Presentation();
$presentation->setLogoImage("http://www.yeowza.com/favico.ico")
->setBrandName("YeowZa! Paypal")
->setLocaleCode("US");
$inputfields = new \PayPal\Api\InputFields();
$inputfields ->getNoShipping(1);
$webProfile = new \PayPal\Api\WebProfile();
$webProfile
->setName('somename' . uniqid())
->setInputFields($inputfields)
->setTemporary(true);
$webProfileId = $webProfile->create($apiContext)->getId();
$payment = new \PayPal\Api\Payment();
$payment->setExperienceProfileId($webProfileId);
$payment->setIntent('sale')
->setPayer($payer)
->setTransactions(array($transaction))
->setRedirectUrls($redirectUrls);
try {
$payment->create($apiContext);
echo "\n\nRedirect user to approval_url: " . $payment->getApprovalLink() . "\n";
}
catch (\PayPal\Exception\PayPalConnectionException $ex) {
// This will print the detailed information on the exception.
echo $ex->getData();
}
?>
I get the payment link but i still see the shipping info.
I have defined getNoShipping to true, maybe hooked web profile wrong. So thats one thing. The second thing I am not sure about is this.
I passed a payment and got redirected back to paypal_success.php with paymentId, token and PayerID. How would I use these to receive info about the transaction. I wish to make sure it actually occured.
I tried the following:
$paymentId = $_GET["paymentId"];
$token = $_GET["token"];
$PayerID = $_GET["PayerID"];
echo "paymentId: " . $paymentId . "<br>";
echo "token: " .$token . "<br>";
echo "PayerID: " .$PayerID . "<br>";
$curl = curl_init("https://api.sandbox.paypal.com/v1/checkout/orders/$paymentId");
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $token,
'Accept: application/json',
'Content-Type: application/json'
));
$response = curl_exec($curl);
$result = json_decode($response);
var_dump($result);
with the following result:
{ ["error"]=> string(13) "invalid_token" ["error_description"]=> string(35) "Token signature verification failed" }
Will appreciate any help rendered. Thanks
You can get the payment details using following call
$payment_details = PayPal\Api\Payment::get($paymentId, $apiContext);
Here $apiContext
is your api credentials that you have used to make transaction.
Also if you want to use curl then this following endpoint
$curl = curl_init("https://api.sandbox.paypal.com/v1/checkout/orders/$paymentId");
is not correct to get payment details, rather you should use this endpoint $curl = curl_init("https://api.sandbox.paypal.com/v1/payments/payment/$paymentId");