Skip to content

Instantly share code, notes, and snippets.

@luopio
Forked from gnepud/gist:5804215
Last active June 17, 2016 15:54
Show Gist options
  • Save luopio/f5a58f1dacf94d6094ad to your computer and use it in GitHub Desktop.
Save luopio/f5a58f1dacf94d6094ad to your computer and use it in GitHub Desktop.
Generating a Paymill token to test without the Javascript Bridge
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