0

I am trying to integrate payment gateway to my application. Their docs (https://razorpay.com/docs/route/api-reference/#funds-movement-in-linked-accounts) say I have to send request like this:

   curl https://api.razorpay.com/v1/payments/pay_AlSXPEsTyXyxYx/transfers \
   -u <YOUR_API_KEY>:<YOUR_SECRET_KEY> \
   -d 'transfers[0][account]=acc_BYYYYJRfs1234S' \
   -d 'transfers[0][amount]=1000' \
   -d 'transfers[0][currency]=INR' \
   -d 'transfers[0][notes][roll_no]=IEC2011025' \
   -d 'transfers[0][notes][name]=Gaurav Kumar' \
   -d 'transfers[0][linked_account_notes][0]=roll_no' \
   -d 'transfers[1][account]=acc_BYYYYJRfs1234S' \
   -d 'transfers[1][amount]=1000' \
   -d 'transfers[1][currency]=INR' \
   -d 'transfers[1][notes][roll_no]=IEC2011026' \
   -d 'transfers[1][notes][name]=Saurav Kumar'

I send the data as an object and doing angular.toJson() on it. I get 400 bad request

   let payData =
  {
    account: 'anccount',
    rzp_test_abcd:  'tyaef', //key
    amount: parseInt($scope.amountPayingNow*100),

  }

Calling their API:

 $http({
    method: "POST",
    url: 'https://api.razorpay.com/v1/payments/'+ transaction.razorpay_payment_id + '/transfers',
    data: angular.toJson(payData),
  });
Le guy
  • 59
  • 8

1 Answers1

0

See the curl manual:

-d/--data

(HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded. Compare to -F/--form.

Now see your code:

data: angular.toJson(payData),

JSON is not application/x-www-form-urlencoded!

You need to encode the data in the expected format.

Now see How to force Angular2 to POST using x-www-form-urlencoded elsewhere on Stackoverflow for an implementation of the solution.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335