focas-client 0.1.2 → 0.1.4

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: b083e5b0da2910143a54d9374252cbad5a5fa17d3a9c3f617ac77c980ec42b7a
4
- data.tar.gz: a1067fbb7afca792242235e6bfae1b8d8e1884650d931028499b27ce20e68754
3
+ metadata.gz: e8eaa764deded36176c987d6e4745d41bc22575972a84d1bd9cacd48744831cb
4
+ data.tar.gz: 920a967e3145c9a44862bd0d8b78550caf903157350d976d8ce2aeb29a720ce0
5
5
  SHA512:
6
- metadata.gz: d436deb7ebeabd939351d52e678105f89c167a764ceb1fee1090645208232280727b004f6a2e4c5df72b9e7a52280eb3c967e45ab76f3ae0dafead32cb16e0be
7
- data.tar.gz: 319c8d978c1202c7c3bff17b743619c1a50e64980f7f454094938c9e0616f12eb9235c2dd2a866cd2a0c4478c211fbb11f6db3a24282f91ca86257c5862b2619
6
+ metadata.gz: 67654996060afba1cb162628c4799871dca8298b5b4834f20356ca73aed8a915d849dd05c63fb0bf4083dcfbd06f6ef4108b9056e66474a2e0f9532f72af6b6d
7
+ data.tar.gz: 257bced906ad64453bb2b55f093de6fafc5195b738d9244ffd60bf3e239262209e01f22048aa22771c657474fdad7cd92d06d1d7cddb818ebfb4d300c6a2fa40
data/CHANGELOG.md CHANGED
@@ -1 +1 @@
1
- ## 0.1.2 (開發中)
1
+ ## 0.1.4 (開發中)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- focas-client (0.1.2)
4
+ focas-client (0.1.4)
5
5
  activesupport (>= 4.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -33,6 +33,7 @@ $ rails generate focas:install
33
33
  - config.mer_id = '' # 通常是統編
34
34
  - config.marchant_id = '' # 商店 ID
35
35
  - config.terminal_id = '' # 付費終端機 ID
36
+ - config.token = '' # 驗證參數(token),須在商店設定好,請銀行人員人工放行
36
37
  - config.customize = 1 # 使用客製頁面1
37
38
  - config.auto_cap = 1 # 自動請款
38
39
  - config.encode_type = 'UTF-8' # 編碼一定要用 UTF-8,避免亂碼
@@ -0,0 +1,40 @@
1
+ ## 刷卡成功 callback 範例
2
+
3
+ {
4
+ "errcode"=>"00",
5
+ "authCode"=>"AB1234",
6
+ "authRespTime"=>"20230502200708",
7
+ "lastPan4"=>"5101",
8
+ "amtExp"=>"0",
9
+ "xid"=>"xxx",
10
+ "errDesc"=>"",
11
+ "lidm"=>"xxx",
12
+ "authAmt"=>"5000",
13
+ "currency"=>"",
14
+ "merID"=>"xxx",
15
+ "cardBrand"=>"VISA",
16
+ "pan"=>"490706******5101",
17
+ "status"=>"0",
18
+ "controller"=>"xxx",
19
+ "action"=>"xxx"
20
+ }
21
+
22
+
23
+ ## 刷卡失敗 callback 範例
24
+
25
+ {
26
+ "errcode"=>"91",
27
+ "authCode"=>"",
28
+ "authRespTime"=>"20230503112403",
29
+ "lastPan4"=>"5101",
30
+ "amtExp"=>"0",
31
+ "xid"=>"xxx",
32
+ "errDesc"=>"%B1%C2%C5v%A5%A2%B1%D1", #(big5?)
33
+ "lidm"=>"xxx",
34
+ "authAmt"=>"10000",
35
+ "currency"=>"",
36
+ "merID"=>"xxx",
37
+ "cardBrand"=>"VISA",
38
+ "pan"=>"490706******5101",
39
+ "status"=>"8"
40
+ }
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
data/lib/focas/payment.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'net/http'
4
4
  require 'json'
5
+ require 'digest'
5
6
 
6
7
  require_relative 'config'
7
8
  require_relative 'errors'
@@ -45,11 +46,69 @@ module Focas
45
46
  @response['Status'] == 'SUCCESS'
46
47
  end
47
48
 
49
+ def check_resp_token(data)
50
+ # 資料錯誤的先 return
51
+ return false if not data.present?
52
+
53
+ ret = data.transform_keys(&:to_sym).to_h
54
+ return false if not ret[:respToken].present?
55
+
56
+
57
+ begin
58
+ # to hash
59
+ resp_token = ret[:respToken]
60
+
61
+ options = Config.options
62
+ settings = options.transform_keys(&:to_sym).to_h
63
+
64
+ # 檢查 ret[:status] 成功或失敗
65
+ if ret[:status] == '0'
66
+ # 成功
67
+ tmp_arr = %W(
68
+ #{ret[:status]}
69
+ #{ret[:lidm]}
70
+ #{settings[:token]}
71
+ #{ret[:authCode]}
72
+ #{ret[:authRespTime]}
73
+ #{settings[:merchant_id]}
74
+ #{settings[:terminal_id]}
75
+ )
76
+
77
+ hash_string = tmp_arr.join('&')
78
+ else
79
+ # 失敗
80
+ tmp_arr = %W(
81
+ #{ret[:status]}
82
+ #{ret[:errcode]}
83
+ #{ret[:lidm]}
84
+ #{settings[:token]}
85
+ #{ret[:authRespTime]}
86
+ #{settings[:merchant_id]}
87
+ #{settings[:terminal_id]}
88
+ )
89
+ end
90
+
91
+ # 開始驗證 token
92
+ hash_token = Digest::SHA256.hexdigest(hash_string).upcase
93
+ return (resp_token.upcase == hash_token)
94
+ rescue
95
+ return false
96
+ end
97
+ end
98
+
48
99
  private
49
100
 
50
101
  def set_trade_info
51
102
  options = Config.options
52
103
  @trade_info = options.transform_keys(&:to_sym).to_h
104
+ local_date = Time.now.strftime('%Y%m%d')
105
+ local_time = Time.now.strftime('%H%M%S')
106
+ trade_time = "#{local_date}#{local_time}"
107
+
108
+ # 訂單編號&交易金額&驗證參數&特店代號&端末代號&交易時間
109
+ hash_string = "#{@lidm}#{@purch_amt}#{@trade_info[:token]}#{@trade_info[:merchant_id]}#{@trade_info[:terminal_id]}#{trade_time}"
110
+
111
+ req_token = Digest::SHA256.hexdigest(hash_string).upcase
53
112
 
54
113
  individual_trade_info = {
55
114
  lidm: @lidm, # 商店訂單編號,如:用途_日期時間戳記_流水號
@@ -57,6 +116,9 @@ module Focas
57
116
  CurrencyNote: @currency_note, # 商品資訊
58
117
  # 回傳網址
59
118
  AuthResURL: @auth_res_url,
119
+ reqToken: req_token,
120
+ LocalDate: local_date,
121
+ LocalTime: local_time
60
122
  }
61
123
 
62
124
  individual_trade_info.merge!(options[:trade_info]) if options[:trade_info]
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.2'
4
+ VERSION = '0.1.4'
5
5
  end
@@ -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
  # 其他參數
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.2
4
+ version: 0.1.4
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-05-02 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
@@ -42,6 +42,7 @@ files:
42
42
  - Rakefile
43
43
  - bin/console
44
44
  - bin/setup
45
+ - doc/paid_status.md
45
46
  - focas-client.gemspec
46
47
  - lib/focas-client.rb
47
48
  - lib/focas/config.rb