tappay_ruby 0.6.0 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1396c7927613825f5182660db63871bc06c114cc38ef334b6143929e7e88f730
4
- data.tar.gz: a6e2fcf2e65a3fa7d47e2a6f7f621d149e189f8be2ec980391e767ecc0000d27
3
+ metadata.gz: ef378bc35a591f5a2c295d7e2c530e174484e200fde3413978081103c4a7a8e3
4
+ data.tar.gz: b15ecfb7ad4c2f13093578a4bfc1a5468ad9b014b04fdc3e561128d6f33cfcbb
5
5
  SHA512:
6
- metadata.gz: 1d9e6b6a5394f54f846562e38053a490145f0c779aca7e61096ec43e3c2ee6055387639790352885b52db8a0918119469897e8b83fcef910965ad7e0d8f5e278
7
- data.tar.gz: ae5f360a2e89ede2df5c0f5d104105aeaefa10c0409b075074a903141d822690328a3e11ee7a55f8fb0256f632d72dac2f76f066b00440dd6cb89351c0c2d8f5
6
+ metadata.gz: 85a20b681bcd1ba1dd830506a3fab64c81652ae61703790f38866cc6d452926272151918914ffaca2d5f01b5dcdcf94cd251dfc707c77b7fa2926934f8622f8b
7
+ data.tar.gz: d72a42f89901fbe206b816d24397a6552326e509cb8c7959f05121091179fe0b50b7b61e075afc70a426e07ed1608e04cb1ae8c67a4c1cc50c3a8e7e3806b43f
@@ -23,7 +23,7 @@ module Tappay
23
23
  end
24
24
 
25
25
  def endpoint_url
26
- Tappay::Endpoints::CreditCard.payment_by_prime_url
26
+ Tappay::Endpoints::Payment.pay_by_prime_url
27
27
  end
28
28
 
29
29
  def validate_options!
@@ -60,7 +60,7 @@ module Tappay
60
60
  end
61
61
 
62
62
  def endpoint_url
63
- Tappay::Endpoints::CreditCard.payment_by_token_url
63
+ Tappay::Endpoints::Payment.pay_by_token_url
64
64
  end
65
65
 
66
66
  def validate_options!
@@ -1,117 +1,9 @@
1
- module Tappay
2
- module CreditCard
3
- class PaymentBase < Client
4
- def initialize(options = {})
5
- super
6
- validate_options!
7
- end
8
-
9
- def execute
10
- post(endpoint_url, payment_data)
11
- end
1
+ # frozen_string_literal: true
12
2
 
13
- protected
14
-
15
- def endpoint_url
16
- raise NotImplementedError, "Subclass must implement abstract method 'endpoint_url'"
17
- end
18
-
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
-
49
- {
50
- partner_key: Tappay.configuration.partner_key,
51
- amount: options[:amount],
52
- details: options[:details],
53
- currency: options[:currency] || 'TWD',
54
- order_number: options[:order_number],
55
- three_domain_secure: options[:three_domain_secure] || false
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
62
- data[:cardholder] = card_holder_data if options[:cardholder]
63
- data[:instalment] = options[:instalment] if options[:instalment]
64
- data[:result_url] = options[:result_url] if options[:result_url]
65
- end
66
- end
67
-
68
- def card_holder_data
69
- return nil unless options[:cardholder]
70
-
71
- case options[:cardholder]
72
- when CardHolder
73
- options[:cardholder].to_h
74
- when Hash
75
- options[:cardholder]
76
- else
77
- raise ValidationError, "Invalid cardholder format"
78
- end
79
- end
80
-
81
- def validate_options!
82
- required = base_required_options + additional_required_options
83
- missing = required.select { |key| options[key].nil? }
84
- raise ValidationError, "Missing required options: #{missing.join(', ')}" if missing.any?
85
-
86
- validate_instalment! if options[:instalment]
87
- validate_result_url! if options[:three_domain_secure]
88
- end
89
-
90
- private
91
-
92
- def base_required_options
93
- [:amount, :details]
94
- end
95
-
96
- def additional_required_options
97
- []
98
- end
99
-
100
- def validate_instalment!
101
- unless options[:instalment].to_i.between?(1, 12)
102
- raise ValidationError, "Invalid instalment value. Must be between 1 and 12"
103
- end
104
- end
105
-
106
- def validate_result_url!
107
- return if options[:result_url] &&
108
- options[:result_url][:frontend_redirect_url] &&
109
- options[:result_url][:backend_notify_url]
110
-
111
- raise ValidationError, "result_url with frontend_redirect_url and backend_notify_url is required when three_domain_secure is true"
112
- end
113
- end
3
+ require 'tappay/payment_base'
114
4
 
5
+ module Tappay
6
+ module CreditCard
115
7
  class Pay < PaymentBase
116
8
  def self.by_prime(options = {})
117
9
  PayByPrime.new(options)
@@ -131,7 +23,7 @@ module Tappay
131
23
  end
132
24
 
133
25
  def endpoint_url
134
- Tappay::Endpoints::CreditCard.payment_by_prime_url
26
+ Tappay::Endpoints::Payment.pay_by_prime_url
135
27
  end
136
28
 
137
29
  private
@@ -150,7 +42,7 @@ module Tappay
150
42
  end
151
43
 
152
44
  def endpoint_url
153
- Tappay::Endpoints::CreditCard.payment_by_token_url
45
+ Tappay::Endpoints::Payment.pay_by_token_url
154
46
  end
155
47
 
156
48
  private
@@ -12,16 +12,20 @@ module Tappay
12
12
  end
13
13
  end
14
14
 
15
- module CreditCard
15
+ module Payment
16
16
  class << self
17
- def payment_by_prime_url
17
+ def pay_by_prime_url
18
18
  "#{Endpoints.base_url}/tpc/payment/pay-by-prime"
19
19
  end
20
20
 
21
- def payment_by_token_url
21
+ def pay_by_token_url
22
22
  "#{Endpoints.base_url}/tpc/payment/pay-by-token"
23
23
  end
24
+ end
25
+ end
24
26
 
27
+ module CreditCard
28
+ class << self
25
29
  def refund_url
26
30
  "#{Endpoints.base_url}/tpc/transaction/refund"
27
31
  end
@@ -55,5 +59,17 @@ module Tappay
55
59
  end
56
60
  end
57
61
  end
62
+
63
+ module LinePay
64
+ class << self
65
+ def redirect_url
66
+ "#{Endpoints.base_url}/tpc/payment/redirect"
67
+ end
68
+
69
+ def query_url
70
+ "#{Endpoints.base_url}/tpc/transaction/query"
71
+ end
72
+ end
73
+ end
58
74
  end
59
75
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tappay/payment_base'
4
+
5
+ module Tappay
6
+ module LinePay
7
+ class Pay < PaymentBase
8
+ def payment_data
9
+ super.merge(
10
+ prime: options[:prime],
11
+ result_url: {
12
+ frontend_redirect_url: options[:frontend_redirect_url],
13
+ backend_notify_url: options[:backend_notify_url]
14
+ },
15
+ remember: options[:remember] || false
16
+ )
17
+ end
18
+
19
+ def endpoint_url
20
+ Tappay::Endpoints::Payment.pay_by_prime_url
21
+ end
22
+
23
+ private
24
+
25
+ def additional_required_options
26
+ [:prime, :frontend_redirect_url, :backend_notify_url]
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tappay
4
+ class PaymentBase < Client
5
+ def initialize(options = {})
6
+ super
7
+ validate_options!
8
+ end
9
+
10
+ def execute
11
+ post(endpoint_url, payment_data)
12
+ end
13
+
14
+ protected
15
+
16
+ def endpoint_url
17
+ raise NotImplementedError, "Subclass must implement abstract method 'endpoint_url'"
18
+ end
19
+
20
+ def payment_data
21
+ # Check configuration conflicts first
22
+ if Tappay.configuration.merchant_group_id && Tappay.configuration.merchant_id
23
+ raise Tappay::ValidationError, "merchant_group_id and merchant_id cannot be used together"
24
+ end
25
+
26
+ # Get values from options
27
+ opt_group_id = options[:merchant_group_id]
28
+ opt_merchant_id = options[:merchant_id]
29
+
30
+ # Check for conflicts in options
31
+ if opt_group_id && opt_merchant_id
32
+ raise Tappay::ValidationError, "merchant_group_id and merchant_id cannot be used together"
33
+ end
34
+
35
+ # If options has any ID, use it exclusively
36
+ if opt_group_id || opt_merchant_id
37
+ merchant_group_id = opt_group_id
38
+ merchant_id = opt_merchant_id
39
+ else
40
+ # If no options, use configuration
41
+ merchant_group_id = Tappay.configuration.merchant_group_id
42
+ merchant_id = Tappay.configuration.merchant_id
43
+ end
44
+
45
+ # Check if at least one is provided
46
+ unless merchant_group_id || merchant_id
47
+ raise Tappay::ValidationError, "Either merchant_group_id or merchant_id must be provided"
48
+ end
49
+
50
+ {
51
+ partner_key: Tappay.configuration.partner_key,
52
+ amount: options[:amount],
53
+ details: options[:details],
54
+ currency: options[:currency] || 'TWD',
55
+ order_number: options[:order_number],
56
+ three_domain_secure: options[:three_domain_secure] || false
57
+ }.tap do |data|
58
+ if merchant_group_id
59
+ data[:merchant_group_id] = merchant_group_id
60
+ else
61
+ data[:merchant_id] = merchant_id
62
+ end
63
+ data[:cardholder] = card_holder_data if options[:cardholder]
64
+ data[:instalment] = options[:instalment] if options[:instalment]
65
+ data[:result_url] = options[:result_url] if options[:result_url]
66
+ end
67
+ end
68
+
69
+ def card_holder_data
70
+ return nil unless options[:cardholder]
71
+
72
+ case options[:cardholder]
73
+ when CardHolder
74
+ options[:cardholder].to_h
75
+ when Hash
76
+ options[:cardholder]
77
+ else
78
+ raise ValidationError, "Invalid cardholder format"
79
+ end
80
+ end
81
+
82
+ def validate_options!
83
+ required = base_required_options + additional_required_options
84
+ missing = required.select { |key| options[key].nil? }
85
+ raise ValidationError, "Missing required options: #{missing.join(', ')}" if missing.any?
86
+
87
+ validate_instalment! if options[:instalment]
88
+ validate_result_url! if options[:three_domain_secure]
89
+ end
90
+
91
+ private
92
+
93
+ def base_required_options
94
+ [:amount, :details]
95
+ end
96
+
97
+ def additional_required_options
98
+ []
99
+ end
100
+
101
+ def validate_instalment!
102
+ unless options[:instalment].to_i.between?(1, 12)
103
+ raise ValidationError, "Invalid instalment value. Must be between 1 and 12"
104
+ end
105
+ end
106
+
107
+ def validate_result_url!
108
+ return if options[:result_url] &&
109
+ options[:result_url][:frontend_redirect_url] &&
110
+ options[:result_url][:backend_notify_url]
111
+
112
+ raise ValidationError, "result_url with frontend_redirect_url and backend_notify_url is required when three_domain_secure is true"
113
+ end
114
+ end
115
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Tappay
2
- VERSION = "0.6.0"
4
+ VERSION = "0.7.0"
3
5
  end
data/lib/tappay.rb CHANGED
@@ -10,6 +10,7 @@ require_relative "tappay/transaction/query"
10
10
  require_relative "tappay/credit_card/pay"
11
11
  require_relative "tappay/credit_card/refund"
12
12
  require_relative "tappay/credit_card/instalment"
13
+ require_relative "tappay/line_pay/pay"
13
14
 
14
15
  module Tappay
15
16
  class Error < StandardError; end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tappay_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zac
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2024-12-30 00:00:00.000000000 Z
10
+ date: 2025-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: httparty
@@ -83,6 +83,8 @@ files:
83
83
  - lib/tappay/credit_card/refund.rb
84
84
  - lib/tappay/endpoints.rb
85
85
  - lib/tappay/errors.rb
86
+ - lib/tappay/line_pay/pay.rb
87
+ - lib/tappay/payment_base.rb
86
88
  - lib/tappay/transaction/query.rb
87
89
  - lib/tappay/version.rb
88
90
  - lib/tappay_ruby.rb