【问题标题】:How to make a payment via Paymill using Ruby如何使用 Ruby 通过 Paymill 进行付款
【发布时间】:2013-02-11 22:54:30
【问题描述】:

我需要向Paymill 付款,并且我希望能够使用 Ruby 语言实现这一目标。

更新:

我确实在 github 上公开发布了 paymill_on_rails。它是一个基于 Rails 4.0.0 和 paymill-ruby 的 Paymill 订阅系统,运行在 ruby​​-2.0.0-p247 上

另见home project

一个示例应用程序也部署在Heroku 上。请随时 fork 并最终做出贡献。

【问题讨论】:

    标签: ruby e-commerce payment-gateway activemerchant paymill


    【解决方案1】:

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

    它非常易于使用,只需按照自述文件进行操作,您就会了解它的可能性。它还支持订阅。

    【讨论】:

    • 自述文件缺少很多信息。例如,它如何处理错误?太神秘了
    【解决方案2】:

    我通过以下步骤很容易地做到了这一点:

    1. Paymill 创建一个新帐户。

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

    3. 安装activemerchant gem:

      gem install activemerchant
      
    4. 我使用以下脚本进行购买

    请注意,只要您不在 Paymill 上激活您的帐户,它就会在测试模式下运行。因此,实际上不会转移任何资金。他们还列出了test credit cards,它也永远不会被借记。

    脚本:

    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
    

    【讨论】:

    • 如果您没有适当的 PCI 认证,请不要使用它。相反,请使用 Kryptman 建议的解决方案。原因是信用卡数据应该永远到达您的服务器,除非您拥有适当的 PCI 认证。 (免责声明:我在 PAYMILL 工作)
    • 如何提供电子邮件和客户姓名?我该如何订阅?
    猜你喜欢
    • 2012-07-22
    • 2014-04-09
    • 2017-10-14
    • 2015-07-20
    • 2016-09-03
    • 2016-04-23
    • 2016-03-14
    • 2013-05-27
    • 1970-01-01
    相关资源
    最近更新 更多