Active Merchant 是电子商务软件解决方案 Shopify 中提取出来的。 Shopify 需要一个简单统一的 API 来访问数十个具有非常不同内部 API 的支付网关,这是设计该库的主要原则。

Active Merchant 自2006 年 6 月以来一直投入生产使用,现在已用于大多数处理金融交易的现代 Ruby 应用程序中。 它由 ShopifySpreedly 团队维护,并得到不断增长的贡献者的大力帮助。

它被开发用于 Ruby on Rails Web 应用程序,并可以无缝集成作为插件,但它也可以作为独立的库出色地工作。

它看起来像什么?

# Send requests to the gateway's test servers
ActiveMerchant::Billing::Base.mode = :test

# Create a new credit card object
credit_card = ActiveMerchant::Billing::CreditCard.new(
  :number     => '4111111111111111',
  :month      => '8',
  :year       => '2009',
  :first_name => 'Tobias',
  :last_name  => 'Luetke',
  :verification_value  => '123'
)

if credit_card.valid?
  # Create a gateway object to the TrustCommerce service
  gateway = ActiveMerchant::Billing::TrustCommerceGateway.new(
    :login    => 'TestMerchant',
    :password => 'password'
  )

  # Authorize for $10 dollars (1000 cents)
  response = gateway.authorize(1000, credit_card)

  if response.success?
    # Capture the money
    gateway.capture(1000, response.authorization)
  else
    raise StandardError, response.message
  end
end

我如何获取它?

Rubygems

RubyGems

gem install activemerchant

如果您想在高安全设置下安装此 gem,您需要
gem cert --add gem-public_cert.pem

Ruby on Rails

Ruby on Rails

添加gem 'activemerchant'到您的 Gemfile 中。

Ruby

下载发布版

来自 RubyGems

Ruby

Git 克隆

来自 GitHub

ActiveMerchantShopifySpreedly 的持续开发赞助并促成。