2015年7月16日 星期四

paypal parse cloud code

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);
  }
});


  });

沒有留言:

張貼留言