Advertisement
Guest User

Code

a guest
Sep 26th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.02 KB | None | 0 0
  1. def submit_card
  2.         params.permit(:pan, :amount, :exp_mm, :exp_yy, :cvv, :zip)
  3.  
  4.         # Auth
  5.         Excon.defaults[:ssl_verify_peer] = false
  6.  
  7.         auth_response = Excon.post('https://api.phasive.com/v1/auth/authenticate',
  8.           :body => URI.encode_www_form(client_id: '0d5b4a6d582e42071473283046350aa806f3bf2711ea8', username: 'fide_demo', password: "Password99!!"),
  9.           :headers => { "Content-Type" => "multipart/form-data" })
  10.  
  11.         unless auth_response.data[:status] == '200'
  12.           return flash[:error] = "Server Error: Authorization"
  13.         end
  14.  
  15.         auth_token_json = JSON.parse auth_response.data[:body]
  16.  
  17.         auth_token = auth_token_json["token"]["auth_token"]
  18.  
  19.         sale_response = Excon.post('https://api.phasive.com/v1/payment/sale',
  20.           :body => URI.encode_www_form(terminal_key: 'fbd826c83f2026dadaeb0797f84856d91474514846060',
  21.                                       merchant_key: 'd36f88a2c57e3c7d1474514750980db50255a9f17fc81',
  22.                                       wallet_key: "412f34776ab12d806b3810d76aa863651474514483736",
  23.                                       card_number: "#{params[:pan]}",
  24.                                       expire_month: "#{params[:exp_mm]}",
  25.                                       expire_year: "20#{params[:exp_yy]}",
  26.                                       cvv: "#{params[:cvv]}",
  27.                                       amount: "#{params[:amount]}",
  28.                                       currency_code: "USD",
  29.                                       settle_currency_code: "USD",
  30.                                       issuing: "true",
  31.                                       receiver_key: "111f0ff0b3968c5cf7003a24f905ec101474514493066",
  32.                                       ),
  33.           :headers => { "Content-Type" => "multipart/form-data", "Authorization" => "Bearer #{auth_token}" })
  34.  
  35.         unless sale_response.data[:status] == '200'
  36.           return flash[:error] = "Server Error: Payment"
  37.         end
  38.  
  39.         render nothing:true
  40.       end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement