Skip to content
This repository has been archived by the owner on May 12, 2020. It is now read-only.

MALFORMED_REQUEST for Version 2.0.0-rc.1 #350

Closed
ankibalyan opened this issue Mar 1, 2018 · 3 comments
Closed

MALFORMED_REQUEST for Version 2.0.0-rc.1 #350

ankibalyan opened this issue Mar 1, 2018 · 3 comments

Comments

@ankibalyan
Copy link

General information

  • SDK/Library version: 2.0.0-rc.1
  • Environment: Sandbox
  • PayPal-Debug-ID values: '450e42f1e1a1a',
  • Language, language version, and OS: Nodejs 8.9.4 on Ubuntu 16.04

Issue description

Not able to execute the payment after customer approves the request. getting following error.

{ Error: {"name":"MALFORMED_REQUEST","message":"Incoming JSON request does not map to API request","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST","debug_id":"450e42f1e1a1a"}

Here Is the code for execution.

function handleChargeResponse({ body, payment_ref }) {
  const payments = paypal.v1.payments;
  const payReq = new payments.PaymentExecuteRequest(body.paymentId);
  payReq.headers['PayPal-Request-ID'] = payment_ref;
  payReq.headers['Authorization'] = `Bearer ${body.token}`;
  const details = { payer_id: body.payerId};
  payReq.requestBody(body.paymentId, details);
  return client.execute(payReq)
    .then((chargeObject) => {
      console.log('=============== START DEBUG LOG retrieve Paypal chargeObject ===============');
      console.log(chargeObject);
      console.log('=============== END DEBUG LOG retrieve Paypal chargeObject ===============');
      return { chargeObject };
    })
    .catch((err) => {
      console.log(err);
      return { chargeObject };
    });
}
@ankibalyan
Copy link
Author

Issue Resolved by changing these params

const details = { payer_id: body.PayerID };
payReq.requestBody(details);

@artur-sim
Copy link

Can some one help me im out of my mind already, i cannot figure out what is wrong in body

` let payerId = req.query.PayerID;
let paymentId = req.query.paymentId;

let execute_payment_json = {
    "payer_id": payerId,
    "transactions": [{
        "amount": {
            "total": "2.00",
            "currency": "USD",
            "details": {
                "subtotal": "1.00",
                "tax": "0.00",
                "shipping": "1.00"
            }
        }
    }]
};


let payment = new payments.PaymentExecuteRequest();
payment.requestBody(paymentId, execute_payment_json);

client.execute(payment).then((response) => {
    console.log(response);
    res.send('paid succesfully')
}).catch((error) => {
    console.error(error.statusCode);
    console.error(error.message);
    res.send(error.message)
});`

Im getting fkn error

400 {"name":"MALFORMED_REQUEST","message":"Incoming JSON request does not map to API request","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST","debug_id":"16eab59ce8d5c

@artur-sim
Copy link

anyone facing this , my solution was

` let payerId = req.query.PayerID;
let paymentId = req.query.paymentId;

let payment = new payments.PaymentExecuteRequest(paymentId);
payment.requestBody({
    "payer_id": payerId
});

client.execute(payment).then((response) => {

    console.log(response);
    res.send('paid succesfully')
}).catch((error) => {
    console.error(error.statusCode);
    console.error(error.message);
    res.send(error.message)
});`

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants