Skip to content

Instantly share code, notes, and snippets.

@matsubo
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matsubo/9205415 to your computer and use it in GitHub Desktop.
Save matsubo/9205415 to your computer and use it in GitHub Desktop.
Sample code for activemerchant's WorldpayGateway.
require 'active_merchant'
require 'pp'
currency = 'USD'
gateway = ActiveMerchant::Billing::WorldpayGateway.new(
:login => 'YOUR_MERCHANT_ID',
:password => 'YOUR_XML_PASSWORD',
:test => true,
)
money = 100
credit_card = ActiveMerchant::Billing::CreditCard.new(
:number => "4444333322221111",
:month => "12",
:year => Time.now.year + 1,
:brand => :visa,
:first_name => 'first',
:last_name => 'last',
)
order_id = 'label-' + Time.now.to_i.to_s
# 1. authorization
response1 = gateway.authorize(money, credit_card, {
:order_id => order_id,
:currency => currency,
})
pp response1
# 2. capture
#response2 = gateway.capture(money, response1.authorization, {
# :authorization_validated => true, # avoid order status query
#})
#pp response2
# 3. void
#response3 = gateway.void(response1.authorization)
#pp response3
# 4. Reccuring payment (payAsOrder)
# Specify initial order_id instead of credit card comparing to the 1st payment.
subsequent_order_id = 'label-subsequent-' + Time.now.to_i.to_s
response4 = gateway.authorize(money, order_id, {
:order_id => subsequent_order_id,
:currency => currency,
})
pp response4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment