New member
- Joined
- Feb 14, 2023
- Messages
- 7
- Thread Author
- #1
Developed PHP Paypal Integration via REST API. when creating payment intent to get url to redirect user to Payment gateway it works fine. I get the redirect url as well. Example redirect url live mode
https://www.paypal.com/checkoutnow?token=7JR976187U6560045
But when we go to Payment page we can select either to logged in to Paypal account or pay as a guest using credit or debit card.
But for the logged in user it shows select the payment source (card) to pay but when we click on proceed or review it always not going to proceed to next step or to thank you page it reload back to same page without showing any error or warning.
This happens in Sandbox mode as well.
When we select pay via Credit card without logging in it it loads the card details entering page but after adding the cart it will not accept the payment and shows card was declined message. Cards has funds. Something happening in Sandbox with test card details.
below is sample code used for generate payment intent.
Tried both live mode and sandbox mode.
https://www.paypal.com/checkoutnow?token=7JR976187U6560045
But when we go to Payment page we can select either to logged in to Paypal account or pay as a guest using credit or debit card.
But for the logged in user it shows select the payment source (card) to pay but when we click on proceed or review it always not going to proceed to next step or to thank you page it reload back to same page without showing any error or warning.
This happens in Sandbox mode as well.
When we select pay via Credit card without logging in it it loads the card details entering page but after adding the cart it will not accept the payment and shows card was declined message. Cards has funds. Something happening in Sandbox with test card details.
below is sample code used for generate payment intent.
Code:
//first get the access token
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.paypal.com/v1/oauth2/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "grant_type=client_credentials",
CURLOPT_HTTPHEADER => array(
"Authorization: Basic " . base64_encode(PAYPAL_ID.":".PAYPAL_SECRET),
"Content-Type: application/x-www-form-urlencoded"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
exit();
}
$responseData = json_decode($response);
$accessToken = $responseData->access_token;
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.paypal.com/v2/checkout/orders",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($requestBody),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"Authorization: Bearer $accessToken"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
exit();
}
$responseData = json_decode($response);
//var_dump($responseData);
if ($responseData->status !== 'CREATED') {
echo "Order creation failed: " . $responseData->debug_id;
exit();
}
$orderId = $responseData->id;
$_SESSION['paypal_id'] = $orderId;
$approveUrl = '';
foreach ($responseData->links as $link) {
if ($link->rel === 'approve') {
$approveUrl = $link->href;
break;
}
}
if (!$approveUrl) {
echo "Approve URL not found";
exit();
}
$data_back = array();
$data_back['url'] = $approveUrl;
Tried both live mode and sandbox mode.