OffsitePaymentsPay2go
OffsitePayments Integrations 介面串接 pay2go 的金流服務。這是非官方實作。
This plugin is an OffsitePayments patch for Pay2go(智付通) online payment in Taiwan.
Now it supports Credit card(信用卡), ATM(ATM轉帳), and CVS(超商繳費).
Installation
Add this line to your application's Gemfile:
gem 'offsite_payments'
gem 'offsite_payments_pay2go', github: 'GoodLife/offsite_payments_pay2go.git'
And then execute:
$ bundle install
Usage
You can get Payment API and SPEC in Pay2go API. Then create an initializer, like initializers/pay2go.rb. Add the following configurations depends on your settings.
# config/environments/development.rb
config.after_initialize do
OffsitePayments::Base.integration_mode = :development
end
# config/environments/production.rb
config.after_initialize do
OffsitePayments::Base.integration_mode = :production
end
# initializers/pay2go.rb
OffsitePayments::Integrations::Pay2go.setup do |pay2go|
if Rails.env.development?
# change to yours
pay2go.merchant_id = '5455626'
pay2go.hash_key = '5294y06JbISpM5x9'
pay2go.hash_iv = 'v77hoKGq4kWxNNIS'
else
# change to yours
pay2go.merchant_id = '7788520'
pay2go.hash_key = 'adfas123412343j'
pay2go.hash_iv = '123ddewqerasdfas'
end
end
Example Usage
Once you’ve configured ActiveMerchantPay2go, you need a checkout form; it looks like:
<% payment_service_for @order,
@order.user.email,
:service => :pay2go,
:html => { :id => 'pay2go-checkout-form', :method => :post } do |service| %>
<% service.merchant_order_no @order.payments.last.identifier %>
<% service.respond_type "String" %>
<% service.time_stamp @order.created_at.to_i %>
<% service.version "1.2" %>
<% service.item_desc @order.number %>
<% service.amt @order.money %>
<% service.email @order.buyer.email %>
<% service.login_type 0 %>
<% service.client_back_url spree.orders_account_url %>
<% service.notify_url pay2go_return_url %>
<% service.encrypted_data %>
<%= submit_tag 'Buy!' %>
<% end %>
Also need a notification action when Pay2go service notifies your server; it looks like:
def notify
notification = OffsitePayments::Integrations::Pay2go::Notification.new(request.raw_post)
order = Order.find_by_number(notification.merchant_order_no)
if notification.status && notification.checksum_ok?
# payment is compeleted
else
# payment is failed
end
render text: '1|OK', status: 200
end
Troublechooting
If you get a error "undefined method `payment_service_for`", you can add following configurations to initializers/pay2go.rb.
require "offsite_payments/integrations/action_view_helper"
ActionView::Base.send(:include, OffsitePayments::Integrations::ActionViewHelper)
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request