tappay_ruby 0.4.2 → 0.5.1

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: a31a7dd2dae54e34e6cb67c26d2063bb55ee28a313c87164ff362ff0b3cff405
4
- data.tar.gz: 8103f3a1bb11d48a7781a735eeba2afc75bb4a6b1d2d2d590b1bd3dcb211fc63
3
+ metadata.gz: 42349c6d543ca1fa3a3bf6ead0e0f6eb9f281c80b28d35811058d2661d084f10
4
+ data.tar.gz: 82da8ed41bed6cfa50845bf8d9751fb796e8c2373e7978c9e60d35d560c2ccb8
5
5
  SHA512:
6
- metadata.gz: d575276fde2cb8fcb25404efb44b504079075243c9c72293825edb967e0f97a418a65928fc94f69a120ae7c664528038e941ad9332d9b7abcee4d3313fbd85e1
7
- data.tar.gz: 8f3851d3008f156ecf7c63b9ae4d24ff79604271b2d056d662c24bc4183a7c97187cdb5d4540d16e989789af9e3bf226a63756d8d4b0c750326f3a2586f11891
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
@@ -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 = '2'
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
 
@@ -1,3 +1,3 @@
1
1
  module Tappay
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tappay_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zac