Reputation: 1352
I am trying to use the rest API to update a billing plan's setup fee. The plan is active, but not used at the moment. I create a plan for each client for each service because the values are different for each, and if they do not complete the payment process and come back at some future date the values could change.
So if they come back at some time I may need to update the setup_fee, which according to the API docs setup_fee can be changed via PATCH.
So here is the plan prior to the change request.
{
"id": "P-7H193472JB2565539MCC4REI",
"product_id": "PROD-3GK52832VM631252R",
"name": "Access to Gig",
"status": "ACTIVE",
"description": "Access to Gig",
"usage_type": "LICENSED",
"billing_cycles": [
{
"pricing_scheme": {
"version": 6,
"fixed_price": {
"currency_code": "USD",
"value": "9.44"
},
"create_time": "2021-04-25T20:25:47Z",
"update_time": "2021-04-25T20:25:47Z"
},
"frequency": {
"interval_unit": "MONTH",
"interval_count": 1
},
"tenure_type": "REGULAR",
"sequence": 1,
"total_cycles": 0
}
],
"payment_preferences": {
"service_type": "PREPAID",
"auto_bill_outstanding": true,
"setup_fee": {
"currency_code": "USD",
"value": "19.57"
},
"setup_fee_failure_action": "CANCEL",
"payment_failure_threshold": 1
},
"quantity_supported": false,
"create_time": "2021-04-25T19:52:49Z",
"update_time": "2021-04-25T20:25:47Z",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/billing/plans/P-7H193472JB2565539MCC4REI",
"rel": "self",
"method": "GET",
"encType": "application/json"
},
{
"href": "https://api.sandbox.paypal.com/v1/billing/plans/P-7H193472JB2565539MCC4REI",
"rel": "edit",
"method": "PATCH",
"encType": "application/json"
},
{
"href": "https://api.sandbox.paypal.com/v1/billing/plans/P-7H193472JB2565539MCC4REI/deactivate",
"rel": "self",
"method": "POST",
"encType": "application/json"
}
]
So now I want to update the setup_fee.
PATCH https://api.sandbox.paypal.com/v1/billing/plans/P-7H193472JB2565539MCC4REI
Authorization: Bearer <ACCESS TOKEN>
Content-Type: application/json
{
"path" : "payment_preferences/setup_fee",
"value" : {
"setup_fee" : {
"value" : "220.80",
"currency_code" : "USD"
}
},
"op" : "replace"
}
In response I get:
{
'details' => [
{
'location' => 'body',
'issue' => 'MALFORMED_REQUEST_JSON',
'field' => '/',
'description' => 'The request JSON is not well formed.'
}
],
'links' => [],
'message' => 'Request is not well-formed, syntactically incorrect, or violates schema.',
'name' => 'INVALID_REQUEST',
'debug_id' => '9444da3d14a00'
};
Any idea why this fails? I have tried to change the way the "value" entry is, as just the actual setup_fee, or as a hash with the entire setup_fee structure there.
Thanx
Upvotes: 1
Views: 398
Reputation: 1352
Turns out I had multiple problems, yes the first was I needed the path to be "/payment_preferences/setup_fee", I had forgotten the leading slash.
But also, I needed the json data to be an array of structures rather than a structure.
[
{
"op":"replace",
"path":"/payment_preferences/setup_fee",
"value":
{
"currency_code":"USD",
"value":"500.00"
}
}
]
Thank you all.
Upvotes: 1