Skip to content

AlvinChiou/active_merchant_pay2go

 
 

Repository files navigation

ActiveMerchantPay2go

This gem integrate Rails with pay2go(智付寶).

It was inspired by active_merchant_allpay.

Installation

Add this line to your application's Gemfile:

gem 'active_merchant_pay2go'

And then execute:

$ bundle

Setup

  • I would suggest reading the official API first.

  • Create file config/initializers/pay2go.rb

rails g pay2go:install
  • Go to Pay2go and get your credential information. Then fill in config/initializers/pay2go.rb
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
  • Environment configuration:
# 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

Example

<% 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 %>

This example code only fulfill the min requirements.

To customize settings, you should read the documents. I put some comments in the code as well!

Here is an example app though it is really rough.

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.

About

This gem integrate Rails with pay2go(智付寶).

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 99.2%
  • Shell 0.8%