active_merchant_allpay 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +116 -0
- data/Rakefile +1 -0
- data/active_merchant_allpay.gemspec +22 -0
- data/lib/active_merchant/billing/integrations/allpay/helper.rb +88 -0
- data/lib/active_merchant/billing/integrations/allpay/notification.rb +107 -0
- data/lib/active_merchant/billing/integrations/allpay.rb +47 -0
- data/lib/active_merchant_allpay/version.rb +3 -0
- data/lib/active_merchant_allpay.rb +10 -0
- metadata +70 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ee196458cee31d52bbdeec5ef7b2f7df7ca3bc13
|
4
|
+
data.tar.gz: 075db62c77d3e9d07f699cd8619f92367717a465
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f23496aca65532d1787206ede00c9ea913ff6101ce606c97f8a38979794063a126548126404b1033d50508bb986c1069c624ff3ff15aadc6156b4bbc0c96b5c5
|
7
|
+
data.tar.gz: 8904df32ebc5217b00e0776cbe581edc8ad697969ec7ef59badbda43d3171ca17eb9226977e6ae79206ca97c1e9072178349b6e135a13b6b69a21ea33123e88e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 xwaynec
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
# ActiveMerchantAllpay
|
2
|
+
|
3
|
+
This plugin is an active_merchant patch forAllpay(歐付寶) online payment in Taiwan.
|
4
|
+
Now it supports Credit card(信用卡), ATM(虛擬ATM) and CVS(超商繳費).
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'activemerchant'
|
11
|
+
gem 'active_merchant_allpay'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install activemerchant
|
20
|
+
$ gem install active_merchant_allpay
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
You can get Payment API and SPEC in [Allpay API](http://www.allpay.com.tw/Service/API).
|
25
|
+
Then create an initializer, like initializers/allpay.rb. Add the following configurations depends on your settings.
|
26
|
+
|
27
|
+
``` ruby
|
28
|
+
|
29
|
+
# config/environments/development.rb
|
30
|
+
config.after_initialize do
|
31
|
+
ActiveMerchant::Billing::Base.integration_mode = :development
|
32
|
+
end
|
33
|
+
|
34
|
+
# config/environments/production.rb
|
35
|
+
config.after_initialize do
|
36
|
+
ActiveMerchant::Billing::Base.integration_mode = :production
|
37
|
+
end
|
38
|
+
|
39
|
+
```
|
40
|
+
|
41
|
+
``` ruby
|
42
|
+
ActiveMerchant::Billing::Integrations::Allpay.setup do |allpay|
|
43
|
+
if Rails.env.development?
|
44
|
+
allpay.merchant_id = '5566183'
|
45
|
+
allpay.hash_key = '56cantdieohyeah'
|
46
|
+
allpay.hash_iv = '183club'
|
47
|
+
else
|
48
|
+
allpay.merchant_id = '7788520'
|
49
|
+
allpay.hash_key = 'adfas123412343j'
|
50
|
+
allpay.hash_iv = '123ddewqerasdfas'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
## Example Usage
|
56
|
+
|
57
|
+
Now support three payment methods:
|
58
|
+
|
59
|
+
``` ruby
|
60
|
+
# 1. Credit card
|
61
|
+
ActiveMerchant::Billing::Integrations::Allpay::PAYMENT_CREDIT_CARD
|
62
|
+
|
63
|
+
# 2. ATM
|
64
|
+
ActiveMerchant::Billing::Integrations::Allpay::PAYMENT_ATM
|
65
|
+
|
66
|
+
# 3. CVS (convenience store)
|
67
|
+
ActiveMerchant::Billing::Integrations::Allpay::PAYMENT_CVS
|
68
|
+
```
|
69
|
+
|
70
|
+
Once you’ve configured ActiveMerchantAllpay, you need a checkout form; it looks like:
|
71
|
+
|
72
|
+
``` ruby
|
73
|
+
<% payment_service_for @order,
|
74
|
+
@order.user.email,
|
75
|
+
:service => :allpay,
|
76
|
+
:html => { :id => 'allpay-atm-form', :method => :post } do |service| %>
|
77
|
+
|
78
|
+
<% service.merchant_trade_no @order.payments.last.identifier %>
|
79
|
+
<% service.merchant_trade_date @order.created_at %>
|
80
|
+
<% service.total_amount @order.total.to_i %>
|
81
|
+
<% service.trade_desc @order.number %>
|
82
|
+
<% service.item_name @order.number %>
|
83
|
+
<% service.choose_payment ActiveMerchant::Billing::Integrations::Allpay::PAYMENT_ATM %>
|
84
|
+
<% service.client_back_url spree.orders_account_url %>
|
85
|
+
<% service.return_url allpay_atm_return_url %>
|
86
|
+
<% service.encrypted_data %>
|
87
|
+
<%= submit_tag 'Buy!' %>
|
88
|
+
<% end %>
|
89
|
+
```
|
90
|
+
|
91
|
+
Also need a notification action when Allpay service notifies your server; it looks like:
|
92
|
+
|
93
|
+
``` ruby
|
94
|
+
def notify
|
95
|
+
notification = ActiveMerchant::Billing::Integrations::Allpay::Notification.new(params)
|
96
|
+
|
97
|
+
order = Order.find_by_number(notification.merchant_trade_no)
|
98
|
+
|
99
|
+
if notification.status && notification.checksum_ok?
|
100
|
+
# payment is compeleted
|
101
|
+
else
|
102
|
+
# payment is failed
|
103
|
+
end
|
104
|
+
|
105
|
+
render text: '1|OK', status: 200
|
106
|
+
end
|
107
|
+
```
|
108
|
+
|
109
|
+
## Contributing
|
110
|
+
|
111
|
+
1. Fork it
|
112
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
113
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
114
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
115
|
+
5. Create new Pull Request
|
116
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'active_merchant_allpay/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "active_merchant_allpay"
|
8
|
+
spec.version = ActiveMerchantAllpay::VERSION
|
9
|
+
spec.authors = ["xwaynec"]
|
10
|
+
spec.email = ["xwaynec@gmail.com"]
|
11
|
+
spec.description = %q{A rails plugin to add active_merchant patch for Taiwan payment}
|
12
|
+
spec.summary = %q{A rails plugin to add active_merchant patch for Taiwan payment}
|
13
|
+
spec.homepage = "https://github.com/xwaynec/active_merchant_allpay"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'activemerchant', '>= 1.9.4'
|
22
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
require 'cgi'
|
4
|
+
require 'digest/md5'
|
5
|
+
|
6
|
+
module ActiveMerchant #:nodoc:
|
7
|
+
module Billing #:nodoc:
|
8
|
+
module Integrations #:nodoc:
|
9
|
+
module Allpay
|
10
|
+
class Helper < ActiveMerchant::Billing::Integrations::Helper
|
11
|
+
|
12
|
+
mapping :merchant_id, 'MerchantID'
|
13
|
+
mapping :merchant_trade_no, 'MerchantTradeNo'
|
14
|
+
mapping :payment_type, 'PaymentType'
|
15
|
+
mapping :total_amount, 'TotalAmount'
|
16
|
+
mapping :return_url, 'ReturnURL'
|
17
|
+
mapping :client_back_url, 'ClientBackURL'
|
18
|
+
mapping :choose_payment, 'ChoosePayment'
|
19
|
+
|
20
|
+
def initialize(order, account, options = {})
|
21
|
+
super
|
22
|
+
add_field 'MerchantID', ActiveMerchant::Billing::Integrations::Allpay.merchant_id
|
23
|
+
add_field 'PaymentType', ActiveMerchant::Billing::Integrations::Allpay::PAYMENT_TYPE
|
24
|
+
end
|
25
|
+
|
26
|
+
def merchant_trade_no(trade_number)
|
27
|
+
add_field 'MerchantTradeNo', trade_number
|
28
|
+
end
|
29
|
+
|
30
|
+
def merchant_trade_date(date)
|
31
|
+
add_field 'MerchantTradeDate', date.strftime('%Y/%m/%d %H:%M:%S')
|
32
|
+
end
|
33
|
+
|
34
|
+
def total_amount(amount)
|
35
|
+
add_field 'TotalAmount', amount
|
36
|
+
end
|
37
|
+
|
38
|
+
def trade_desc(description)
|
39
|
+
add_field 'TradeDesc', description
|
40
|
+
end
|
41
|
+
|
42
|
+
def item_name(item)
|
43
|
+
add_field 'ItemName', item
|
44
|
+
end
|
45
|
+
|
46
|
+
def choose_payment(payment)
|
47
|
+
add_field 'ChoosePayment', payment
|
48
|
+
end
|
49
|
+
|
50
|
+
def return_url(url)
|
51
|
+
add_field 'ReturnURL', url
|
52
|
+
end
|
53
|
+
|
54
|
+
def client_back_url(url)
|
55
|
+
add_field 'ClientBackURL', url
|
56
|
+
end
|
57
|
+
|
58
|
+
def encrypted_data
|
59
|
+
|
60
|
+
hash_data = {
|
61
|
+
:ChoosePayment => @fields['ChoosePayment'],
|
62
|
+
:ClientBackURL => @fields['ClientBackURL'],
|
63
|
+
:ItemName => @fields['ItemName'],
|
64
|
+
:MerchantID => @fields['MerchantID'],
|
65
|
+
:MerchantTradeDate => @fields['MerchantTradeDate'],
|
66
|
+
:MerchantTradeNo => @fields['MerchantTradeNo'],
|
67
|
+
:PaymentType => @fields['PaymentType'],
|
68
|
+
:ReturnURL => @fields['ReturnURL'],
|
69
|
+
:TotalAmount => @fields['TotalAmount'],
|
70
|
+
:TradeDesc => @fields['TradeDesc']
|
71
|
+
}
|
72
|
+
|
73
|
+
raw_data = hash_data.map do |x, y|
|
74
|
+
"#{x}=#{y}"
|
75
|
+
end.join('&')
|
76
|
+
|
77
|
+
hash_raw_data = "HashKey=#{ActiveMerchant::Billing::Integrations::Allpay.hash_key}&#{raw_data}&HashIV=#{ActiveMerchant::Billing::Integrations::Allpay.hash_iv}"
|
78
|
+
|
79
|
+
url_endcode_data = (CGI::escape(hash_raw_data)).downcase
|
80
|
+
|
81
|
+
add_field 'CheckMacValue', Digest::MD5.hexdigest(url_endcode_data)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module ActiveMerchant #:nodoc:
|
4
|
+
module Billing #:nodoc:
|
5
|
+
module Integrations #:nodoc:
|
6
|
+
module Allpay
|
7
|
+
class Notification < ActiveMerchant::Billing::Integrations::Notification
|
8
|
+
|
9
|
+
def status
|
10
|
+
if rtn_code == '1'
|
11
|
+
true
|
12
|
+
else
|
13
|
+
false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def checksum_ok?
|
18
|
+
checksum = @params.delete('CheckMacValue')
|
19
|
+
|
20
|
+
@params.delete('controller')
|
21
|
+
@params.delete('action')
|
22
|
+
|
23
|
+
raw_data = @params.map do |x, y|
|
24
|
+
"#{x}=#{y}"
|
25
|
+
end.join('&')
|
26
|
+
|
27
|
+
hash_raw_data = "HashKey=#{ActiveMerchant::Billing::Integrations::Allpay.hash_key}&#{raw_data}&HashIV=#{ActiveMerchant::Billing::Integrations::Allpay.hash_iv}"
|
28
|
+
|
29
|
+
url_endcode_data = (CGI::escape(hash_raw_data)).downcase
|
30
|
+
|
31
|
+
(Digest::MD5.hexdigest(url_endcode_data) == checksum.to_s.downcase)
|
32
|
+
end
|
33
|
+
|
34
|
+
def initialize(params)
|
35
|
+
self.params = params
|
36
|
+
end
|
37
|
+
|
38
|
+
def params=(params)
|
39
|
+
@params = params.inject({}) do |buffer, (name, value)|
|
40
|
+
buffer.merge(name.to_s => value)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def rtn_code
|
45
|
+
@params['RtnCode']
|
46
|
+
end
|
47
|
+
|
48
|
+
def merchant_id
|
49
|
+
@params['MerchantID']
|
50
|
+
end
|
51
|
+
|
52
|
+
def merchant_trade_no
|
53
|
+
@params['MerchantTradeNo']
|
54
|
+
end
|
55
|
+
|
56
|
+
def rtn_msg
|
57
|
+
@params['RtnMsg']
|
58
|
+
end
|
59
|
+
|
60
|
+
def trade_no
|
61
|
+
@params['TradeNo']
|
62
|
+
end
|
63
|
+
|
64
|
+
def trade_amt
|
65
|
+
@params['TradeAmt']
|
66
|
+
end
|
67
|
+
|
68
|
+
def payment_date
|
69
|
+
@params['PaymentDate']
|
70
|
+
end
|
71
|
+
|
72
|
+
def payment_type
|
73
|
+
@params['PaymentType']
|
74
|
+
end
|
75
|
+
|
76
|
+
def payment_type_charge_fee
|
77
|
+
@params['PaymentTypeChargeFee']
|
78
|
+
end
|
79
|
+
|
80
|
+
def trade_date
|
81
|
+
@params['TradeDate']
|
82
|
+
end
|
83
|
+
|
84
|
+
def simulate_paid
|
85
|
+
@params['SimulatePaid']
|
86
|
+
end
|
87
|
+
|
88
|
+
def check_mac_value
|
89
|
+
@params['CheckMacValue']
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
# Take the posted data and move the relevant data into a hash
|
95
|
+
def parse(post)
|
96
|
+
@raw = post.to_s
|
97
|
+
for line in @raw.split('&')
|
98
|
+
key, value = *line.scan(%r{^([A-Za-z0-9_.]+)\=(.*)$}).flatten
|
99
|
+
params[key] = CGI.unescape(value)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/allpay/helper.rb'
|
2
|
+
require File.dirname(__FILE__) + '/allpay/notification.rb'
|
3
|
+
|
4
|
+
module ActiveMerchant #:nodoc:
|
5
|
+
module Billing #:nodoc:
|
6
|
+
module Integrations #:nodoc:
|
7
|
+
module Allpay
|
8
|
+
autoload :Helper, 'active_merchant/billing/integrations/allpay/helper.rb'
|
9
|
+
autoload :Notification, 'active_merchant/billing/integrations/allpay/notification.rb'
|
10
|
+
|
11
|
+
PAYMENT_CREDIT_CARD = 'Credit'
|
12
|
+
PAYMENT_ATM = 'ATM'
|
13
|
+
PAYMENT_CVS = 'CVS'
|
14
|
+
|
15
|
+
PAYMENT_TYPE = 'aio'
|
16
|
+
|
17
|
+
mattr_accessor :service_url
|
18
|
+
mattr_accessor :merchant_id
|
19
|
+
mattr_accessor :hash_key
|
20
|
+
mattr_accessor :hash_iv
|
21
|
+
|
22
|
+
def self.service_url
|
23
|
+
mode = ActiveMerchant::Billing::Base.integration_mode
|
24
|
+
case mode
|
25
|
+
when :production
|
26
|
+
'https://payment.allpay.com.tw/Cashier/AioCheckOut'
|
27
|
+
when :development
|
28
|
+
'http://payment-stage.allpay.com.tw/Cashier/AioCheckOut'
|
29
|
+
when :test
|
30
|
+
'http://payment-stage.allpay.com.tw/Cashier/AioCheckOut'
|
31
|
+
else
|
32
|
+
raise StandardError, "Integration mode set to an invalid value: #{mode}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.notification(post)
|
37
|
+
Notification.new(post)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.setup
|
41
|
+
yield(self)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_merchant_allpay
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- xwaynec
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activemerchant
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.9.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.9.4
|
27
|
+
description: A rails plugin to add active_merchant patch for Taiwan payment
|
28
|
+
email:
|
29
|
+
- xwaynec@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- .gitignore
|
35
|
+
- Gemfile
|
36
|
+
- LICENSE.txt
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- active_merchant_allpay.gemspec
|
40
|
+
- lib/active_merchant/billing/integrations/allpay.rb
|
41
|
+
- lib/active_merchant/billing/integrations/allpay/helper.rb
|
42
|
+
- lib/active_merchant/billing/integrations/allpay/notification.rb
|
43
|
+
- lib/active_merchant_allpay.rb
|
44
|
+
- lib/active_merchant_allpay/version.rb
|
45
|
+
homepage: https://github.com/xwaynec/active_merchant_allpay
|
46
|
+
licenses:
|
47
|
+
- MIT
|
48
|
+
metadata: {}
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 2.1.9
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: A rails plugin to add active_merchant patch for Taiwan payment
|
69
|
+
test_files: []
|
70
|
+
has_rdoc:
|