Page 1 of 1

Create PayPal REST API "Billing Plan"

Posted: Tue Apr 26, 2016 6:43 am
by Ed

Hello,

I am able to obtain the Access Token through oauth2 API but when I apply the Bearer Token in Request Header to create the "PayPal Billing Plan" and obtain the Billing Plan ID I get the following Error message:

{
"status":400,
"uri":"https://api.sandbox.paypal.com/v1/pay...",
"response":{
"name":"VALIDATION_ERROR",
"details":[
{
"field":"payment_definitions",
"issue":"Payment definitions are invalid. Valid parameters are REGULAR or combination of TRIAL and REGULAR."
}
],
"message":"Invalid request - see details",
"information_link":"https://developer.paypal.com/webapps/...",
"debug_id":"773d07ee153d0"
}
}

I am using the following API Request sample made available by PayPal:

curl -v POST https://api.sandbox.paypal.com/v1/pay... \
-H 'Content-Type:application/json' \
-H 'Authorization: Bearer ' \
-d '{
"name": "T-Shirt of the Month Club Plan",
"description": "Template creation.",
"type": "fixed",
"payment_definitions": [
{
"name": "Regular Payments",
"type": "REGULAR",
"frequency": "MONTH",
"frequency_interval": "2",
"amount": {
"value": "100",
"currency": "USD"
},
"cycles": "12",
"charge_models": [
{
"type": "SHIPPING",
"amount": {
"value": "10",
"currency": "USD"
}
},
{
"type": "TAX",
"amount": {
"value": "12",
"currency": "USD"
}
}
]
}
],
"merchant_preferences": {
"setup_fee": {
"value": "1",
"currency": "USD"
},
"return_url": "http://www.return.com",
"cancel_url": "http://www.cancel.com",
"auto_bill_amount": "YES",
"initial_fail_amount_action": "CONTINUE",
"max_fail_attempts": "0"
}
}'

What is causing this Error Message? Thanks in advance!


Create PayPal REST API "Billing Plan"

Posted: Tue Apr 26, 2016 1:00 pm
by Serhii Kulibaba

Hello Ed,

We are very sorry, but this is something outside the scope (http://devcenter.appery.io/support-po...) of our standard support. Please ask that question to the paypal support


Create PayPal REST API "Billing Plan"

Posted: Tue Apr 26, 2016 8:02 pm
by Ed

Hi,

I already spoke to PayPal integration support and tested it on their tool and it worked perfectly.

This might be a BUG on the Appery.io platform. For some reason it is NOT posting the "Payment_Definitions" (please see attachments and debugging).

Also, you guys have provided support for similar issues on this forum!

Image Image Image Image Image Image


Create PayPal REST API "Billing Plan"

Posted: Tue Apr 26, 2016 11:08 pm
by maxkatz

Most likely the body request structure has an error in it.

Here is better way to do this, using Server Code script.

Script to get a PayPal token:
pre
var url = "https://api.sandbox.paypal.com/v1/oauth2/token";

var XHRResponse = XHR2.send("POST", url, {
"parameters": {
"grant_type": "client_credentials"
},
"headers": {
"Accept": "application/json",
"Accept-Language": "en_US",
"Authorization": "Basic client_id:secret_in_base64"
}
});

Apperyio.response.success(XHRResponse.body, "application/json");
/pre

Script to create a billing plan:
pre
var url = "https://api.sandbox.paypal.com/v1/payments/billing-plans";

var XHRResponse = XHR2.send("POST", url, {
"headers": {
"Content-type": "application/json",
"Authorization": "Bearer token_from_previous_call",
},
"body": {
"name": "T-Shirt of the Month Club Plan",
"description": "Template creation.",
"type": "fixed",
"payment_definitions": [{
"name": "Regular Payments",
"type": "REGULAR",
"frequency": "MONTH",
"frequency_interval": "2",
"amount": {
"value": "100",
"currency": "USD"
},
"cycles": "12",
"charge_models": [{
"type": "SHIPPING",
"amount": {
"value": "10",
"currency": "USD"
}
}, {
"type": "TAX",
"amount": {
"value": "12",
"currency": "USD"
}
}]
}],
"merchant_preferences": {
"setup_fee": {
"value": "1",
"currency": "USD"
},
"return_url": "http://www.return.com",
"cancel_url": "http://www.cancel.com",
"auto_bill_amount": "YES",
"initial_fail_amount_action": "CONTINUE",
"max_fail_attempts": "0"
}
}
});

Apperyio.response.success(XHRResponse.body, "application/json");
/pre

API docs: https://developer.paypal.com/docs/api...