首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Ruby通过Paymill付款

如何使用Ruby通过Paymill付款
EN

Stack Overflow用户
提问于 2013-02-26 13:10:34
回答 2查看 1.3K关注 0票数 5

我需要向佩米尔付款,我希望能够使用Ruby实现这一点。

更新:

我在github上公开发布了钢轨。它是一个基于Rails 4.0.0和佩米尔-红宝石的贝宝订阅系统,运行在ruby-2.0.0-p 247上。

也请参阅家庭工程

还在赫鲁库上部署了一个示例应用程序。最后请随意分叉和贡献。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-02-26 13:10:34

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

  1. 佩米尔创建一个新帐户。
  2. 从Paymill设置页面获取公共密钥和私钥
  3. 安装激活剂 gem: gem安装激活器
  4. 我使用了下面的脚本来购买

请注意,只要你不激活你的帐户在贝宝,它将运行在测试模式。这样就不会有真正的资金转移。他们还列出了永远不会借方的测试信用卡

剧本:

代码语言:javascript
复制
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
票数 1
EN

Stack Overflow用户

发布于 2013-03-17 20:52:10

我是用https://github.com/dkd/paymill-ruby的贝宝宝石做的

它非常容易使用,只需遵循自述,您就会知道它的可能性。它还支持订阅。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15089973

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档