Git Product home page Git Product logo

active_merchant_pay2go's Introduction

ActiveMerchantPay2go

This plugin is an active_merchant 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 'active_merchant_pay2go', '>=0.1'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install active_merchant_pay2go

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
  ActiveMerchant::Billing::Base.integration_mode = :development
end

# config/environments/production.rb
config.after_initialize do
  ActiveMerchant::Billing::Base.integration_mode = :production
end
# initializers/pay2go.rb
ActiveMerchant::Billing::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 = ActiveMerchant::Billing::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 "active_merchant/billing/integrations/action_view_helper"
ActionView::Base.send(:include, ActiveMerchant::Billing::Integrations::ActionViewHelper)

TODOs

  • Transaction Query Review
  • CreditCard Refund
  • CreditCard Inst(定期定額)
  • Electronic Invoice

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

active_merchant_pay2go's People

Contributors

hothero avatar hrs113355 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.