Paypal-rest-starting-guide
Using Paypal Rest processor (PR) is very similar to older Paypal processor (PP), thus switch from the older to newer version should not be a problem. All the differences should take place in the backend of payment app, because of the change of old paypal NVP api to the new rest api.
Here is the list of common calls:
1. transaction.init
request:
{ "c": "api", "a": ".json", "cmd": "transaction.init", "data": { "tracking_company": "1", "tracking_user": "18080627", "tracking_tag": "3213", "zipcode": "85035", "country": "US", "email": "dogj0490@gmail.com", "first_name": "rino692u", "last_name": "", "ip": "172.69.34.183", "host": "172.69.34.183", "currency": "USD", "pp_type": "PR", "tax_rate": "0", "tax_amount": "0", "items": [ { "tracking_item": "186", "amount": "29.99", "description": "$3.49 5 Day trial rebills at $29.99 per month*", "rebill_unit": "month", "rebill_period": "1", "trial_amount": "3.49", "trial_unit": "day", "trial_period": "5", "max_rebill_count": "-1" } ], "order_type": "", "cancel_url": "https:\/\/www.cosplaydatingsite.com\/payment\/cancel", "return_url": "https:\/\/www.cosplaydatingsite.com\/payment\/finish" }, "ptnr_id": "1", "token": "<partner_token>", "pass": "<partner_password>" }
response:
{ "code": 700, "status": "Action completed successfully", "command": "transaction.init", "result": { "hash": "161252520590129a48aad3ebd1e603a0", "redirect": "https:\/\/www.paypal.com\/webapps\/billing\/subscriptions?ba_token=BA-25032222MM8175034" }, "request": { "cmd": "transaction.init", "data": { "tracking_company": "1", "tracking_user": "18080627", "tracking_tag": "3213", "zipcode": "85035", "country": "US", "email": "dogj0490@gmail.com", "first_name": "rino692u", "last_name": "", "ip": "172.69.34.183", "host": "172.69.34.183", "currency": "USD", "pp_type": "PR", "tax_rate": "0", "tax_amount": "0", "items": [ { "tracking_item": "186", "amount": "29.99", "description": "$3.49 5 Day trial rebills at $29.99 per month*", "rebill_unit": "month", "rebill_period": "1", "trial_amount": "3.49", "trial_unit": "day", "trial_period": "5", "max_rebill_count": "-1" } ], "order_type": "", "cancel_url": "https:\/\/www.cosplaydatingsite.com\/payment\/cancel", "return_url": "https:\/\/www.cosplaydatingsite.com\/payment\/finish" }, "token": "<partner_token>", "pass": "<partner_password>" }, "ts": 1612525206, "origin_ip": "10.3.3.35", "errors": null }
2. transaction.finish
request:
{ "c": "api", "a": ".json", "cmd": "transaction.finish", "data": { "pp_type": "pr", "hash": "16125250428952274a271d211a24edad" }, "ptnr_id": "1", "token": "<partner_token>", "pass": "<partner_password>" }
response:
{ "code": 700, "status": "Action completed successfully", "command": "transaction.finish", "result": { "success": true, "payment_tran_id": 177184973, "items_data": [ { "item_id": "77879453", "order_id": "77844313", "tracking_item": "157" } ] }, "request": { "cmd": "transaction.finish", "data": { "pp_type": "pr", "hash": "16125250428952274a271d211a24edad" }, "token": "<partner_token>", "pass": "<partner_password>" }, "ts": 1612525106, "origin_ip": "10.3.3.35", "errors": null }
3. transaction.refund
request:
{ "c": "api", "a": ".json", "cmd": "transaction.refund", "data": { "sub_id": "32351833", "tran_id": "177120903", "pp_type": "PR", "limit": "50" }, "ptnr_id": "1", "token": "<partner_token>", "pass": "<partner_password>" }
response:
{ "code": 700, "status": "Action completed successfully", "command": "transaction.refund", "result": { "success": true, "tran_id": 177148543 }, "request": { "cmd": "transaction.refund", "data": { "sub_id": "32351833", "tran_id": "177120903", "pp_type": "PR", "limit": "50" }, "token": "<partner_token>", "pass": "<partner_password>" }, "ts": 1612496456, "origin_ip": "10.3.3.19", "errors": null
}
4. subscription.cancel
request:
{ "c": "api", "a": ".json", "cmd": "subscription.cancel", "data": { "sub_id": "32364543", "tran_id": "1", "pp_type": "PR", "passback": { "flags": [ "skip_subscription_stopped_notification" ] }, "limit": "50" }, "ptnr_id": "1", "token": "<partner_token>", "pass": "<partner_password>"
}
response:
{ "code": 700, "status": "Action completed successfully", "command": "subscription.cancel", "result": { "success": true }, "request": { "cmd": "subscription.cancel", "data": { "sub_id": "32364543", "tran_id": "1", "pp_type": "PR", "passback": { "flags": [ "skip_subscription_stopped_notification" ] }, "limit": "50" }, "token": "<partner_token>", "pass": "<partner_password>" }, "ts": 1612525888, "origin_ip": "10.3.3.174", "errors": null
}
A little bit more about process of creating subscriptions and misleading naming of payment api calls:
-you call a pair of method transaction.create / transaction.finish only when you want to create new subscription
-you don't call transaction.create otherwise, you don't need to inform payment about new transactions. We know about them directly from paypal, because we have listener and receive their notifications, moreover we send you payment notifications about such events as usual
Basic description of the process of creating subscription from the client side:
- call transaction.init, apart from usual subscription data specify return_url and cancel_url. They are used for paypal process purpose. In a nutshell:
-when user creates successfully subscripton on paypal side there's going to be redirection to return_url link
-when an error occures during process of creating subscription or user cancels the process there's going to be redirection to cancel_url link
- for successful transaction.init in the response you are given redirect url. Redirect user to it. After that the user needs to login to paypal account and confirm subscription
- After successful subscription confirmation by the user paypal redirects back to return_url. Just end the whole process by calling transaction.finish
- Last Author
- adzida
- Last Edited
- Feb 5 2021, 07:28