Search code examples
node.jspaypalpaypal-sandboxpaypal-rest-sdk

paypal rest sdk - cancel a payment gives only token


so i've seen some question about this subject but no good answer

after creating a paypal payment via paypal api, the client is being redirected to paypal for payment approval the payment object also gets a "approved" and "cancelled" urls so that paypal could let my server know what course of action took place within the client's approval process

if the client has cancelled the payment, the http request being sent from paypal looks like this: /customerCancelled?token=EC-32W183225U612050A when "customerCancelled" is a get method in my server of course

what paypal claims should be done here is just to cancel the payment in my DB because they already cancel it on theirs

the problem is here - what the hack is this token? its not the paymentID (which is the primary key of the payments in my database) how does it help me identifying the payment object that was canceled?

it takes a lot of time until paypal answers questions.. so if anyone here has got a clue that would be helpful

thanks


Solution

  • I have discovered it. When you enter the cancel URL first you have to ask for access token (if you dont have it stored), then get the payment information (here you can see) and the response contains a cart value, the cart value is same that the token without EC-, I mean, if cart value is 1234567890 the token you have is EC-1234567890.

    When you create the payment store in your database (or elsewhere) the payment id, cart value and the final token. Then on cancel you search the cart value in your database and you obtain the Payment ID.

    Did I explain?