active_merchant_ecpay 0.1.2
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 +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +95 -0
- data/Rakefile +6 -0
- data/active_merchant_ecpay.gemspec +33 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/active_merchant_ecpay.rb +13 -0
- data/lib/active_merchant_ecpay/version.rb +3 -0
- data/lib/offsite_payments/integrations/ecpay.rb +56 -0
- data/lib/offsite_payments/integrations/ecpay/helper.rb +217 -0
- data/lib/offsite_payments/integrations/ecpay/notification.rb +170 -0
- metadata +199 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: f6f1486db7a5d1d4e59e71ac6a8728da6770912a
|
|
4
|
+
data.tar.gz: feef310fb566b03580f2ffd5dfe00805f11c9f35
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 593db06557415056377b8a4590ba088b28a8729660d443e4eedb0f8a45d7c43c8cf5965eb8758668e62c838b1418c76b4be9039c35c9dacb7c8b3c99bc38ff87
|
|
7
|
+
data.tar.gz: edcf3f6cab3e0847db0b49d1206d6e257d7e7865603e66c8e80c9216c8abf8d1775c372359b916576b771595ecb29b52ba800f2df1de7c2579206d25028ffaf3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 sdlong
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# ActiveMerchantEcpay
|
|
2
|
+
|
|
3
|
+
This plugin is an active_merchant patch for ecpay(歐付寶) online payment in Taiwan.
|
|
4
|
+
Now it supports:
|
|
5
|
+
- Credit card(信用卡)
|
|
6
|
+
- ATM(虛擬ATM)
|
|
7
|
+
- BARCODE(超商條碼).
|
|
8
|
+
|
|
9
|
+
It has been tested on Rails 4.2 successfully.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Add this line to your application's Gemfile:
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
gem 'active_merchant_ecpay'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
And then execute:
|
|
20
|
+
|
|
21
|
+
$ bundle
|
|
22
|
+
|
|
23
|
+
Or install it yourself as:
|
|
24
|
+
|
|
25
|
+
$ gem install active_merchant_ecpay
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
You can get Payment API and SPEC in [Ecpay API](https://www.ecpay.com.tw/Content/files/ecpay_011.pdf).
|
|
30
|
+
Then create an initializer, like initializers/ecpay.rb. Add the following configurations depends on your settings.
|
|
31
|
+
|
|
32
|
+
``` ruby
|
|
33
|
+
# config/environments/development.rb
|
|
34
|
+
config.after_initialize do
|
|
35
|
+
ActiveMerchant::Billing::Base.mode = :development
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# config/environments/production.rb
|
|
39
|
+
config.after_initialize do
|
|
40
|
+
ActiveMerchant::Billing::Base.mode = :production
|
|
41
|
+
end
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
``` ruby
|
|
45
|
+
# initializers/ecpay.rb
|
|
46
|
+
OffsitePayments::Integrations::Ecpay.setup do |ecpay|
|
|
47
|
+
if Rails.env.development?
|
|
48
|
+
# default setting for stage test
|
|
49
|
+
ecpay.merchant_id = '2000132'
|
|
50
|
+
ecpay.hash_key = '5294y06JbISpM5x9'
|
|
51
|
+
ecpay.hash_iv = 'v77hoKGq4kWxNNIS'
|
|
52
|
+
else
|
|
53
|
+
# change to yours
|
|
54
|
+
ecpay.merchant_id = '23466XX'
|
|
55
|
+
ecpay.hash_key = 'adfasdsfgseweqwg'
|
|
56
|
+
ecpay.hash_iv = '15y3ersee34yasdf'
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Once you’ve configured ActiveMerchantEcpay, you need a checkout form; it looks like:
|
|
62
|
+
|
|
63
|
+
``` erb
|
|
64
|
+
<% payment_service_for @order.id,
|
|
65
|
+
@order.user.email,
|
|
66
|
+
service: :ecpay,
|
|
67
|
+
html: { method: :post } do |service| %>
|
|
68
|
+
<% service.merchant_trade_no "#{@order.id}T#{Time.zone.now}" %>
|
|
69
|
+
<% service.merchant_trade_date @order.created_at %>
|
|
70
|
+
<% service.total_amount @order.total.to_i %>
|
|
71
|
+
<% service.description @order.id %>
|
|
72
|
+
<% service.item_name @order.id %>
|
|
73
|
+
<% service.choose_payment OffsitePayments::Integrations::Ecpay::PAYMENT_ATM %>
|
|
74
|
+
<% service.return_url root_path %>
|
|
75
|
+
<% service.notify_url ecpay_atm_return_url %>
|
|
76
|
+
<% service.encrypted_data %>
|
|
77
|
+
<%= submit_tag 'Buy!' %>
|
|
78
|
+
<% end %>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Development
|
|
82
|
+
|
|
83
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
84
|
+
|
|
85
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
86
|
+
|
|
87
|
+
## Contributing
|
|
88
|
+
|
|
89
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/superlanding/active_merchant_ecpay.
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
95
|
+
|
data/Rakefile
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
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_ecpay/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "active_merchant_ecpay"
|
|
8
|
+
spec.version = ActiveMerchantEcpay::VERSION
|
|
9
|
+
spec.authors = ["Eddie Li"]
|
|
10
|
+
spec.email = ["eddie@super-landing.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{ActiveMerchant x Ecpay (綠界科技)}
|
|
13
|
+
spec.description = %q{This gem integrate Rails with ecpay (綠界科技).}
|
|
14
|
+
spec.homepage = "https://github.com/superlanding/active_merchant_ecpay"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
18
|
+
spec.bindir = "exe"
|
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
20
|
+
spec.require_paths = ["lib"]
|
|
21
|
+
|
|
22
|
+
spec.add_dependency 'activemerchant', '~> 1.50'
|
|
23
|
+
spec.add_dependency 'money'
|
|
24
|
+
spec.add_dependency 'offsite_payments', '~> 2'
|
|
25
|
+
|
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
29
|
+
spec.add_development_dependency('mocha', '~> 0.13.0')
|
|
30
|
+
spec.add_development_dependency('rails', '>= 2.3.14')
|
|
31
|
+
spec.add_development_dependency('pry')
|
|
32
|
+
spec.add_development_dependency('thor')
|
|
33
|
+
end
|
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "active_merchant_ecpay"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'action_view'
|
|
2
|
+
require "active_merchant_ecpay/version"
|
|
3
|
+
require 'active_merchant'
|
|
4
|
+
require 'money'
|
|
5
|
+
require 'offsite_payments'
|
|
6
|
+
|
|
7
|
+
module OffsitePayments
|
|
8
|
+
module Integrations
|
|
9
|
+
autoload :Ecpay, 'offsite_payments/integrations/ecpay'
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
ActionView::Base.send(:include, OffsitePayments::ActionViewHelper)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/ecpay/helper.rb'
|
|
2
|
+
require File.dirname(__FILE__) + '/ecpay/notification.rb'
|
|
3
|
+
|
|
4
|
+
module OffsitePayments #:nodoc:
|
|
5
|
+
module Integrations #:nodoc:
|
|
6
|
+
module Ecpay
|
|
7
|
+
PAYMENT_CREDIT_CARD = 'Credit'
|
|
8
|
+
PAYMENT_ATM = 'ATM'
|
|
9
|
+
PAYMENT_CVS = 'CVS'
|
|
10
|
+
PAYMENT_ALIPAY = 'Alipay'
|
|
11
|
+
PAYMENT_BARCODE = 'BARCODE'
|
|
12
|
+
|
|
13
|
+
SUBPAYMENT_ATM_TAISHIN = 'TAISHIN'
|
|
14
|
+
SUBPAYMENT_ATM_ESUN = 'ESUN'
|
|
15
|
+
SUBPAYMENT_ATM_HUANAN = 'HUANAN'
|
|
16
|
+
SUBPAYMENT_ATM_BOT = 'BOT'
|
|
17
|
+
SUBPAYMENT_ATM_FUBON = 'FUBON'
|
|
18
|
+
SUBPAYMENT_ATM_CHINATRUST = 'CHINATRUST'
|
|
19
|
+
SUBPAYMENT_ATM_FIRST = 'FIRST'
|
|
20
|
+
|
|
21
|
+
SUBPAYMENT_CVS_CVS = 'CVS'
|
|
22
|
+
SUBPAYMENT_CVS_OK = 'OK'
|
|
23
|
+
SUBPAYMENT_CVS_FAMILY = 'FAMILY'
|
|
24
|
+
SUBPAYMENT_CVS_HILIFE = 'HILIFE'
|
|
25
|
+
SUBPAYMENT_CVS_IBON = 'IBON'
|
|
26
|
+
|
|
27
|
+
PAYMENT_TYPE = 'aio'
|
|
28
|
+
|
|
29
|
+
mattr_accessor :service_url
|
|
30
|
+
mattr_accessor :merchant_id
|
|
31
|
+
mattr_accessor :hash_key
|
|
32
|
+
mattr_accessor :hash_iv
|
|
33
|
+
mattr_accessor :debug
|
|
34
|
+
|
|
35
|
+
def self.service_url
|
|
36
|
+
mode = ActiveMerchant::Billing::Base.mode
|
|
37
|
+
case mode
|
|
38
|
+
when :production
|
|
39
|
+
'https://payment.ecpay.com.tw/Cashier/AioCheckOut/V5'
|
|
40
|
+
when :development, :test
|
|
41
|
+
'https://payment-stage.ecpay.com.tw/Cashier/AioCheckOut/V5'
|
|
42
|
+
else
|
|
43
|
+
raise StandardError, "Integration mode set to an invalid value: #{mode}"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.notification(post)
|
|
48
|
+
Notification.new(post)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def self.setup
|
|
52
|
+
yield(self)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
require 'digest/md5'
|
|
2
|
+
|
|
3
|
+
module OffsitePayments #:nodoc:
|
|
4
|
+
module Integrations #:nodoc:
|
|
5
|
+
module Ecpay
|
|
6
|
+
class Helper < OffsitePayments::Helper
|
|
7
|
+
### 預設介面
|
|
8
|
+
|
|
9
|
+
# 廠商編號(由 ecpay 提供)
|
|
10
|
+
# type: Varchar(10)
|
|
11
|
+
# presense: true
|
|
12
|
+
# example: 2000132
|
|
13
|
+
# description:
|
|
14
|
+
mapping :merchant_id, 'MerchantID'
|
|
15
|
+
mapping :account, 'MerchantID' # AM common
|
|
16
|
+
|
|
17
|
+
# 廠商交易編號
|
|
18
|
+
# type: Varchar(20)
|
|
19
|
+
# presense: true
|
|
20
|
+
# example: ecpay1234
|
|
21
|
+
# description: 廠商交易編號不可重覆。英數字大小寫混合
|
|
22
|
+
mapping :merchant_trade_no, 'MerchantTradeNo'
|
|
23
|
+
mapping :order, 'MerchantTradeNo' # AM common
|
|
24
|
+
|
|
25
|
+
# 廠商交易時間
|
|
26
|
+
# type: Varchar(20)
|
|
27
|
+
# presense: true
|
|
28
|
+
# example: 2012/03/21 15:40:18
|
|
29
|
+
# description: 格式為:yyyy/MM/dd HH:mm:ss
|
|
30
|
+
mapping :merchant_trade_date, 'MerchantTradeDate'
|
|
31
|
+
|
|
32
|
+
# 交易類型
|
|
33
|
+
# type: Varchar(20)
|
|
34
|
+
# presense: true
|
|
35
|
+
# example: aio
|
|
36
|
+
# description: 請帶 aio
|
|
37
|
+
mapping :payment_type, 'PaymentType'
|
|
38
|
+
|
|
39
|
+
# 交易金額
|
|
40
|
+
# type: Varchar(20)
|
|
41
|
+
# presense: true
|
|
42
|
+
# example:
|
|
43
|
+
# description:
|
|
44
|
+
mapping :total_amount, 'TotalAmount'
|
|
45
|
+
mapping :amount, 'TotalAmount' # AM common
|
|
46
|
+
|
|
47
|
+
# 交易描述
|
|
48
|
+
# type: Varchar(20)
|
|
49
|
+
# presense: true
|
|
50
|
+
# example:
|
|
51
|
+
# description:
|
|
52
|
+
mapping :description, 'TradeDesc'
|
|
53
|
+
|
|
54
|
+
# 商品名稱
|
|
55
|
+
# type: Varchar(20)
|
|
56
|
+
# presense: true
|
|
57
|
+
# example:
|
|
58
|
+
# description:
|
|
59
|
+
mapping :item_name, 'ItemName'
|
|
60
|
+
|
|
61
|
+
# 付款完成通知回傳網址
|
|
62
|
+
# type: Varchar(20)
|
|
63
|
+
# presense: true
|
|
64
|
+
# example:
|
|
65
|
+
# description:
|
|
66
|
+
mapping :notify_url, 'ReturnURL' # AM common
|
|
67
|
+
|
|
68
|
+
# 選擇預設付款方式
|
|
69
|
+
# type: Varchar(20)
|
|
70
|
+
# presense: true
|
|
71
|
+
# example:
|
|
72
|
+
# description:
|
|
73
|
+
mapping :choose_payment, 'ChoosePayment'
|
|
74
|
+
|
|
75
|
+
# 檢查碼
|
|
76
|
+
# type: Varchar(20)
|
|
77
|
+
# presense: true
|
|
78
|
+
# example:
|
|
79
|
+
# description:
|
|
80
|
+
mapping :check_mac_value, 'CheckMacValue'
|
|
81
|
+
|
|
82
|
+
# Client 端返回廠商網址
|
|
83
|
+
# type: Varchar(20)
|
|
84
|
+
# presense: true
|
|
85
|
+
# example:
|
|
86
|
+
# description:
|
|
87
|
+
mapping :client_back_url, 'ClientBackURL'
|
|
88
|
+
mapping :return_url, 'ClientBackURL' # AM common
|
|
89
|
+
|
|
90
|
+
# 商品銷售網址
|
|
91
|
+
mapping :item_url, 'ItemURL'
|
|
92
|
+
|
|
93
|
+
# 備註欄位。
|
|
94
|
+
mapping :remark, 'Remark'
|
|
95
|
+
|
|
96
|
+
# 選擇預設付款子項目
|
|
97
|
+
mapping :choose_sub_payment, 'ChooseSubPayment'
|
|
98
|
+
|
|
99
|
+
# 付款完成 redirect 的網址
|
|
100
|
+
mapping :redirect_url, 'OrderResultURL'
|
|
101
|
+
|
|
102
|
+
# 是否需要額外的付款資訊, defalut: N
|
|
103
|
+
mapping :need_extra_paid_info, 'NeedExtraPaidInfo'
|
|
104
|
+
|
|
105
|
+
# 裝置來源, defalut: P
|
|
106
|
+
mapping :devise_source, 'DeviceSource'
|
|
107
|
+
|
|
108
|
+
# 忽略的付款方式
|
|
109
|
+
mapping :ignore_payment, 'IgnorePayment'
|
|
110
|
+
|
|
111
|
+
# 特約合作平台商代號(由ecpay提供)
|
|
112
|
+
mapping :platform_id, 'PlatformID'
|
|
113
|
+
|
|
114
|
+
# 電子發票開註記
|
|
115
|
+
mapping :invoice_mark, 'InvoiceMark'
|
|
116
|
+
|
|
117
|
+
# 是否延遲撥款, defalut: 0
|
|
118
|
+
mapping :hold_trade_amt, 'HoldTradeAMT'
|
|
119
|
+
|
|
120
|
+
# CheckMacValue 加密類型, defalut: 0
|
|
121
|
+
mapping :encrypt_type, 'EncryptType'
|
|
122
|
+
|
|
123
|
+
### ChoosePayment 為 ATM/CVS/BARCODE
|
|
124
|
+
|
|
125
|
+
# ATM, CVS 序號回傳網址 (Server Side)
|
|
126
|
+
mapping :payment_info_url, 'PaymentInfoURL'
|
|
127
|
+
# ATM, CVS 序號頁面回傳網址 (Client Side)
|
|
128
|
+
mapping :client_redirect_url, 'ClientRedirectURL'
|
|
129
|
+
mapping :payment_redirect_url, 'ClientRedirectURL'
|
|
130
|
+
|
|
131
|
+
### ATM
|
|
132
|
+
|
|
133
|
+
# ATM 允許繳費有效天數
|
|
134
|
+
mapping :expire_date, 'ExpireDate'
|
|
135
|
+
|
|
136
|
+
### CVS/BARCODE
|
|
137
|
+
|
|
138
|
+
# 超商繳費截止時間
|
|
139
|
+
mapping :store_expire_date, 'StoreExpireDate'
|
|
140
|
+
# 交易描述1
|
|
141
|
+
mapping :desc_1, 'Desc_1'
|
|
142
|
+
# 交易描述2
|
|
143
|
+
mapping :desc_2, 'Desc_2'
|
|
144
|
+
# 交易描述3
|
|
145
|
+
mapping :desc_3, 'Desc_3'
|
|
146
|
+
# 交易描述4
|
|
147
|
+
mapping :desc_4, 'Desc_4'
|
|
148
|
+
|
|
149
|
+
### Alipay
|
|
150
|
+
mapping :alipay_item_name, 'AlipayItemName'
|
|
151
|
+
mapping :alipay_item_counts, 'AlipayItemCounts'
|
|
152
|
+
mapping :alipay_item_price, 'AlipayItemPrice'
|
|
153
|
+
mapping :email, 'Email'
|
|
154
|
+
mapping :phone_no, 'PhoneNo'
|
|
155
|
+
mapping :uder_name, 'UserName'
|
|
156
|
+
mapping :expire_time, 'ExpireTime'
|
|
157
|
+
|
|
158
|
+
def initialize(order, account, options = {})
|
|
159
|
+
super
|
|
160
|
+
add_field 'MerchantID', OffsitePayments::Integrations::Ecpay.merchant_id
|
|
161
|
+
add_field 'PaymentType', OffsitePayments::Integrations::Ecpay::PAYMENT_TYPE
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def merchant_trade_date(date)
|
|
165
|
+
add_field 'MerchantTradeDate', date.strftime('%Y/%m/%d %H:%M:%S')
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def hash_key(key)
|
|
169
|
+
@key = key
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def hash_iv(iv)
|
|
173
|
+
@iv = iv
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def merchant_hash_key
|
|
177
|
+
@key || OffsitePayments::Integrations::Ecpay.hash_key
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def merchant_hash_iv
|
|
181
|
+
@iv || OffsitePayments::Integrations::Ecpay.hash_iv
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def encrypted_data
|
|
185
|
+
|
|
186
|
+
raw_data = @fields.sort.map{|field, value|
|
|
187
|
+
# utf8, authenticity_token, commit are generated from form helper, needed to skip
|
|
188
|
+
"#{field}=#{value}" if field!='utf8' && field!='authenticity_token' && field!='commit'
|
|
189
|
+
}.join('&')
|
|
190
|
+
|
|
191
|
+
hash_raw_data = "HashKey=#{merchant_hash_key}&#{raw_data}&HashIV=#{merchant_hash_iv}"
|
|
192
|
+
url_encode_data = self.class.url_encode(hash_raw_data)
|
|
193
|
+
url_encode_data.downcase!
|
|
194
|
+
|
|
195
|
+
binding.pry if OffsitePayments::Integrations::Ecpay.debug
|
|
196
|
+
|
|
197
|
+
add_field 'CheckMacValue', Digest::MD5.hexdigest(url_encode_data).upcase
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# ecpay .NET url encoding
|
|
201
|
+
# Code based from CGI.escape()
|
|
202
|
+
# Some special characters (e.g. "()*!") are not escaped on ecpay server when they generate their check sum value, causing CheckMacValue Error.
|
|
203
|
+
#
|
|
204
|
+
# TODO: The following characters still cause CheckMacValue error:
|
|
205
|
+
# '<', "\n", "\r", '&'
|
|
206
|
+
def self.url_encode(text)
|
|
207
|
+
text = text.dup
|
|
208
|
+
text.gsub!(/([^ a-zA-Z0-9\(\)\!\*_.-]+)/) do
|
|
209
|
+
'%' + $1.unpack('H2' * $1.bytesize).join('%')
|
|
210
|
+
end
|
|
211
|
+
text.tr!(' ', '+')
|
|
212
|
+
text
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
end
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
|
|
3
|
+
module OffsitePayments #:nodoc:
|
|
4
|
+
module Integrations #:nodoc:
|
|
5
|
+
module Ecpay
|
|
6
|
+
class Notification < OffsitePayments::Notification
|
|
7
|
+
|
|
8
|
+
def status
|
|
9
|
+
if rtn_code == '1'
|
|
10
|
+
true
|
|
11
|
+
else
|
|
12
|
+
false
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# TODO 使用查詢功能實作 acknowledge
|
|
17
|
+
# Ecpay 沒有遠端驗證功能,
|
|
18
|
+
# 而以 checksum_ok? 代替
|
|
19
|
+
def acknowledge
|
|
20
|
+
checksum_ok?
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def complete?
|
|
24
|
+
case @params['RtnCode']
|
|
25
|
+
when '1' #付款成功
|
|
26
|
+
true
|
|
27
|
+
when '2' # ATM 取號成功
|
|
28
|
+
true
|
|
29
|
+
when '10100073' # CVS 或 BARCODE 取號成功
|
|
30
|
+
true
|
|
31
|
+
when '800' #貨到付款訂單建立成功
|
|
32
|
+
true
|
|
33
|
+
else
|
|
34
|
+
false
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def hash_key=(key)
|
|
39
|
+
@hash_key = key
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def hash_iv=(iv)
|
|
43
|
+
@hash_iv = iv
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def hash_key
|
|
47
|
+
@hash_key || OffsitePayments::Integrations::Ecpay.hash_key
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def hash_iv
|
|
51
|
+
@hash_iv || OffsitePayments::Integrations::Ecpay.hash_iv
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def checksum_ok?
|
|
55
|
+
params_copy = @params.clone
|
|
56
|
+
|
|
57
|
+
checksum = params_copy.delete('CheckMacValue')
|
|
58
|
+
|
|
59
|
+
# 把 params 轉成 query string 前必須先依照 hash key 做 sort
|
|
60
|
+
# 依照英文字母排序,由 A 到 Z 且大小寫不敏感
|
|
61
|
+
raw_data = params_copy.sort_by{ |k,v| k.downcase }.map do |x, y|
|
|
62
|
+
"#{x}=#{y}"
|
|
63
|
+
end.join('&')
|
|
64
|
+
|
|
65
|
+
hash_raw_data = "HashKey=#{hash_key}&#{raw_data}&HashIV=#{hash_iv}"
|
|
66
|
+
|
|
67
|
+
url_encode_data = OffsitePayments::Integrations::Ecpay::Helper.url_encode(hash_raw_data)
|
|
68
|
+
url_encode_data.downcase!
|
|
69
|
+
|
|
70
|
+
(Digest::MD5.hexdigest(url_encode_data) == checksum.to_s.downcase)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def rtn_code
|
|
74
|
+
@params['RtnCode']
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def merchant_id
|
|
78
|
+
@params['MerchantID']
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# 廠商交易編號
|
|
82
|
+
def merchant_trade_no
|
|
83
|
+
@params['MerchantTradeNo']
|
|
84
|
+
end
|
|
85
|
+
alias :item_id :merchant_trade_no
|
|
86
|
+
|
|
87
|
+
def rtn_msg
|
|
88
|
+
@params['RtnMsg']
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# EcPay 的交易編號
|
|
92
|
+
def trade_no
|
|
93
|
+
@params['TradeNo']
|
|
94
|
+
end
|
|
95
|
+
alias :transaction_id :trade_no
|
|
96
|
+
|
|
97
|
+
def trade_amt
|
|
98
|
+
@params['TradeAmt']
|
|
99
|
+
end
|
|
100
|
+
def gross
|
|
101
|
+
::Money.new(@params['TradeAmt'].to_i * 100, currency)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def payment_date
|
|
105
|
+
@params['PaymentDate']
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def payment_type
|
|
109
|
+
@params['PaymentType']
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def payment_type_charge_fee
|
|
113
|
+
@params['PaymentTypeChargeFee']
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def trade_date
|
|
117
|
+
@params['TradeDate']
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def simulate_paid
|
|
121
|
+
@params['SimulatePaid']
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def check_mac_value
|
|
125
|
+
@params['CheckMacValue']
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# for ATM
|
|
129
|
+
def bank_code
|
|
130
|
+
@params['BankCode']
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def v_account
|
|
134
|
+
@params['vAccount']
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def expire_date
|
|
138
|
+
@params['ExpireDate']
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# for CreditCard
|
|
142
|
+
def card4no
|
|
143
|
+
@params['card4no']
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# for CVS
|
|
147
|
+
def payment_no
|
|
148
|
+
@params['PaymentNo']
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def currency
|
|
152
|
+
'TWD'
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# for BARCODE
|
|
156
|
+
def barcode1
|
|
157
|
+
@params['Barcode1']
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def barcode2
|
|
161
|
+
@params['Barcode2']
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def barcode3
|
|
165
|
+
@params['Barcode3']
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: active_merchant_ecpay
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Eddie Li
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-11-16 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.50'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.50'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: money
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: offsite_payments
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '2'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '2'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: bundler
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '1.14'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '1.14'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rake
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '10.0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '10.0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rspec
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '3.0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '3.0'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: mocha
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: 0.13.0
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: 0.13.0
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: rails
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - ">="
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: 2.3.14
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - ">="
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: 2.3.14
|
|
125
|
+
- !ruby/object:Gem::Dependency
|
|
126
|
+
name: pry
|
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
|
128
|
+
requirements:
|
|
129
|
+
- - ">="
|
|
130
|
+
- !ruby/object:Gem::Version
|
|
131
|
+
version: '0'
|
|
132
|
+
type: :development
|
|
133
|
+
prerelease: false
|
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
135
|
+
requirements:
|
|
136
|
+
- - ">="
|
|
137
|
+
- !ruby/object:Gem::Version
|
|
138
|
+
version: '0'
|
|
139
|
+
- !ruby/object:Gem::Dependency
|
|
140
|
+
name: thor
|
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
|
142
|
+
requirements:
|
|
143
|
+
- - ">="
|
|
144
|
+
- !ruby/object:Gem::Version
|
|
145
|
+
version: '0'
|
|
146
|
+
type: :development
|
|
147
|
+
prerelease: false
|
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
149
|
+
requirements:
|
|
150
|
+
- - ">="
|
|
151
|
+
- !ruby/object:Gem::Version
|
|
152
|
+
version: '0'
|
|
153
|
+
description: This gem integrate Rails with ecpay (綠界科技).
|
|
154
|
+
email:
|
|
155
|
+
- eddie@super-landing.com
|
|
156
|
+
executables: []
|
|
157
|
+
extensions: []
|
|
158
|
+
extra_rdoc_files: []
|
|
159
|
+
files:
|
|
160
|
+
- ".gitignore"
|
|
161
|
+
- ".rspec"
|
|
162
|
+
- ".travis.yml"
|
|
163
|
+
- Gemfile
|
|
164
|
+
- LICENSE.txt
|
|
165
|
+
- README.md
|
|
166
|
+
- Rakefile
|
|
167
|
+
- active_merchant_ecpay.gemspec
|
|
168
|
+
- bin/console
|
|
169
|
+
- bin/setup
|
|
170
|
+
- lib/active_merchant_ecpay.rb
|
|
171
|
+
- lib/active_merchant_ecpay/version.rb
|
|
172
|
+
- lib/offsite_payments/integrations/ecpay.rb
|
|
173
|
+
- lib/offsite_payments/integrations/ecpay/helper.rb
|
|
174
|
+
- lib/offsite_payments/integrations/ecpay/notification.rb
|
|
175
|
+
homepage: https://github.com/superlanding/active_merchant_ecpay
|
|
176
|
+
licenses:
|
|
177
|
+
- MIT
|
|
178
|
+
metadata: {}
|
|
179
|
+
post_install_message:
|
|
180
|
+
rdoc_options: []
|
|
181
|
+
require_paths:
|
|
182
|
+
- lib
|
|
183
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
184
|
+
requirements:
|
|
185
|
+
- - ">="
|
|
186
|
+
- !ruby/object:Gem::Version
|
|
187
|
+
version: '0'
|
|
188
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
189
|
+
requirements:
|
|
190
|
+
- - ">="
|
|
191
|
+
- !ruby/object:Gem::Version
|
|
192
|
+
version: '0'
|
|
193
|
+
requirements: []
|
|
194
|
+
rubyforge_project:
|
|
195
|
+
rubygems_version: 2.4.8
|
|
196
|
+
signing_key:
|
|
197
|
+
specification_version: 4
|
|
198
|
+
summary: ActiveMerchant x Ecpay (綠界科技)
|
|
199
|
+
test_files: []
|