137 文字
1 分
Ruby ActiveMerchant sample code for WorldPay
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. authorizationresponse1 = 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_sresponse4 = gateway.authorize(money, order_id, { :order_id => subsequent_order_id, :currency => currency,})
pp response4quoted from https://blog.teraren.com/2014/02/25/worldpay-activemerchant/
Ruby ActiveMerchant sample code for WorldPay
https://blog.teraren.com/posts/qiita-20140226-66a5eb548386e70f519b/ 関連記事
この記事が役に立ったら
GitHub Sponsorsで応援できます