tappay_ruby 0.9.0 → 0.11.0
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 +4 -4
- data/README.md +27 -74
- data/lib/tappay/configuration.rb +1 -1
- data/lib/tappay/credit_card/instalment.rb +8 -0
- data/lib/tappay/jko_pay/pay.rb +4 -0
- data/lib/tappay/line_pay/pay.rb +4 -0
- data/lib/tappay/payment_base.rb +16 -34
- data/lib/tappay/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 920fd5c582914989062cb76fc47306e6ec3b4714b2558e2d4f04e2e43c4c11a0
|
|
4
|
+
data.tar.gz: 85a9f5331b47bdfbb78f81da3236d5123086f873e1260fb68b5c757bb7984e1d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9fb651e7b40a652a725896d697a75a3e47484f58bc64102b057bfa2a8b049f0427b8c1bdb0dcaa229d84f999898e291b9bfd36548e0ce012fdff4cb706201b03
|
|
7
|
+
data.tar.gz: 62b665b0e9d15c07966cc61998d215ff2e531a1664d5dffd824b9fc116db93a4c031f1f5271e5701cc445793056bd167ca561c6688064a281707dcba17e27839
|
data/README.md
CHANGED
|
@@ -10,9 +10,13 @@ A Ruby library for integrating with TapPay payment services. This gem provides a
|
|
|
10
10
|
|
|
11
11
|
- Multiple payment methods:
|
|
12
12
|
- Credit card payments (one-time and tokenized)
|
|
13
|
-
- Instalment payments (3
|
|
13
|
+
- Instalment payments (3, 6, 12, 18, 24, 30 months)
|
|
14
14
|
- Line Pay
|
|
15
15
|
- JKO Pay
|
|
16
|
+
- Flexible merchant identification:
|
|
17
|
+
- Support for both `merchant_id` and `merchant_group_id`
|
|
18
|
+
- Automatic fallback handling
|
|
19
|
+
- Priority-based merchant ID resolution
|
|
16
20
|
- Refund processing
|
|
17
21
|
- Transaction status queries
|
|
18
22
|
- Comprehensive error handling
|
|
@@ -50,89 +54,37 @@ The simplest way to configure the gem:
|
|
|
50
54
|
|
|
51
55
|
```ruby
|
|
52
56
|
Tappay.configure do |config|
|
|
53
|
-
|
|
54
|
-
config.mode = Rails.env.production? ? :production : :sandbox
|
|
55
|
-
|
|
56
|
-
# Common settings
|
|
57
|
-
config.partner_key = 'your_partner_key'.freeze
|
|
58
|
-
config.app_id = 'your_app_id'.freeze
|
|
57
|
+
config.partner_key = 'YOUR_PARTNER_KEY'
|
|
59
58
|
|
|
60
|
-
#
|
|
61
|
-
|
|
59
|
+
# Primary merchant identification
|
|
60
|
+
# You can use either merchant_id or merchant_group_id
|
|
61
|
+
config.merchant_id = 'YOUR_MERCHANT_ID'
|
|
62
62
|
# OR
|
|
63
|
-
config.merchant_group_id = '
|
|
63
|
+
config.merchant_group_id = 'YOUR_MERCHANT_GROUP_ID'
|
|
64
64
|
|
|
65
|
-
#
|
|
66
|
-
|
|
67
|
-
config.
|
|
68
|
-
config.
|
|
65
|
+
# Optional merchant IDs for specific payment methods
|
|
66
|
+
# Note: These will be ignored if merchant_group_id is set
|
|
67
|
+
config.jko_pay_merchant_id = 'YOUR_JKO_PAY_MERCHANT_ID'
|
|
68
|
+
config.line_pay_merchant_id = 'YOUR_LINE_PAY_MERCHANT_ID'
|
|
69
|
+
config.instalment_merchant_id = 'YOUR_INSTALMENT_MERCHANT_ID'
|
|
69
70
|
|
|
70
|
-
config.
|
|
71
|
-
config.vat_number = 'your_vat_number'.freeze
|
|
71
|
+
config.mode = :sandbox # or :production
|
|
72
72
|
end
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
### Merchant ID
|
|
76
|
-
|
|
77
|
-
The gem supports flexible merchant ID configuration:
|
|
75
|
+
### Merchant ID Resolution
|
|
78
76
|
|
|
79
|
-
|
|
80
|
-
- `merchant_id`: Default merchant ID for all payments
|
|
81
|
-
- `merchant_group_id`: Group merchant ID (mutually exclusive with merchant_id)
|
|
77
|
+
The gem uses the following priority order when resolving merchant IDs:
|
|
82
78
|
|
|
83
|
-
|
|
84
|
-
- `
|
|
85
|
-
-
|
|
86
|
-
- `jko_pay_merchant_id`: Specific merchant ID for JKO Pay transactions
|
|
87
|
-
|
|
88
|
-
Merchant ID Priority:
|
|
89
|
-
1. Payment options merchant ID (if provided in the payment call)
|
|
90
|
-
2. Payment-specific merchant ID (if configured)
|
|
91
|
-
3. Global merchant ID
|
|
92
|
-
|
|
93
|
-
Example of merchant ID usage:
|
|
94
|
-
```ruby
|
|
95
|
-
# Using default merchant ID
|
|
96
|
-
result = Tappay::CreditCard::Pay.by_prime(
|
|
97
|
-
prime: 'prime_from_tappay_sdk',
|
|
98
|
-
amount: 100,
|
|
99
|
-
order_number: 'ORDER-123'
|
|
100
|
-
)
|
|
79
|
+
1. If `merchant_group_id` is set (either in configuration or options):
|
|
80
|
+
- Uses `merchant_group_id` for all payment types
|
|
81
|
+
- Ignores all other merchant IDs (including specific ones for Line Pay, JKO Pay, etc.)
|
|
101
82
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
frontend_redirect_url: 'https://example.com/line_pay/result',
|
|
108
|
-
backend_notify_url: 'https://example.com/line_pay/notify'
|
|
109
|
-
).execute
|
|
110
|
-
|
|
111
|
-
# Overriding merchant ID in payment options
|
|
112
|
-
result = Tappay::CreditCard::Pay.by_prime(
|
|
113
|
-
prime: 'prime_from_tappay_sdk',
|
|
114
|
-
amount: 100,
|
|
115
|
-
merchant_id: 'override_merchant_id', # This takes highest priority
|
|
116
|
-
order_number: 'ORDER-123'
|
|
117
|
-
)
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
### 2. Using Environment Variables
|
|
121
|
-
|
|
122
|
-
For better security, you can use environment variables:
|
|
123
|
-
|
|
124
|
-
```ruby
|
|
125
|
-
Tappay.configure do |config|
|
|
126
|
-
config.mode = Rails.env.production? ? :production : :sandbox
|
|
127
|
-
config.partner_key = ENV['TAPPAY_PARTNER_KEY'].freeze
|
|
128
|
-
config.app_id = ENV['TAPPAY_APP_ID'].freeze
|
|
129
|
-
config.merchant_id = ENV['TAPPAY_MERCHANT_ID'].freeze
|
|
130
|
-
config.line_pay_merchant_id = ENV['TAPPAY_LINE_PAY_MERCHANT_ID'].freeze
|
|
131
|
-
config.instalment_merchant_id = ENV['TAPPAY_INSTALMENT_MERCHANT_ID'].freeze
|
|
132
|
-
config.jko_pay_merchant_id = ENV['TAPPAY_JKO_PAY_MERCHANT_ID'].freeze
|
|
133
|
-
# ... other configurations
|
|
134
|
-
end
|
|
135
|
-
```
|
|
83
|
+
2. If `merchant_group_id` is not set:
|
|
84
|
+
- For Line Pay: Uses `line_pay_merchant_id` if set, otherwise falls back to `merchant_id`
|
|
85
|
+
- For JKO Pay: Uses `jko_pay_merchant_id` if set, otherwise falls back to `merchant_id`
|
|
86
|
+
- For Instalments: Uses `instalment_merchant_id` if set, otherwise falls back to `merchant_id`
|
|
87
|
+
- For other payment types: Uses `merchant_id`
|
|
136
88
|
|
|
137
89
|
## Usage
|
|
138
90
|
|
|
@@ -186,6 +138,7 @@ result = Tappay::LinePay::Pay.new(
|
|
|
186
138
|
Tappay.configure do |config|
|
|
187
139
|
config.partner_key = 'YOUR_PARTNER_KEY'
|
|
188
140
|
config.merchant_id = 'YOUR_MERCHANT_ID'
|
|
141
|
+
config.merchant_group_id = 'YOUR_MERCHANT_GROUP_ID' # Optional, mutually exclusive with merchant_id
|
|
189
142
|
config.jko_pay_merchant_id = 'YOUR_JKO_PAY_MERCHANT_ID' # Optional, falls back to merchant_id if not set
|
|
190
143
|
config.sandbox = true # Set to false for production
|
|
191
144
|
end
|
data/lib/tappay/configuration.rb
CHANGED
|
@@ -36,7 +36,7 @@ module Tappay
|
|
|
36
36
|
|
|
37
37
|
def validate!
|
|
38
38
|
raise ValidationError, 'partner_key is required' if partner_key.nil?
|
|
39
|
-
raise ValidationError, 'merchant_id is required' if merchant_id.nil?
|
|
39
|
+
raise ValidationError, 'Either merchant_id or merchant_group_id is required' if merchant_id.nil? && merchant_group_id.nil?
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
42
|
end
|
|
@@ -34,6 +34,10 @@ module Tappay
|
|
|
34
34
|
private
|
|
35
35
|
|
|
36
36
|
def get_merchant_id
|
|
37
|
+
# If merchant_group_id is set, it takes precedence
|
|
38
|
+
return nil if Tappay.configuration.merchant_group_id
|
|
39
|
+
|
|
40
|
+
# Otherwise, use instalment_merchant_id or fall back to default merchant_id
|
|
37
41
|
Tappay.configuration.instalment_merchant_id || super
|
|
38
42
|
end
|
|
39
43
|
|
|
@@ -75,6 +79,10 @@ module Tappay
|
|
|
75
79
|
private
|
|
76
80
|
|
|
77
81
|
def get_merchant_id
|
|
82
|
+
# If merchant_group_id is set, it takes precedence
|
|
83
|
+
return nil if Tappay.configuration.merchant_group_id
|
|
84
|
+
|
|
85
|
+
# Otherwise, use instalment_merchant_id or fall back to default merchant_id
|
|
78
86
|
Tappay.configuration.instalment_merchant_id || super
|
|
79
87
|
end
|
|
80
88
|
|
data/lib/tappay/jko_pay/pay.rb
CHANGED
|
@@ -15,6 +15,10 @@ module Tappay
|
|
|
15
15
|
private
|
|
16
16
|
|
|
17
17
|
def get_merchant_id
|
|
18
|
+
# If merchant_group_id is set, it takes precedence
|
|
19
|
+
return nil if Tappay.configuration.merchant_group_id
|
|
20
|
+
|
|
21
|
+
# Otherwise, use jko_pay_merchant_id or fall back to default merchant_id
|
|
18
22
|
Tappay.configuration.jko_pay_merchant_id || super
|
|
19
23
|
end
|
|
20
24
|
|
data/lib/tappay/line_pay/pay.rb
CHANGED
|
@@ -23,6 +23,10 @@ module Tappay
|
|
|
23
23
|
private
|
|
24
24
|
|
|
25
25
|
def get_merchant_id
|
|
26
|
+
# If merchant_group_id is set, it takes precedence
|
|
27
|
+
return nil if Tappay.configuration.merchant_group_id
|
|
28
|
+
|
|
29
|
+
# Otherwise, use line_pay_merchant_id or fall back to default merchant_id
|
|
26
30
|
Tappay.configuration.line_pay_merchant_id || super
|
|
27
31
|
end
|
|
28
32
|
|
data/lib/tappay/payment_base.rb
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module Tappay
|
|
4
4
|
class PaymentBase < Client
|
|
5
|
-
VALID_INSTALMENT_VALUES = [0, 3, 6, 12, 24, 30].freeze
|
|
5
|
+
VALID_INSTALMENT_VALUES = [0, 3, 6, 12, 18, 24, 30].freeze
|
|
6
6
|
|
|
7
7
|
def initialize(options = {})
|
|
8
8
|
super
|
|
@@ -20,48 +20,26 @@ module Tappay
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def payment_data
|
|
23
|
-
#
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
opt_merchant_id = options[:merchant_id]
|
|
31
|
-
|
|
32
|
-
# Check for conflicts in options
|
|
33
|
-
if opt_group_id && opt_merchant_id
|
|
34
|
-
raise Tappay::ValidationError, "merchant_group_id and merchant_id cannot be used together"
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
# If options has any ID, use it exclusively
|
|
38
|
-
if opt_group_id || opt_merchant_id
|
|
39
|
-
merchant_group_id = opt_group_id
|
|
40
|
-
merchant_id = opt_merchant_id
|
|
23
|
+
# Prioritize merchant_group_id from options, then configuration
|
|
24
|
+
merchant_group_id = options[:merchant_group_id] || Tappay.configuration.merchant_group_id
|
|
25
|
+
merchant_id = options[:merchant_id] || get_merchant_id
|
|
26
|
+
|
|
27
|
+
# Determine which identifier to use
|
|
28
|
+
identifier = if merchant_group_id
|
|
29
|
+
{ merchant_group_id: merchant_group_id }
|
|
41
30
|
else
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
merchant_id = get_merchant_id
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# Check if at least one is provided
|
|
48
|
-
unless merchant_group_id || merchant_id
|
|
49
|
-
raise Tappay::ValidationError, "Either merchant_group_id or merchant_id must be provided"
|
|
31
|
+
raise Tappay::ValidationError, "Either merchant_group_id or merchant_id must be provided" unless merchant_id
|
|
32
|
+
{ merchant_id: merchant_id }
|
|
50
33
|
end
|
|
51
34
|
|
|
52
|
-
{
|
|
35
|
+
identifier.merge({
|
|
53
36
|
partner_key: Tappay.configuration.partner_key,
|
|
54
37
|
amount: options[:amount],
|
|
55
38
|
details: options[:details],
|
|
56
39
|
currency: options[:currency] || 'TWD',
|
|
57
40
|
order_number: options[:order_number],
|
|
58
41
|
three_domain_secure: options[:three_domain_secure] || false
|
|
59
|
-
}.tap do |data|
|
|
60
|
-
if merchant_group_id
|
|
61
|
-
data[:merchant_group_id] = merchant_group_id
|
|
62
|
-
else
|
|
63
|
-
data[:merchant_id] = merchant_id
|
|
64
|
-
end
|
|
42
|
+
}).tap do |data|
|
|
65
43
|
data[:cardholder] = card_holder_data if options[:cardholder]
|
|
66
44
|
data[:result_url] = options[:result_url] if options[:result_url]
|
|
67
45
|
data[:instalment] = options[:instalment] || 0
|
|
@@ -103,6 +81,10 @@ module Tappay
|
|
|
103
81
|
end
|
|
104
82
|
|
|
105
83
|
def get_merchant_id
|
|
84
|
+
# If merchant_group_id is set, it takes precedence over all other merchant IDs
|
|
85
|
+
return nil if Tappay.configuration.merchant_group_id
|
|
86
|
+
|
|
87
|
+
# Otherwise, return the default merchant_id
|
|
106
88
|
Tappay.configuration.merchant_id
|
|
107
89
|
end
|
|
108
90
|
|
data/lib/tappay/version.rb
CHANGED