1

After I complete payment with paypal express and my database update fail, what I can do in that case?

Here is code:

    $transaction = $this->initPayPalExpress()->completePurchase($this->param);
    $response = $transaction->send();
    $data = $response->getData();
    if (isset($data['PAYMENTINFO_0_ACK']) && $data['PAYMENTINFO_0_ACK'] === 'Success') {
      $this->updateDatabase($data);
    }
Vladimir Djukic
  • 2,042
  • 7
  • 29
  • 60
  • please print your update function and response data if possible – CodeIsLife Feb 13 '16 at 19:27
  • For update function I just store data into MySQL db. For respose I get all details that show transaction is finished. Problem is data in databas will not update if for example user close browser when this function should run: `$this->updateDatabase($data);` – Vladimir Djukic Feb 13 '16 at 19:31
  • even if the user close the browser !, it's server side processing so closing browser wont prevent transaction execution – CodeIsLife Feb 13 '16 at 19:33
  • So update can't fail? I think session will be destroyed and it will fail – Vladimir Djukic Feb 13 '16 at 19:36
  • no ! update can't fail and the session is also a server side file, so your code block will never be interrupted by a client side action – CodeIsLife Feb 13 '16 at 19:55

2 Answers2

0

I recommend that you switch from PayPal express to PayPal REST. That is newer and has better documentation.

In terms of what to do if your database update fails, then I suggest you will need to have some kind of backup plan -- you can use the RestListPurchaseRequest() message to check through your purchase history.

You ask about refunding, but don't give a refund example -- what is the exact nature of your issue?

There are some good examples in the docblocks of the omnipay-paypal REST messages and gateway to achieve what you want to do I think.

delatbabel
  • 3,601
  • 24
  • 29
0

If you are working with payment gateways don't rely on session data to store information you will use to link the payment back to the user. Instead, since the user is paying for something there must be an orders/subscriptions table or even just the the user's id itself. So you can pass that identifying information to PayPal in the custom fields you're allowed to pass and then in the redirects/callbacks you can do something like (not Omnipay code, but it illustrates the point):

$response = GetExpressCheckoutDetails( $_REQUEST['token'] );
$orderID = $response["PAYMENTREQUEST_0_CUSTOM"];

This way you can complete the transaction whether or not the user has an active session; and if your database fails, you don't have to refund the customer because the problem is not on their end but yours. You're better off catching the database failure and have the script log or email a note telling you so and so paid successfully but the database failed - and you manually fulfil the purchase.

Sam
  • 2,540
  • 2
  • 23
  • 24