tappay_ruby 0.4.2 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +69 -0
- data/lib/tappay/configuration.rb +2 -2
- data/lib/tappay/credit_card/pay.rb +34 -2
- 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: 42349c6d543ca1fa3a3bf6ead0e0f6eb9f281c80b28d35811058d2661d084f10
|
4
|
+
data.tar.gz: 82da8ed41bed6cfa50845bf8d9751fb796e8c2373e7978c9e60d35d560c2ccb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfd22c013a32a3aa5c13bc28c84d94e21f49cdaf71657b6f7cf39e2c0240cff23fe61db6b396ccbb02cdf0571802318689b022bc796e4253ea799bc3837c1898
|
7
|
+
data.tar.gz: 4878db49a06c88e21fc6a5affa06eed404bf2a90feaaa82921824ad27a280977caafe05d945765a43ca21cba41dba78bf52d6bd7cbdf8d59706a62207accacc3
|
data/README.md
CHANGED
@@ -52,13 +52,40 @@ Tappay.configure do |config|
|
|
52
52
|
# Common settings
|
53
53
|
config.partner_key = 'your_partner_key'.freeze
|
54
54
|
config.app_id = 'your_app_id'.freeze
|
55
|
+
|
56
|
+
# Merchant settings (use either merchant_id or merchant_group_id, not both)
|
55
57
|
config.merchant_id = 'your_merchant_id'.freeze
|
58
|
+
# OR
|
59
|
+
config.merchant_group_id = 'your_merchant_group_id'.freeze
|
60
|
+
|
56
61
|
config.instalment_merchant_id = 'your_instalment_merchant_id'.freeze
|
57
62
|
config.currency = 'TWD'.freeze
|
58
63
|
config.vat_number = 'your_vat_number'.freeze
|
59
64
|
end
|
60
65
|
```
|
61
66
|
|
67
|
+
### Merchant ID Configuration
|
68
|
+
|
69
|
+
The gem supports two types of merchant identification:
|
70
|
+
1. `merchant_id`: Individual merchant ID
|
71
|
+
2. `merchant_group_id`: Group merchant ID
|
72
|
+
|
73
|
+
Important rules:
|
74
|
+
- You can set either `merchant_id` or `merchant_group_id` in the configuration, but not both
|
75
|
+
- When making a payment, you can override the configured merchant ID by providing either `merchant_id` or `merchant_group_id` in the payment options
|
76
|
+
- If you provide merchant ID in the payment options, it will take precedence over any configuration
|
77
|
+
|
78
|
+
Example of overriding merchant ID in payment:
|
79
|
+
```ruby
|
80
|
+
# Using merchant_group_id in payment options
|
81
|
+
result = Tappay::CreditCard::Pay.by_prime(
|
82
|
+
prime: 'prime_from_tappay_sdk',
|
83
|
+
amount: 100,
|
84
|
+
merchant_group_id: 'group_123', # This will be used instead of configured merchant_id
|
85
|
+
order_number: 'ORDER-123'
|
86
|
+
)
|
87
|
+
```
|
88
|
+
|
62
89
|
### 2. Using Environment Variables
|
63
90
|
|
64
91
|
For better security, you can use environment variables:
|
@@ -138,6 +165,38 @@ result = Tappay::CreditCard::Pay.by_prime(
|
|
138
165
|
|
139
166
|
Both approaches are valid and will work the same way. The CardHolder object provides a more structured way to handle cardholder information and includes validation.
|
140
167
|
|
168
|
+
## Payment URL
|
169
|
+
|
170
|
+
When processing payments, the API response may include a `payment_url` field. This URL is used for redirecting users to complete their payment in scenarios such as:
|
171
|
+
|
172
|
+
- 3D Secure verification
|
173
|
+
- LINE Pay payment page
|
174
|
+
- JKO Pay payment page
|
175
|
+
|
176
|
+
Note: payment_url is not supported for:
|
177
|
+
- Apple Pay
|
178
|
+
- Google Pay
|
179
|
+
- Samsung Pay
|
180
|
+
|
181
|
+
Example of handling payment URL in response:
|
182
|
+
```ruby
|
183
|
+
result = Tappay::CreditCard::Pay.by_prime(
|
184
|
+
prime: 'prime_from_tappay_sdk',
|
185
|
+
amount: 100,
|
186
|
+
order_number: 'ORDER-123'
|
187
|
+
)
|
188
|
+
|
189
|
+
if result['status'] == 0
|
190
|
+
if result['payment_url']
|
191
|
+
# Redirect user to payment page for:
|
192
|
+
# - 3D Secure verification
|
193
|
+
# - LINE Pay payment
|
194
|
+
# - JKO Pay payment
|
195
|
+
redirect_to result['payment_url']
|
196
|
+
end
|
197
|
+
end
|
198
|
+
```
|
199
|
+
|
141
200
|
## Usage
|
142
201
|
|
143
202
|
### Pay by Prime
|
@@ -165,6 +224,11 @@ if result['status'] == 0
|
|
165
224
|
card_token = result['card_secret']['card_token']
|
166
225
|
# Store card_key and card_token securely for future payments
|
167
226
|
end
|
227
|
+
|
228
|
+
# Handle payment URL if present (for 3D Secure, LINE Pay, JKO Pay)
|
229
|
+
if result['payment_url']
|
230
|
+
redirect_to result['payment_url']
|
231
|
+
end
|
168
232
|
end
|
169
233
|
```
|
170
234
|
|
@@ -213,6 +277,11 @@ begin
|
|
213
277
|
number_of_instalments = instalment_info['number_of_instalments']
|
214
278
|
first_payment = instalment_info['first_payment']
|
215
279
|
each_payment = instalment_info['each_payment']
|
280
|
+
|
281
|
+
# Handle payment URL if present (for 3D Secure)
|
282
|
+
if result['payment_url']
|
283
|
+
redirect_to result['payment_url']
|
284
|
+
end
|
216
285
|
end
|
217
286
|
rescue Tappay::PaymentError => e
|
218
287
|
# Handle payment error
|
data/lib/tappay/configuration.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Tappay
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :partner_key, :merchant_id, :instalment_merchant_id, :app_id, :currency, :vat_number
|
3
|
+
attr_accessor :partner_key, :merchant_id, :merchant_group_id, :instalment_merchant_id, :app_id, :currency, :vat_number
|
4
4
|
attr_writer :api_version
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
@mode = :sandbox
|
8
|
-
@api_version = '
|
8
|
+
@api_version = '3'
|
9
9
|
end
|
10
10
|
|
11
11
|
def api_version
|
@@ -17,18 +17,50 @@ module Tappay
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def payment_data
|
20
|
+
# Check configuration conflicts first
|
21
|
+
if Tappay.configuration.merchant_group_id && Tappay.configuration.merchant_id
|
22
|
+
raise Tappay::ValidationError, "merchant_group_id and merchant_id cannot be used together"
|
23
|
+
end
|
24
|
+
|
25
|
+
# Get values from options
|
26
|
+
opt_group_id = options[:merchant_group_id]
|
27
|
+
opt_merchant_id = options[:merchant_id]
|
28
|
+
|
29
|
+
# Check for conflicts in options
|
30
|
+
if opt_group_id && opt_merchant_id
|
31
|
+
raise Tappay::ValidationError, "merchant_group_id and merchant_id cannot be used together"
|
32
|
+
end
|
33
|
+
|
34
|
+
# If options has any ID, use it exclusively
|
35
|
+
if opt_group_id || opt_merchant_id
|
36
|
+
merchant_group_id = opt_group_id
|
37
|
+
merchant_id = opt_merchant_id
|
38
|
+
else
|
39
|
+
# If no options, use configuration
|
40
|
+
merchant_group_id = Tappay.configuration.merchant_group_id
|
41
|
+
merchant_id = Tappay.configuration.merchant_id
|
42
|
+
end
|
43
|
+
|
44
|
+
# Check if at least one is provided
|
45
|
+
unless merchant_group_id || merchant_id
|
46
|
+
raise Tappay::ValidationError, "Either merchant_group_id or merchant_id must be provided"
|
47
|
+
end
|
48
|
+
|
20
49
|
{
|
21
50
|
partner_key: Tappay.configuration.partner_key,
|
22
|
-
merchant_id: options[:merchant_id] || Tappay.configuration.merchant_id,
|
23
51
|
amount: options[:amount],
|
24
52
|
details: options[:details],
|
25
53
|
currency: options[:currency] || 'TWD',
|
26
54
|
order_number: options[:order_number],
|
27
55
|
three_domain_secure: options[:three_domain_secure] || false
|
28
56
|
}.tap do |data|
|
57
|
+
if merchant_group_id
|
58
|
+
data[:merchant_group_id] = merchant_group_id
|
59
|
+
else
|
60
|
+
data[:merchant_id] = merchant_id
|
61
|
+
end
|
29
62
|
data[:cardholder] = card_holder_data if options[:cardholder]
|
30
63
|
data[:instalment] = options[:instalment] if options[:instalment]
|
31
|
-
data[:payment_url] = options[:payment_url] if options[:payment_url]
|
32
64
|
end
|
33
65
|
end
|
34
66
|
|
data/lib/tappay/version.rb
CHANGED