如何使用Ruby通过Paymill付款

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上还部署了一个示例应用程序.请随意分叉并最终做出贡献.

Kry*_*man 5

我正在使用来自https://github.com/dkd/paymill-ruby的paymill gem

它非常易于使用,只需按照README进行操作即可了解它的可能性.它还支持订阅.


Bes*_*esi 1

我通过以下步骤轻松实现了这一目标:

  1. 在Paymill创建一个新帐户。

  2. 从 Paymill 设置页面获取公钥和私钥

  3. 安装activemerchant gem:

    gem install activemerchant
    
    Run Code Online (Sandbox Code Playgroud)
  4. 我使用下面的脚本来进行购买

请注意,只要您不在 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)

  • 如果您没有适当的 PCI 认证,请不要使用此功能。相反,请使用 Kryptman 建议的解决方案。原因是信用卡数据“永远”不应该到达您的服务器,除非您拥有适当的 PCI 认证。(免责声明:我在 PAYMILL 工作) (10认同)