5

I need to make a payment to Paymill and I want to be able to achieve this using the Ruby language.

UPDATE:

I did publicly release paymill_on_rails on github. It is a Paymill subscription system based on Rails 4.0.0 and paymill-ruby, running on ruby-2.0.0-p247

See also the home project

An example application is also deployed on Heroku. Please feel free to fork & contribute eventually.

Luca G. Soave
  • 12,271
  • 12
  • 58
  • 109
Besi
  • 22,579
  • 24
  • 131
  • 223

2 Answers2

5

I'm doing it using a paymill gem from https://github.com/dkd/paymill-ruby

It's really easy to use, just follow the README and you will have an idea of it's possibilities. It also supports subscriptions.

Kryptman
  • 996
  • 9
  • 14
  • 1
    The readme is lacking a lot of info. For example, how does it handle errors? it's too cryptic – cauchi Aug 08 '13 at 15:11
1

I managed to achieve this quite easily using the following steps:

  1. Create a new Account at Paymill.

  2. Get the public and private key from the Paymill settings page

  3. Install the activemerchant gem:

    gem install activemerchant
    
  4. I used the following script below in order to make a purchase

Please note that as long as you don't activate your account at Paymill it will run in Test mode. So no money will actually be transferred. They also list test credit cards which will never be debited either.

The 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
Besi
  • 22,579
  • 24
  • 131
  • 223
  • 10
    Please, do NOT use this if you don't have the proper PCI certifications. Instead, use the solution suggested by Kryptman . The reason is that Credit Card data should *never* reach your servers, unless you have the appropriate PCI certification. (disclaimer: I work at PAYMILL) – jpkroehling May 29 '13 at 13:55
  • How can I supply an email and the name of the customer? And how can I make this a subscription? – Jonathan Clark May 31 '13 at 11:39