parshv sheth
parshv sheth

Reputation: 1

Paypal REST API : Nodejs : i am having problem in creating billing plan : Incoming JSON request does not map to API request

I am using Paypal-rest-sdk and i am having problem in creating new billing plans in PayPal:

This is billingPlan variable value and that is what i am sending to sdk function

{"product_id":"ESSENTIAL_PLAN_MONTHLY","name":"Essential Monthly Plan","description":"Basic plan with 1-month billing cycle","billing_cycles":[{"frequency":{"interval_unit":"MONTH","interval_count":1},"tenure_type":"REGULAR","sequence":1,"total_cycles":12,"pricing_scheme":{"fixed_price":{"value":"12","currency_code":"USD"}}}],"payment_preferences":{"auto_bill_outstanding":true,"setup_fee":{"value":"10","currency_code":"USD"},"setup_fee_failure_action":"CONTINUE","payment_failure_threshold":3},"taxes":{"percentage":"10","inclusive":false}}

This is usage of the function

import paypal from "paypal-rest-sdk";
dotenv.config();

paypal.configure({
    'mode': 'sandbox', // sandbox or live
    'client_id': process.env.PAYPAL_CLIENT_ID!,
    'client_secret': process.env.PAYPAL_CLIENT_SECRET!
});

const response = await new Promise((resolve, reject) => {
                    paypal.billingPlan.create(billingPlan, {}, (error: any, plan: any) => {
                        if (error) {
                            reject(error);
                        } else {
                            resolve(plan);
                        }
                    });
                });

Error:

Error creating PayPal billing plan: 
Error: Response Status : 400
    at IncomingMessage.<anonymous> (C:\Users\Sheth parshv n\desktop-shortcut\fivverr\toolmate\code\toomate-node\node_modules\paypal-rest-sdk\lib\client.js:130:23)
    at IncomingMessage.emit (node:events:529:35)
    at IncomingMessage.emit (node:domain:489:12)
    at endReadableNT (node:internal/streams/readable:1368:12)
    at processTicksAndRejections (node:internal/process/task_queues:82:21) {
  response: {
    name: 'MALFORMED_REQUEST',
    debug_id: '9c688af6ebcbc',
    message: 'Incoming JSON request does not map to API request',     
    information_link: 'https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST',
    httpStatusCode: 400
  },
  httpStatusCode: 400
}

How to fix this as i have matched the body i am sending with the official docs that Paypal provides and also matched with their postman reference the body is correct, then why i can't create billingPlan

I want to create billing plan in paypal and i am having malformated JSON error i want to create billing plans and return them in array

Upvotes: 0

Views: 26

Answers (0)

Related Questions