EDIT:
As @bluepnume stated probably this is a bug and would be fixed later.
In my case I did the same thing (create payment / execute payment) but on server side with the REST API without using checkout.js
and now everything works fine.
The only difference is that I'm redirecting the client to PayPal (with $payment->getApprovalLink()
) instead of using the on-site lightbox generated by checkout.js
.
Original question:
I integrated PayPal Express Checkout with a Basic Client Integration.
Everything seems fine. The payment completes smoothly and I can view the payment as completed/approved from both Rest API request and Seller's Account (Sandbox).
However the payment is not completed even after successful Execute. I try to make a refund from the API after order cancellation but after reading Payment data successfully I can't receive and Related Resources in payment's transactions.
JS code (works fine):
paypal.Button.render({
env: $form.find('[name="env"]').val(),
client: {
sandbox: $form.find('[name="client_id"]').val(),
production: $form.find('[name="client_id"]').val()
},
locale: 'it_IT',
commit: true, // Optional: show a 'Pay Now' button in the checkout flow
payment: function() {
var env = this.props.env;
var client = this.props.client;
return paypal.rest.payment.create(env, client, {
transactions: [
{
custom: $form.find('[name="custom"]').val(),
amount: {
total: $form.find('[name="subtotal"]').val(),
currency: $form.find('[name="currency_code"]').val()
},
description: $form.find('[name="item_name"]').val(),
}
],
redirect_urls: {
"return_url": $form.find('[name="return"]').val(),
"cancel_url": $form.find('[name="notify_url"]').val()
}
});
},
onAuthorize: function(data, actions) {
return actions.payment.execute().then(function() {
actions.payment.get().then(function(data) {
pjQ.$.post($form.find('[name="notify_url"]').val(), data).done(function (data) {
return actions.redirect();
});
});
});
},
onCancel: function(data, actions) {
return actions.redirect();
}
}, '#paypal-button');
PHP code:
$payment = \PayPal\Api\Payment::get($paymentId, $apiContext); // It's ok
$transactions = $payment->getTransactions(); // It's ok
$relatedResources = $transactions[0]->getRelatedResources(); // Empty...
// I can't use the code below as $relatedResources is empty
$sale = $relatedResources[0]->getSale();
$saleId = $sale->getId();
$sale = new \PayPal\Api\Sale();
$sale->setId($saleId);
$refundedSale = $sale->refundSale($refundRequest, $apiContext);
Any ideas?