it's some days that i am trying to solve a paypal issue. I'm working with the PayPal PHP SDK, my envoirment is a Linux Server (Ubuntu 16) with Php 7.2 installed and running Laravel 5.6.
I installed through composer the paypal php sdk and i integrated 'successfuly' in the code. When i try to run the code, i get back the link for make the payment (usually where u redirect the user) so it's working fine, no problem about the first request or api credential.
The problem is that, if you go to the pay link and i made the payment, it will redirect the payer to the success page of my website but i am not getting any transaction in my account (the buyer and the reciver) and also i am not getting any webhook or IPN notify (also like, user have to money or user profile is not verified, just nothing).
What i already tryed:
This is my code (but i don't think the problem is this one):
$_api_context = new ApiContext(new OAuthTokenCredential(
'CLIENT_ID','SECRET'));
$_api_context->setConfig(array(
'mode' => env('PAYPAL_MODE', 'sandbox'),
'log.LogEnabled' => true,
'log.FileName' => 'PayPal.log',
'log.LogLevel' => 'DEBUG'
));
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$item_1 = new Item();
$item_1->setName('Item 1') /** item name **/
->setCurrency('USD')
->setQuantity(1)
->setPrice('3'); /** unit price **/
$item_list = new ItemList();
$item_list->setItems(array($item_1));
$amount = new Amount();
$amount->setCurrency('USD')
->setTotal('3');
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($item_list)
->setDescription('Your transaction description');
$redirect_urls = new RedirectUrls();
$redirect_urls->setReturnUrl('https://XXXXXXX.ngrok.io/success') /** Specify return URL **/
->setCancelUrl('https://XXXXX.ngrok.io/error');
$payment = new Payment();
$payment->setIntent('Sale')
->setPayer($payer)
->setRedirectUrls($redirect_urls)
->setTransactions(array($transaction));
//dd($payment);
try {
$payment->create($_api_context);
} catch (\PayPal\Exception\PPConnectionException $ex) {
dd($ex);
}
foreach ($payment->getLinks() as $link) {
if ($link->getRel() == 'approval_url') {
$redirect_url = $link->getHref();
break;
}
}
$approvalUrl = $payment->getApprovalLink();
dd($redirect_url,$_api_context,$paypal,$paymentGateway,$approvalUrl,$payment->getId());
UPDATE
I tryed to sent money form sandbox account (personal) to the business account that own the api, and the ipn is working correctly.
对于任何有同样问题的人,您应该在用户重定向到您的成功页面后执行付款。
I did not find where you set post request send your server to save your transactions. Try like this way .. code..
<script>
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '{{$form_data->net_amount}}'
}
}]
});
},
onApprove: function(data, actions) {
console.log('data');
console.log(data);
return actions.order.capture().then(function(details) {
console.log(details);
alert('Transaction completed by ' + details.payer.name.given_name);
// Call your server to save the transaction
return fetch('/paypal-transaction-complete', {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
orderID: data.orderID,
userDetail: details,
bookingId: '{{$form_data->id}}',
_token: '{{csrf_token()}}'
})
}).then(function(){
location.reload();
});
});
}
}).render('#paypal-button-container');
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.