focas-client 0.1.1 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eda8b71ebb1b5782bfc98a1a3a80eb0c7ff797bd2c7c97284b44b7d1d29e6ddf
4
- data.tar.gz: 8a48b3886d3ff230d1d23a9484eebc3f94af58e72326e96a668b7d2f6f30a329
3
+ metadata.gz: 74330bb8c48da9e0697d4a6960d2deac6a3c5f1d157b8ac6b12109f1912e08e8
4
+ data.tar.gz: ac10d85a495cd9527c79b728d81b73208af58b79c5ea175584065461599bea0f
5
5
  SHA512:
6
- metadata.gz: e45e4fed447778fbf83237be62cb60c948a0be3461cddf9b5a208372de09b59615f82fd1b8eae56d33665375598ca4874a6ee1702ee1a456ec19403d72f2cfb3
7
- data.tar.gz: 276453f7db9b85feaec6f1aa1b277207c7d1b80e7187c17e0c9fba4d6d237eb166094bdd8510b0450dee8455e43da2fc2ad22447f6dad91c913cccf4eb09e7db
6
+ metadata.gz: 4d7de62c28c8a71929c5db46a8be26398f00046b920133d3529f637493a70d69a0f757e94d482d4d2d14664c8503b5f7aeda6ed46c80296e519d73035bb8f186
7
+ data.tar.gz: 36056fa2f61e7f3c653834e3d47d0cf3953a92eaf5a7ee087f4194917b6518c0eec3b9684b6ff5bd20918a4f13e71cd47a18073ac5c40e0f249a259588c05cf8
data/CHANGELOG.md CHANGED
@@ -1 +1 @@
1
- ## 0.1.1 (開發中)
1
+ ## 0.1.3 (開發中)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- focas-client (0.1.1)
4
+ focas-client (0.1.3)
5
5
  activesupport (>= 4.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -29,27 +29,17 @@ $ rails generate focas:install
29
29
  設定 `config/initializers/focas.rb`:
30
30
 
31
31
  ```yml
32
- - config.production_mode # 0: 開發環境 / 1: 正式站,預設為 0
33
- - config.mer_id # 通常是統編
34
- - config.marchant_id # 商店 ID
35
- - config.terminal_id # 付費終端機 ID
32
+ - config.production_mode # 0: 開發環境 / 1: 正式站,預設為 0
33
+ - config.mer_id = '' # 通常是統編
34
+ - config.marchant_id = '' # 商店 ID
35
+ - config.terminal_id = '' # 付費終端機 ID
36
+ - config.token = '' # 驗證參數(token),須在商店設定好,請銀行人員人工放行
37
+ - config.customize = 1 # 使用客製頁面1
38
+ - config.auto_cap = 1 # 自動請款
39
+ - config.encode_type = 'UTF-8' # 編碼一定要用 UTF-8,避免亂碼
40
+ - config.currency = 901 # 交易幣別,901 新台幣
36
41
  ```
37
42
 
38
- ## Usage
39
-
40
- TODO: Write usage instructions here
41
-
42
- ## Development
43
-
44
- 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.
45
-
46
- 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).
47
-
48
- ## Contributing
49
-
50
- Bug reports and pull requests are welcome on GitHub at https://github.com/pct/focas-client.
51
-
52
-
53
43
  ## License
54
44
 
55
45
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/lib/focas/config.rb CHANGED
@@ -16,6 +16,7 @@ module Focas
16
16
  mattr_accessor :api_base_url # 依據 production_mode 設定 api 網址
17
17
 
18
18
  OPTIONS = %w[
19
+ token
19
20
  merID
20
21
  MerchantID
21
22
  TerminalID
@@ -45,6 +46,7 @@ module Focas
45
46
  # 標 **[必] 為必填,另外 threeDSAuthInd 是 3DS 驗證,需要時就必填
46
47
  # TradeInfo 參數
47
48
  MAPPING_TABLE = {
49
+ token: 'token', # **[必] 驗證參數,於商店自行設定,然後請銀行人員人工放行
48
50
  merID: 'mer_id', # **[必] 網站特店自訂代碼(請注意 merID 與 MerchantID 不同), number <= 10
49
51
  MerchantID: 'merchant_id', # **[必] 收單銀行授權使用的特店代號(由收單銀行編製提供), number 固定 15
50
52
  TerminalID: 'terminal_id', # **[必] 收單銀行授權使用的機台代號(由收單銀行編製提供), number 固定 8
@@ -65,7 +67,7 @@ module Focas
65
67
  enCodeType: 'encode_type', # *[必] 網頁編碼格式(預設為 BIG5),所以必傳 "UTF-8"
66
68
  timeoutDate: 'timeout_date', # 設定交易逾時日期(yyyymmdd),固定長度 8 位
67
69
  timeoutTime: 'timeout_time', # 設定交易逾時起始時間(HHMMSS),固定長度 6 位
68
- timeoutSecs: 'timeout_secs', # 設定交易逾時秒數,固定長度 3 位 (最大值為 600 秒)
70
+ timeoutSecs: 'timeout_secs', # 設定交易逾時秒數,固定長度 3 位 (最大值為 600 秒),先不設定,使用 600 會錯
69
71
  Currency: 'currency', # 交易幣別,固定長度 3 位 (901)
70
72
  lagSelect: 'lag_select', # 語言選擇,固定長度 1 位 (0: 繁 / 1: 簡 / 2: 英 / 3: 日 )
71
73
  threeDSAuthInd: 'three_ds_auth_ind', # 3D 交易驗證類型,若該特店設定支援 3D 交易,前端未帶此欄位,則預設為 0101 (0101 表示支付類交易驗證(PA)的 Payment transaction。 0204 表示非支付類交易驗證(NPA)的 Add card。0205 表示非支付類交易驗證(NPA)的 Maintain card。 註:綁卡驗證應使用 0204 或 0205)
data/lib/focas/payment.rb CHANGED
@@ -45,19 +45,69 @@ module Focas
45
45
  @response['Status'] == 'SUCCESS'
46
46
  end
47
47
 
48
- def gen_payment_params
49
- {
50
- merID: Config.options[:merID], # merID (統一編號)
51
- MerchantID: Config.options[:MerchantID], # 商店 ID
52
- TerminalID: Config.options[:TerminalID], # 終端機
53
- }
48
+ def check_resp_token(data)
49
+ # 資料錯誤的先 return
50
+ return false if not data.present?
51
+
52
+ ret = data.transform_keys(&:to_sym).to_h
53
+ return false if not ret[:respToken].present?
54
+
55
+
56
+ begin
57
+ # to hash
58
+ resp_token = ret[:respToken]
59
+
60
+ options = Config.options
61
+ settings = options.transform_keys(&:to_sym).to_h
62
+
63
+ # 檢查 ret[:status] 成功或失敗
64
+ if ret[:status] == '0'
65
+ # 成功
66
+ tmp_arr = %W(
67
+ #{ret[:status]}
68
+ #{ret[:lidm]}
69
+ #{settings[:token]}
70
+ #{ret[:authCode]}
71
+ #{ret[:authRespTime]}
72
+ #{settings[:merchant_id]}
73
+ #{settings[:terminal_id]}
74
+ )
75
+
76
+ hash_string = tmp_arr.join('&')
77
+ else
78
+ # 失敗
79
+ tmp_arr = %W(
80
+ #{ret[:status]}
81
+ #{ret[:errcode]}
82
+ #{ret[:lidm]}
83
+ #{settings[:token]}
84
+ #{ret[:authRespTime]}
85
+ #{settings[:merchant_id]}
86
+ #{settings[:terminal_id]}
87
+ )
88
+ end
89
+
90
+ # 開始驗證 token
91
+ hash_token = Digest::SHA256.hexdigest(hash_string).upcase
92
+ return (resp_token.upcase == hash_token)
93
+ rescue
94
+ return false
95
+ end
54
96
  end
55
97
 
56
98
  private
57
99
 
58
100
  def set_trade_info
59
101
  options = Config.options
60
- @trade_info = options.transform_keys(&:to_sym)
102
+ @trade_info = options.transform_keys(&:to_sym).to_h
103
+ local_date = Time.now.strftime('%Y%m%d')
104
+ local_time = Time.now.strftime('%H%M%S')
105
+ trade_time = "#{local_date}#{local_time}"
106
+
107
+ # 訂單編號&交易金額&驗證參數&特店代號&端末代號&交易時間
108
+ hash_string = "#{@lidm}#{@purch_amt}#{@trade_info[:token]}#{@trade_info[:merchant_id]}#{@trade_info[:terminal_id]}#{trade_time}"
109
+
110
+ req_token = Digest::SHA256.hexdigest(hash_string).upcase
61
111
 
62
112
  individual_trade_info = {
63
113
  lidm: @lidm, # 商店訂單編號,如:用途_日期時間戳記_流水號
@@ -65,9 +115,15 @@ module Focas
65
115
  CurrencyNote: @currency_note, # 商品資訊
66
116
  # 回傳網址
67
117
  AuthResURL: @auth_res_url,
118
+ reqToken: req_token,
119
+ LocalDate: local_date,
120
+ LocalTime: local_time
68
121
  }
69
122
 
70
- @trade_info.merge!(individual_trade_info)
123
+ individual_trade_info.merge!(options[:trade_info]) if options[:trade_info]
124
+
125
+ # 同是 hash 再來 merge
126
+ @trade_info = (options.to_h.merge!(individual_trade_info)).transform_keys(&:to_sym)
71
127
  end
72
128
  end
73
129
  end
data/lib/focas/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Focas
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.3'
5
5
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- focas.configure do |config|
3
+ Focas.configure do |config|
4
4
  # ========
5
5
  # 必要參數
6
6
  # ========
@@ -8,6 +8,9 @@ focas.configure do |config|
8
8
  # (0/1 使用財金資訊 正式站與否,預設為 0 測試站)
9
9
  config.production_mode = 0
10
10
 
11
+ # **[必] 驗證參數(請於商店設定,然後請銀行人員人工放行)
12
+ config.token = ''
13
+
11
14
  # **[必] 網站特店自訂代碼(請注意 merID 與 MerchantID 不同), number <= 10 (通常是統編)
12
15
  config.mer_id = ''
13
16
 
@@ -17,11 +20,12 @@ focas.configure do |config|
17
20
  # **[必] 收單銀行授權使用的機台代號(由收單銀行編製提供), number 固定 8
18
21
  config.terminal_id = ''
19
22
 
23
+ # **[必] 客製化付款授權網頁辨識碼(0: 預設不客製 / 1-8: 樣式1-8)
24
+ config.customize = 0
25
+
20
26
  # 特店名稱,僅供顯示
21
27
  config.merchant_name = ''
22
28
 
23
- # **[必] 客製化付款授權網頁辨識碼(0: 預設不客製 / 1-8: 樣式1-8)
24
- config.customize = 1
25
29
 
26
30
  # ========
27
31
  # 其他參數
@@ -47,8 +51,8 @@ focas.configure do |config|
47
51
  # *[必] 網頁編碼格式(預設為 BIG5),所以必傳 "UTF-8"
48
52
  config.encode_type = 'UTF-8'
49
53
 
50
- # 設定交易逾時秒數,固定長度 3 位 (最大值為 600 秒)
51
- config.timeout_secs = 600
54
+ # 設定交易逾時秒數,固定長度 3 位 (最大值為 600 秒),先不設定,使用 600 會錯
55
+ #config.timeout_secs = 600
52
56
 
53
57
  # 交易幣別,固定長度 3 位 (901)
54
58
  config.currency = 901
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: focas-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Lin (pct)
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-28 00:00:00.000000000 Z
11
+ date: 2023-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport