I'm trying to use the Faraday gem to post a request.
I receive credit card information and post it to a URL. But, for some reason, my response is "404".
My questions are about the way I get the response, and whether I put the information correctly for the headers and body.
Because there was no Ruby API for this request but only Python, I made a request by translating from Python to Ruby.
This is the Ruby code:
conn2 = Faraday.new(:url => 'https://api.iamport.kr/subscribe/payments')
response2 = conn2.post do |req|
req.url '/onetime'
req.headers['X-ImpTokenHeader'] = "token secret will be put here"
req.body = '{ "token": "abcdefg", "merchant_uid": "merchant_144609705412313",
"amount" : "1000", "card_number" : "555555555555", "expiry": "0520", "birth": "878787",
"pwd_2digit": "99"}'
end
@body2 = response2.body
@status2 = response2.status
And the Python code:
def onetime(self, **params):
url = 'https://api.iamport.kr/subscribe/payments/onetime/'
keys = ['token', 'merchant_uid', 'amount', 'vat', 'card_number', 'expiry', 'birth', 'pwd_2digit',
'remember_me', 'customer_uid', 'buyer_name', 'buyer_email', ]
data = {k: v for k, v in params.items() if k in keys}
def _post(self, url, data=None, headers=None):
data, headers = self._set_default(data, headers)
response = requests.post(url, headers=headers, data=data)
return self._parse_response(response)
def _set_default(self, data, headers):
if not data:
data = {}
if not headers:
headers = {}
headers[self.TOKEN_HEADER] = self._access_code
return data, headers