You need to sign in to do that
Don't have an account?
Venkat H
MALFORMED_REQUEST: “Incoming JSON request does not map to API request” with Paypal integration in salesforce
I am doing paypal integration in my salesforce account, but am getting a validation error when doing payment through Rest API call: Incoming JSON request does not map to API request
I have tried the below link sample json values:https://developer.paypal.com/docs/api/payments/#payment
Share the correct json values for payment, or assist me on how to proceed.
Please find the apex code for payment:
public void Fetchcredentail(){ Http http = new Http(); HttpResponse response; response = new HttpResponse(); response.setBody(convertJsonBody()); HttpRequest req = new HttpRequest(); req.setEndpoint('https://api.sandbox.paypal.com/v1/payments/payment'); req.setMethod('POST'); req.setHeader('Content-Type', 'application/json'); req.setHeader('Authorization', 'Bearer <Access token>'); response = http.send(req); system.debug(response+'-------'+response.getBody()); } public string convertJsonBody(){ string json= '{'+ ' "intent": "sale",'+ ' "payer": {'+ ' "payment_method": "credit_card",'+ ' "funding_instruments": [{'+ ' "credit_card": {'+ ' "number": "4417119669820331",'+ ' "type": "visa",'+ ' "expire_month": 11,'+ ' "expire_year": 2018,'+ ' "cvv2": "874",'+ ' "first_name": "Venkat",'+ ' "last_name": "H",'+ ' "billing_address": {'+ ' "line1": "111 First Street",'+ ' "city": "Chennai",'+ ' "state": "TN",'+ ' "postal_code": "6000088",'+ ' "country_code": "IN"'+ ' }'+ ' }'+ ' }]'+ ' },'+ ' "transactions": [{'+ ' "amount": {'+ ' "total": "1.47",'+ ' "currency": "USD",'+ ' "details": {'+ ' "subtotal": "1.41",'+ ' "tax": "0.03",'+ ' "shipping": "0.03"'+ ' }'+ ' },'+ ' "description": "The payment transaction description."'+ ' }]'+ '}'; return json; }
json
I have tried the below link sample json values:https://developer.paypal.com/docs/api/payments/#payment
Share the correct json values for payment, or assist me on how to proceed.
Please find the apex code for payment:
public void Fetchcredentail(){ Http http = new Http(); HttpResponse response; response = new HttpResponse(); response.setBody(convertJsonBody()); HttpRequest req = new HttpRequest(); req.setEndpoint('https://api.sandbox.paypal.com/v1/payments/payment'); req.setMethod('POST'); req.setHeader('Content-Type', 'application/json'); req.setHeader('Authorization', 'Bearer <Access token>'); response = http.send(req); system.debug(response+'-------'+response.getBody()); } public string convertJsonBody(){ string json= '{'+ ' "intent": "sale",'+ ' "payer": {'+ ' "payment_method": "credit_card",'+ ' "funding_instruments": [{'+ ' "credit_card": {'+ ' "number": "4417119669820331",'+ ' "type": "visa",'+ ' "expire_month": 11,'+ ' "expire_year": 2018,'+ ' "cvv2": "874",'+ ' "first_name": "Venkat",'+ ' "last_name": "H",'+ ' "billing_address": {'+ ' "line1": "111 First Street",'+ ' "city": "Chennai",'+ ' "state": "TN",'+ ' "postal_code": "6000088",'+ ' "country_code": "IN"'+ ' }'+ ' }'+ ' }]'+ ' },'+ ' "transactions": [{'+ ' "amount": {'+ ' "total": "1.47",'+ ' "currency": "USD",'+ ' "details": {'+ ' "subtotal": "1.41",'+ ' "tax": "0.03",'+ ' "shipping": "0.03"'+ ' }'+ ' },'+ ' "description": "The payment transaction description."'+ ' }]'+ '}'; return json; }
json
This error outlines that the Json string being generated through your code is faulty and you may need to relook at it. Can you print the value of the json variable in the debug log and share that string.
Infact you could print the string and use this Online Json Viewing Utility (http://jsonviewer.stack.hu/) to view the string as objects. Instead of generating the Json content manually by appending strings a better way would be to use a wrapper class, similar to the one mentioned below and then using the JSON.serialize() method to generate the Json string using the wrapper class's instance. This technique would prove less cumbersome for Json generation and will save you the overhead of troubleshooting string errors like the one you are facing.
Please do not forget to mark this thread as SOLVED if this answer helps resolve your issue.