Skip to content
💵 Unified API to integrate Ruby on Rails with Pay2go(智付寶) offsite payment.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
lib
test
.gitignore
.travis.yml
CHANGELOG.md
CODE_OF_CONDUCT.md
Gemfile
LICENSE.txt
README.md
Rakefile
active_merchant_pay2go.gemspec

README.md

Gem Version Build Status Code Climate

ActiveMerchantPay2go

Join the chat at https://gitter.im/imgarylai/active_merchant_pay2go

這個 gem 的目的是要串接 智付通(原智付寶) 的金流,不過不是只有單純的 API 封裝,是透過 active_merchantoffsite_payments 包裝後可以快速的在 Rails 上使用。

另外非常感謝 active_merchant_allpay

安裝

Gemfile 中加入這一行

gem 'active_merchant_pay2go'

透過 bundle 安裝:

$ bundle

設定

  • 建議第一次使用的人可以先看一下官方的文件... Official API

  • 建立 config/initializers/pay2go.rb

rails g pay2go:install
  • 到智付寶上申請申請相關的 key 並放入 config/initializers/pay2go.rb 中。
# Example
OffsitePayments::Integrations::Pay2go.setup do |pay2go|
  # You have to apply credential below by yourself.
  pay2go.merchant_id = '123456'
  pay2go.hash_key    = 'xxx'
  pay2go.hash_iv     = 'yyy'
end
  • 環境設定:
# config/environments/development.rb
config.after_initialize do
  ActiveMerchant::Billing::Base.mode = :development
end
# config/environments/production.rb
config.after_initialize do
  ActiveMerchant::Billing::Base.mode = :production
end

範例

<% payment_service_for  @order,
                        @order.user.email,
                        service: :pay2go,
                        html: { :id => 'pay2go-form', :method => :post } do |service| %>
  <% service.time_stamp @order.created_at %>
  <% service.merchant_order_no @order.id %>
  <% service.amt @order.total_amount.to_i %>
  <% service.item_desc @order.description %>
  <% service.email @order.user.email %>
  <% service.login_type 0 %>
  <% service.encrypted_data %>
  <%= submit_tag '付款' %>
<% end %>

這段程式碼只有實做了很基本的功能。

如果有更多的設定,建議看一下官方文件有沒有支援。

範例 (很簡陋的範例).

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/imgarylai/active_merchant_pay2go. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

You can’t perform that action at this time.