Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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',
'' => 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 ='', 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
def url_query_string(hash)
"/?" << URI.escape(hash.collect{|k,v| "#{k}=#{v}"}.join('&'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment