Created
June 18, 2013 10:13
-
-
Save gnepud/5804215 to your computer and use it in GitHub Desktop.
Generate token paymill
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you man :D