I am trying to integrate Paypal Subscriptions via PAYPAL REST API ,using the following documentation
https://developer.paypal.com/docs/subscriptions/integrate/ ( Basic Integration )
Step 1 ( Autorization succesfully )
Step 2 ( Creating Product Successfuly )
Step 3 ( Creating Plan Succesfuly )
Step 4 ( Creating subscription fail )
It look like via Smart Payment Buttons in the JavaScript SDK work . But via REST API
curl -v -k -X POST https://api.sandbox.paypal.com/v1/billing/subscriptions
-H "Accept: application/json"
-H "Authorization: Bearer Access-Token"
-H "PayPal-Request-Id: SUBSCRIPTION-21092020-001"
-H "Prefer: return=representation"
-H "Content-Type: application/json"
-d '{
"plan_id": "P-4ML8771254154362WXNWU5BC",
"start_time": "2020-11-01T00:00:00Z",
"quantity": "20",
"shipping_amount": {
"currency_code": "USD",
"value": "10.00"
},
"subscriber": {
"name": {
"given_name": "John",
"surname": "Doe"
},
"email_address": "[email protected]",
"shipping_address": {
"name": {
"full_name": "John Doe"
},
"address": {
"address_line_1": "2211 N First Street",
"address_line_2": "Building 17",
"admin_area_2": "San Jose",
"admin_area_1": "CA",
"postal_code": "95131",
"country_code": "US"
}
}
},
"application_context": {
"brand_name": "example",
"locale": "en-US",
"shipping_preference": "SET_PROVIDED_ADDRESS",
"user_action": "SUBSCRIBE_NOW",
"payment_method": {
"payer_selected": "PAYPAL",
"payee_preferred": "IMMEDIATE_PAYMENT_REQUIRED"
},
"return_url": "https://example.com/returnUrl",
"cancel_url": "https://example.com/cancelUrl"
}
}'
I get
{"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","debug_id":"ec6f365217c37","details":[{"field":"/name","location":"body","issue":"MISSING_REQUIRED_PARAMETER","description":"A required field is missing."},{"field":"/payment_preferences","location":"body","issue":"MISSING_REQUIRED_PARAMETER","description":"A required field is missing."},{"field":"/billing_cycles","location":"body","issue":"MISSING_REQUIRED_PARAMETER","description":"A required field is missing."},{"field":"/product_id","location":"body","issue":"MISSING_REQUIRED_PARAMETER","description":"A required field is missing."}],"links":[{"href":"https://developer.paypal.com/docs/api/v1/billing/subscriptions#INVALID_REQUEST","rel":"information_link","method":"GET"}]}
I tyed in all possible ways but I don’t know how to debug the problem and what I am missing in create subscription request. Thank you !
2
Answers
Please try to pass PayPal-Request-Id as unique id (Paypal server store it as unique id), it should work
for more details here is a linkclick
let me know if worked or not
PayPal REST API Error 400 in Google Apps Script
This might help.
Issue was that I had to
JSON.stringify
the payload/body