0

I've been trying to create and send invoice using Paypal from Parse.com Cloud Code. Below is my code. I've been getting this error Request failed with response code 0

Parse.Cloud.define("send_paypal_invoice", function(request, response){

var headerParams = [{   //Setting PayPal request headers
                    'X-PAYPAL-SECURITY-USERID'      : '****************',
                    'X-PAYPAL-SECURITY-PASSWORD'    : '***********',
                    'X-PAYPAL-SECURITY-SIGNATURE'   : '****************',
                    // Global Sandbox Application ID
                    'X-PAYPAL-APPLICATION-ID '      : 'APP-80W284485P519543T',
                    // Input and output formats
                    'X-PAYPAL-REQUEST-DATA-FORMAT'  : 'JSON',
                    'X-PAYPAL-RESPONSE-DATA-FORMAT' : 'JSON'
                }];

var payload = {
    requestEnvelope: {
        errorLanguage:  'en_US'
    },
    invoice: {
        merchantEmail: '*****************',
        payerEmail:    '*****************',
        currencyCode:  'SGD',
        paymentTerms:  'DueOnReceipt',
        itemList: [{    name:'BananaPlant',
                        quantity:'1',
                        unitPrice:'38.95'
                    },
                    {   name:'testPlant',
                        quantity:'2',
                        unitPrice:'18.20'}]
            }
    };     

var bodyJsonParams = JSON.stringify(payload);        

var headerJsonParams = JSON.stringify(headerParams);

Parse.Cloud.httpRequest({
  url: 'https://svcs.sandbox.paypal.com/Invoice/CreateAndSendInvoice',
   headers: headerJsonParams,
   body: bodyJsonParams,

  success: function(httpResponse) {
    console.log(httpResponse.text);
  },
  error: function(httpResponse) {
    console.error('Request failed with response code ' + httpResponse.status);
  }
});


  });

Any suggestions? There is no errors coming off cloudcode.

I've used the curl command to verify that my call works.

curl -s -v -D --insecure -H "X-PAYPAL-SECURITY-USERID: *************" -H "X-PAYPAL-SECURITY-PASSWORD: *************" -H "X-PAYPAL-SECURITY-SIGNATURE: *************" -H "X-PAYPAL-REQUEST-DATA-FORMAT: JSON" -H "X-PAYPAL-RESPONSE-DATA-FORMAT: JSON" -H "X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T" https://svcs.sandbox.paypal.com/Invoice/CreateAndSendInvoice -d \
"{\"requestEnvelope\":{\"errorLanguage\":\"en_US\"},\"invoice\":{\"merchantEmail\":\"*************\",\"payerEmail\":\"*************\",\"currencyCode\":\"USD\",\"paymentTerms\":\"DueOnReceipt\",\"itemList\":{\"item\":[{\"name\":\"BananaPlant\",\"quantity\":\"1\",\"unitPrice\":\"38.95\"},{\"name\":\"PeachTree\",\"quantity\":\"2\",\"unitPrice\":\"18.95\"}]}}}"
Ng Zhong Qin
  • 1,211
  • 2
  • 15
  • 28

1 Answers1

0

Ok. It's a real stupid mistake. There's a space between 'X-PAYPAL-APPLICATION-ID and '. It's just weird why PayPal didn't respond with a Auth failure message.

Ng Zhong Qin
  • 1,211
  • 2
  • 15
  • 28