Skip to content

Instantly share code, notes, and snippets.

@gnepud
Created June 18, 2013 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gnepud/5804215 to your computer and use it in GitHub Desktop.
Save gnepud/5804215 to your computer and use it in GitHub Desktop.
Generate token paymill
def get_payment_token
# Simulate the JavaScript bridge we would use in production
params = {
'transaction.mode' => 'CONNECTOR_TEST',
'channel.id' => APP_CONFIG[:paymill_pub_key],
'jsonPFunction' => 'function',
'account.number' => '4111111111111111',
'account.expiry.month' => '02',
'account.expiry.year' => '2014',
'account.verification' => '111',
'presentation.amount3D' => '10.00',
'presentation.currency3D' => 'EUR'
}
http = Net::HTTP.new('test-token.paymill.de', 443)
http.use_ssl = true
response = http.get url_query_string(params)
response.body.scan(/tok_\w*\b/).first # Use a regex to pull the token from the (not-quite-JSON) response
end
def url_query_string(hash)
"/?" << URI.escape(hash.collect{|k,v| "#{k}=#{v}"}.join('&'))
end
@nirnaeth
Copy link

thank you man :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment