MALFORMED_REQUEST Please help me create my first payment :-(

sipi41
Contributor
Contributor

I'm trying to create my first paypal payment but something is making me crazy. After getting my token, I'm trying to form my request using c# and RestClient... I have provided my token via header, the content type, created the json request and used "AddJsonBody" to add the json to the request, please take a look at my code:

 

private static string MakePayment()
{

        string EndPoint = "/v1/payments/payment";

        var cliente = new RestClient(baseURL);
        var request = new RestRequest(EndPoint, Method.POST);
        request.AddHeader("Content-Type", "application/json");
        request.AddHeader("Authorization", $"{TokenType} {Token}");

        string myJson = @"{
            ""intent"": ""sale"",
            ""payer"": {
            ""payment_method"": ""paypal""
            },
            ""transactions"": [

                {        
                    ""reference_id"" : ""MyReferenceXX89899"",
                    ""description"": ""The payment transaction description."",
                    ""note_to_payee"": ""Contact us for any questions on your order."",
                    ""payment_options"": {
                        ""allowed_payment_method"": ""INSTANT_FUNDING_SOURCE""
                    },        
                    ""invoice_number"" : ""48787589673"",
                    ""purchase_order"" : ""MyPurchaseOrder545885"",
                    ""notify_url"":""https://example.com/ordernotify"",
                    ""amount"": {
                        ""currency"": ""USD"",            
                        ""total"": ""30.10"",            
                        ""details"": {
                            ""subtotal"": ""30.00"",
                            ""shipping"": ""0.03"",              
                            ""tax"": ""0.07""
                        }
                    }
                }
            ],  
            ""redirect_urls"": {
                ""return_url"": ""https://example.com/return"",
                ""cancel_url"": ""https://example.com/cancel""
            }
        }";

        request.AddJsonBody(JObject.Parse(myJson));

        IRestResponse R = cliente.Execute(request);

        return R.Content;
    }

I have checked for errors on my json, for read-only properties and the json seems to be ok, except that I receive a message back saying the json is not formed according to what they ask... PLEASE HELP... 😞

 

This is what I get back:

 

{"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":"b8e99a74bab2..."}

Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.