简体   繁体   中英

cannot make API call on paymill - 302 found as a response - rails

I used the examples on the paymill page to get the token with no problem. I'm passing the token using an ajax call. But I cannot make the API to make the final call. I cannot really understand how to use the code from the paymill-ruby or paymill-rails code at github, so I went trough the code and found the API call -which is what I'm missing-, but cannot make it work. All I want to do is a simple payment. No subscription, no user. Just a credit card payment. Here is the code from my controller:

token = params[:token]

params = {'amount' => '#{@@amount}', 'currency' => 'EUR', 'token' => '#{token}', 'description' => 'description'}

https = Net::HTTP.new('api.paymill.de', 80)
https.use_ssl = false
https.start do |connection|
  url = "/v2/transactions"
  https_request = Net::HTTP::Post.new(url)
  https_request.basic_auth(Paymill.api_key,"")
  https_request.set_form_data(params)
  @response = https.request(https_request)
end

puts @response.body
puts @response.header

render :action => "confirm"

The response is

<html>
<head><title>302 Found</title></head>
<body bgcolor="white">
<center><h1>302 Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
#<Net::HTTPFound:0x00000004a98400>

And I cannot figure out what's wrong... a few weeks ago I didn't know what ajax was... can anybody give a hand?

I'm not a rails expert but ...

... you are connecting to our API at port 80 without using SSL. We only allow SSL requests to the api so you'll have to connect using port 443 and having SSL enabled.

Hope that solves your issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM