################################################################################## # Step 1: Generate temporary token: ################################################################################## curl -v https://api.sandbox.paypal.com/v1/oauth2/token \ -H "Accept: application/json" \ -H "Accept-Language: en_US" \ -u < CLIENT ID : SECRET > \ -d "grant_type=client_credentials" ============= Response: ================== {"scope":"https://uri.paypal.com/services/subscriptions https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/vault/credit-card https://uri.paypal.com/services/applications/webhooks openid https://uri.paypal.com/payments/payouts https://api.paypal.com/v1/vault/credit-card/.*","access_token":"A015ba0xn62km2IkqEsSehs7xPMOQgyIVMtWuGW5Zv14ARg","token_type":"Bearer","app_id":"APP-80W284485P519543T","expires_in":28800} ====== Formatted Response: ================ { "scope": "https://uri.paypal.com/services/subscriptions https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/vault/credit-card https://uri.paypal.com/services/applications/webhooks openid https://uri.paypal.com/payments/payouts https://api.paypal.com/v1/vault/credit-card/.*", "access_token": "A015ba0xn62km2IkqEsSehs7xPMOQgyIVMtWuGW5Zv14ARg", "token_type": "Bearer", "app_id": "APP-80W284485P519543T", "expires_in": 28800 } ################################################################################## # Step 2: Create purchase: ################################################################################## # Note the 'return_url' - this is where the buyer will be sent back to if they # agree to the purchase curl -v https://api.sandbox.paypal.com/v1/payments/payment \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer A015vpl8Vr9LcPEEH8hv1djQCccRDlSiC-F1b7zfKF4KDX8' \ -d '{ "intent":"sale", "redirect_urls":{ "return_url":"http://example.com/your_redirect_url.html", "cancel_url":"http://example.com/your_cancel_url.html" }, "payer":{ "payment_method":"paypal" }, "transactions":[ { "amount":{ "total":"7.47", "currency":"USD" } } ] }' ============= Response: ================== {"id":"PAY-5JP12285BD0771206KVVW2KI","create_time":"2015-05-31T20:20:57Z","update_time":"2015-05-31T20:20:57Z","state":"created","intent":"sale","payer":{"payment_method":"paypal","payer_info":{"shipping_address":{}}},"transactions":[{"amount":{"total":"7.47","currency":"USD","details":{"subtotal":"7.47"}},"related_resources":[]}],"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-5JP12285BD0771206KVVW2KI","rel":"self","method":"GET"},{"href":"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-0F743407G4529964R","rel":"approval_url","method":"REDIRECT"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-5JP12285BD0771206KVVW2KI/execute","rel":"execute","method":"POST"}]} ====== Formatted Response: ================ { "id": "PAY-5JP12285BD0771206KVVW2KI", "create_time": "2015-05-31T20:20:57Z", "update_time": "2015-05-31T20:20:57Z", "state": "created", "intent": "sale", "payer": { "payment_method": "paypal", "payer_info": { "shipping_address": {} } }, "transactions": [ { "amount": { "total": "7.47", "currency": "USD", "details": { "subtotal": "7.47" } }, "related_resources": [] } ], "links": [ { "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-5JP12285BD0771206KVVW2KI", "rel": "self", "method": "GET" }, { "href": "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-0F743407G4529964R", "rel": "approval_url", "method": "REDIRECT" }, { "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-5JP12285BD0771206KVVW2KI/execute", "rel": "execute", "method": "POST" } ] } ################################################################################## # Step 3: Buyer Authorizes the purchase ################################################################################## # Redirect the buyer to the URL listed for the 'approval_url' in order to have PayPal ask them if they actually # consent to this or not # You will need to use a test account in order to actually (pretend to) authorize the purchase ============= Response: ================== # If the buyer does agree (and provides a paypal account, or CC#, etc) # they'll be sent to the return_url, with PayerID and paymentId appended to the URL http://example.com/your_redirect_url.html?paymentId=PAY-1V756927YT704944SKVV54GI&token=EC-7YS96203LB732792U&PayerID=G2DMTMHD2D64E ====== Formatted Response: ================ ################################################################################## # Step 4: Execute the payment ################################################################################## # Note that paymentId gets copied into the URL ### AND ### # PayerID gets copied into the -d "payer_id" field on the last line! curl -v https://api.sandbox.paypal.com/v1/payments/payment/PAY-1V756927YT704944SKVV54GI/execute/ \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer A015vpl8Vr9LcPEEH8hv1djQCccRDlSiC-F1b7zfKF4KDX8' \ -d '{ "payer_id" : "G2DMTMHD2D64E" }' ============= Response: ================== {"id":"PAY-1V756927YT704944SKVV54GI","create_time":"2015-06-01T04:22:49Z","update_time":"2015-06-01T04:37:20Z","state":"approved","intent":"sale","payer":{"payment_method":"paypal","payer_info":{"email":"michpa-buyer@hotmail.com","first_name":"test","last_name":"buyer","payer_id":"G2DMTMHD2D64E","shipping_address":{"line1":"1 Main St","city":"San Jose","state":"CA","postal_code":"95131","country_code":"US","recipient_name":"test buyer"}}},"transactions":[{"amount":{"total":"7.47","currency":"USD","details":{"subtotal":"7.47"}},"related_resources":[{"sale":{"id":"91B16201JL042005R","create_time":"2015-06-01T04:22:49Z","update_time":"2015-06-01T04:37:20Z","amount":{"total":"7.47","currency":"USD"},"payment_mode":"INSTANT_TRANSFER","state":"completed","protection_eligibility":"ELIGIBLE","protection_eligibility_type":"ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE","parent_payment":"PAY-1V756927YT704944SKVV54GI","transaction_fee":{"value":"0.52","currency":"USD"},"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/sale/91B16201JL042005R","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/payments/sale/91B16201JL042005R/refund","rel":"refund","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-1V756927YT704944SKVV54GI","rel":"parent_payment","method":"GET"}]}}]}],"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-1V756927YT704944SKVV54GI","rel":"self","method":"GET"}]} ====== Formatted Response: ================ { "id": "PAY-1V756927YT704944SKVV54GI", "create_time": "2015-06-01T04:22:49Z", "update_time": "2015-06-01T04:37:20Z", "state": "approved", "intent": "sale", "payer": { "payment_method": "paypal", "payer_info": { "email": "michpa-buyer@hotmail.com", "first_name": "test", "last_name": "buyer", "payer_id": "G2DMTMHD2D64E", "shipping_address": { "line1": "1 Main St", "city": "San Jose", "state": "CA", "postal_code": "95131", "country_code": "US", "recipient_name": "test buyer" } } }, "transactions": [ { "amount": { "total": "7.47", "currency": "USD", "details": { "subtotal": "7.47" } }, "related_resources": [ { "sale": { "id": "91B16201JL042005R", "create_time": "2015-06-01T04:22:49Z", "update_time": "2015-06-01T04:37:20Z", "amount": { "total": "7.47", "currency": "USD" }, "payment_mode": "INSTANT_TRANSFER", "state": "completed", "protection_eligibility": "ELIGIBLE", "protection_eligibility_type": "ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE", "parent_payment": "PAY-1V756927YT704944SKVV54GI", "transaction_fee": { "value": "0.52", "currency": "USD" }, "links": [ { "href": "https://api.sandbox.paypal.com/v1/payments/sale/91B16201JL042005R", "rel": "self", "method": "GET" }, { "href": "https://api.sandbox.paypal.com/v1/payments/sale/91B16201JL042005R/refund", "rel": "refund", "method": "POST" }, { "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-1V756927YT704944SKVV54GI", "rel": "parent_payment", "method": "GET" } ] } } ] } ], "links": [ { "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-1V756927YT704944SKVV54GI", "rel": "self", "method": "GET" } ] } ################################################################################## # ################################################################################## ============= Response: ================== ====== Formatted Response: ================ ################################################################################## # ################################################################################## ============= Response: ================== ====== Formatted Response: ================ ################################################################################## # ################################################################################## ============= Response: ================== ====== Formatted Response: ================