Bes*_*esi 5 ruby payment-gateway activemerchant e-commerce paymill
我需要向Paymill付款,我希望能够使用Ruby语言实现这一目标.
更新:
我在github上公开发布了paymill_on_rails.这是一个基于Rails 4.0.0和paymill-ruby的Paymill订阅系统,运行在ruby-2.0.0-p247上
另见家庭项目
Heroku上还部署了一个示例应用程序.请随意分叉并最终做出贡献.
我通过以下步骤轻松实现了这一目标:
在Paymill创建一个新帐户。
从 Paymill 设置页面获取公钥和私钥
安装activemerchant gem:
gem install activemerchant
Run Code Online (Sandbox Code Playgroud)我使用下面的脚本来进行购买
请注意,只要您不在 Paymill 激活您的帐户,它就会在测试模式下运行。所以实际上不会转移任何钱。他们还列出了永远不会被借记的测试信用卡。
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1248 次 |
| 最近记录: |