ActiveMerchant with Paypal

先做筆記,以後再補

Installing

gem 'activemerchant'

Usage

def  options
  options ||= { items: [{ name: "客氣了", quantity: 10, amount: 30 * 10}], return_url: "http://paypal-me.dev", cancel_return_url: "http://paypal-me.dev/cancel", currency: 'TWD' }
end

ActiveMerchant::Billing::Base.mode = :test

paypal_billing_gateway ||= ActiveMerchant::Billing::PaypalExpressGateway.new(
  :login => 'hechien+paypal-facilitator_api1.me.com',
  :password => '323451331',
  :signature => 'AOLYMnN04yhgMUgqdMuQUiH04FtTADKiSkCf9sWCjtaPZwicIxoQyC2z'
)

item_amount = 10
item_unit_price = 30
total_price = (item_amount * item_unit_price) * 100 # 乘上 100 是因為 ActiveMerchant 是以「分」來計算

requst = paypal_billing_gateway.setup_purchase(total_price)
redirect_to paypal_billing_gateway.redirect_url_for(request)

以上片段程式碼先記錄一下,之後再處理

Comments

comments powered by Disqus