How to make a payment through Paymill using Ruby

I need to make a Paymill payment , and I want it to be possible using the Ruby language.

UPDATE:

I have publicly released paymill_on_rails on github. This is a Paymill subscription system based on Rails 4.0.0 and paymill-ruby , powered by ruby-2.0.0-p247

See also home project.

A sample application is also deployed to Heroku . Please feel free to develop and contribute in the end.

+5
source share
2 answers

I managed to achieve this quite easily by following these steps:

, , Paymill, . , . , .

script:

require 'rubygems'
require 'active_merchant'
require 'json'

# Use the TrustCommerce test servers
ActiveMerchant::Billing::Base.mode = :test

gateway = ActiveMerchant::Billing::PaymillGateway.new(
    :public_key => 'MY_PAYMILL_PUBLIC_KEY', 
    :private_key => 'MY_PAYMILL_PRIVATE_KEY')

gateway.default_currency = 'USD'

# ActiveMerchant accepts all amounts as Integer values in cents
amount = 1000  # $10.00

# The card verification value is also known as CVV2, CVC2, or CID
credit_card = ActiveMerchant::Billing::CreditCard.new(
    :first_name         => 'Bob',
    :last_name          => 'Bobsen',
    :number             => '5500000000000004',
    :month              => '8',
    :year               => Time.now.year+1,
    :verification_value => '000')

# Validating the card automatically detects the card type
if credit_card.valid?

# Capture the amount from the credit card
response = gateway.purchase(amount, credit_card)

if response.success?
puts "Successfully charged $#{sprintf("%.2f", amount / 100)} to the credit card #{credit_card.display_number}"
else
raise StandardError, response.message
end
end
+1
+5

All Articles