chitzui
chitzui

Reputation: 4098

How to know if Paypal transaction was successful using the API?

I try to integrate PayPal into my checkout process. Here is what I did:

  1. I managed to use the Paypal API Node SDK to create payments with PayPal.payment.create.

  2. and then redirecting the user to the payment URL I get in the response to links[1].href which is something like this: "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-00N000849T505604G".

  3. On that page I sing in with my sandbox user and pay the transaction, I get redirected to my custom success page I declared when creating the payment.

  4. On my Success Page, I want now to check if the transaction really was successful to update my database, so I call my backend, that calls a GET to the transaction to the links[0].href which is something like https://api.sandbox.paypal.com/v1/payments/payment/PAY-1VL72645VS000000XLLARPMI to check for the status.

  5. Unfortunately, the state property of the response is always created.

What am I doing wrong? How can I check it? I was using these docs as a reference.

Generally, I’m a bit overwhelmed by the number of docs and not sure which one is correct and could not find any concise tutorial :S

Thanks for your help!

Upvotes: 0

Views: 3490

Answers (1)

Mohammad Ali Rony
Mohammad Ali Rony

Reputation: 4905

State property of the response is created is the current one.

The state property's possible values created, approved, failed.

created. The transaction was successfully created.

approved. The customer approved the transaction.

failed. The transaction request failed.

but approved. should be The buyer( not customer) approved the transaction.

You can get this from Payment.php file in line #376 of PayPal-PHP-SDK project.

https://github.com/paypal/PayPal-PHP-SDK/blob/master/lib/PayPal/Api/Payment.php

At first State property will created but it will be approved when The buyer approved the transaction using Update payment then you can check List payments /Show payment details then you will found payment is now approved.

For Update payment https://developer.paypal.com/docs/api/payments/#payment_update

and Show payment details https://developer.paypal.com/docs/api/payments/#payment_get

Upvotes: 1

Related Questions