-
-
Save nirnaeth/c65d664b4ed8771ebbde0935c7844599 to your computer and use it in GitHub Desktop.
Generating a Paymill token to test without the Javascript Bridge
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
module PaymillSupport | |
def get_payment_token | |
# Simulate the JavaScript bridge we would use in production | |
params = { | |
'transaction.mode' => 'CONNECTOR_TEST', | |
'channel.id' => Rails.configuration.paymill_public_key, | |
'jsonPFunction' => 'function', | |
'account.number' => '4111111111111111', | |
'account.expiry.month' => 1.year.from_now.month, | |
'account.expiry.year' => 1.year.from_now.year, | |
'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 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment