tappay_ruby 0.21.0 → 1.1.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 +36 -0
- data/lib/tappay/client.rb +42 -14
- data/lib/tappay/configuration.rb +2 -1
- data/lib/tappay/ipass_money/pay.rb +64 -0
- data/lib/tappay/version.rb +1 -1
- data/lib/tappay.rb +1 -0
- metadata +5 -18
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9cbe85ab3afecf239323a807b1a2d55311d1bcb3ad471a85681170eb52770a06
|
|
4
|
+
data.tar.gz: f9d027824f0691aeb7487febc2155d7e31d5a487d2fe3562b79bdb009ca401c9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d98f0e74412ca52ecc67c9f9cf6a24a574f5d4f409aa0c4dda9f9e6ab073d3c775aeafda4cf49140e702e0e6c1e43add2843cda020a5190b40a504e6a5ec82ae
|
|
7
|
+
data.tar.gz: 3b13ec89b5d01fa9b92fe0c5586c89d17462aedeced858178333200c0417070cfe7285f9011da8b3dd2f3b366ac67c3fd45c6a5cb69494dc64325ed4e0aacdea
|
data/README.md
CHANGED
|
@@ -14,6 +14,7 @@ A Ruby library for integrating with TapPay payment services. This gem provides a
|
|
|
14
14
|
- Line Pay
|
|
15
15
|
- JKO Pay
|
|
16
16
|
- Apple Pay
|
|
17
|
+
- iPass Money
|
|
17
18
|
- Flexible merchant identification:
|
|
18
19
|
- Support for both `merchant_id` and `merchant_group_id`
|
|
19
20
|
- Automatic fallback handling
|
|
@@ -83,6 +84,7 @@ The gem uses the following priority order when resolving merchant IDs:
|
|
|
83
84
|
2. If `merchant_group_id` is not set:
|
|
84
85
|
- For Line Pay: Uses `line_pay_merchant_id` if set, otherwise falls back to `merchant_id`
|
|
85
86
|
- For JKO Pay: Uses `jko_pay_merchant_id` if set, otherwise falls back to `merchant_id`
|
|
87
|
+
- For iPass Money: Uses `ipass_money_merchant_id` if set, otherwise falls back to `merchant_id`
|
|
86
88
|
- For Instalments: Uses `instalment_merchant_id` if set, otherwise falls back to `merchant_id`
|
|
87
89
|
- For other payment types: Uses `merchant_id`
|
|
88
90
|
|
|
@@ -206,6 +208,40 @@ payment = Tappay::JkoPay::Pay.new(payment_options)
|
|
|
206
208
|
result = payment.execute
|
|
207
209
|
```
|
|
208
210
|
|
|
211
|
+
### iPass Money
|
|
212
|
+
|
|
213
|
+
#### Configuration
|
|
214
|
+
|
|
215
|
+
```ruby
|
|
216
|
+
Tappay.configure do |config|
|
|
217
|
+
config.partner_key = 'YOUR_PARTNER_KEY'
|
|
218
|
+
config.merchant_id = 'YOUR_MERCHANT_ID'
|
|
219
|
+
config.merchant_group_id = 'YOUR_MERCHANT_GROUP_ID' # Optional, mutually exclusive with merchant_id
|
|
220
|
+
config.ipass_money_merchant_id = 'YOUR_IPASS_MONEY_MERCHANT_ID' # Optional, falls back to merchant_id if not set
|
|
221
|
+
config.sandbox = true # Set to false for production
|
|
222
|
+
end
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
#### Processing an iPass Money Payment
|
|
226
|
+
|
|
227
|
+
```ruby
|
|
228
|
+
payment_options = {
|
|
229
|
+
prime: 'ipass_money_prime',
|
|
230
|
+
amount: 1000,
|
|
231
|
+
details: 'Some item',
|
|
232
|
+
frontend_redirect_url: 'https://your-site.com/ipass_money/result',
|
|
233
|
+
backend_notify_url: 'https://your-site.com/ipass_money/notify',
|
|
234
|
+
cardholder: {
|
|
235
|
+
phone_number: '0912345678',
|
|
236
|
+
name: 'Test User',
|
|
237
|
+
email: 'test@example.com'
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
payment = Tappay::IPassMoney::Pay.new(payment_options)
|
|
242
|
+
result = payment.execute
|
|
243
|
+
```
|
|
244
|
+
|
|
209
245
|
### Transaction Query
|
|
210
246
|
|
|
211
247
|
Query transaction records with required time range:
|
data/lib/tappay/client.rb
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'uri'
|
|
2
3
|
require 'json'
|
|
3
4
|
|
|
4
5
|
module Tappay
|
|
5
6
|
class Client
|
|
6
|
-
include HTTParty
|
|
7
|
-
|
|
8
7
|
attr_reader :options
|
|
9
8
|
|
|
10
9
|
def initialize(options = {})
|
|
@@ -13,16 +12,19 @@ module Tappay
|
|
|
13
12
|
end
|
|
14
13
|
|
|
15
14
|
def post(url, data)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
uri = URI.parse(url)
|
|
16
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
17
|
+
http.use_ssl = (uri.scheme == 'https')
|
|
18
|
+
http.open_timeout = timeout
|
|
19
|
+
http.read_timeout = timeout
|
|
20
|
+
|
|
21
|
+
request = Net::HTTP::Post.new(uri.request_uri, headers)
|
|
22
|
+
request.body = data.to_json
|
|
22
23
|
|
|
24
|
+
@response = http.request(request)
|
|
23
25
|
validate_response
|
|
24
|
-
@response
|
|
25
|
-
rescue
|
|
26
|
+
Response.new(@response)
|
|
27
|
+
rescue Timeout::Error, Net::OpenTimeout, Net::ReadTimeout => e
|
|
26
28
|
raise ConnectionError, "HTTP Request failed: #{e.message}"
|
|
27
29
|
end
|
|
28
30
|
|
|
@@ -40,7 +42,8 @@ module Tappay
|
|
|
40
42
|
end
|
|
41
43
|
|
|
42
44
|
def validate_response
|
|
43
|
-
|
|
45
|
+
code = @response.code.to_i
|
|
46
|
+
case code
|
|
44
47
|
when 200
|
|
45
48
|
true
|
|
46
49
|
when 400
|
|
@@ -48,10 +51,35 @@ module Tappay
|
|
|
48
51
|
when 401
|
|
49
52
|
raise ConfigurationError, "Authentication failed. Check your partner_key."
|
|
50
53
|
when 404
|
|
51
|
-
raise ConnectionError, "API endpoint not found
|
|
54
|
+
raise ConnectionError, "API endpoint not found"
|
|
52
55
|
else
|
|
53
|
-
raise ConnectionError, "HTTP Request failed with code #{
|
|
56
|
+
raise ConnectionError, "HTTP Request failed with code #{code}: #{@response.body}"
|
|
54
57
|
end
|
|
55
58
|
end
|
|
56
59
|
end
|
|
60
|
+
|
|
61
|
+
class Response
|
|
62
|
+
attr_reader :code, :body, :headers
|
|
63
|
+
|
|
64
|
+
def initialize(net_http_response)
|
|
65
|
+
@response = net_http_response
|
|
66
|
+
@code = net_http_response.code.to_i
|
|
67
|
+
@body = net_http_response.body
|
|
68
|
+
@headers = net_http_response.to_hash
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def parsed_response
|
|
72
|
+
@parsed_response ||= JSON.parse(@body)
|
|
73
|
+
rescue JSON::ParserError
|
|
74
|
+
@body
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def success?
|
|
78
|
+
@code >= 200 && @code < 300
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def [](key)
|
|
82
|
+
parsed_response[key]
|
|
83
|
+
end
|
|
84
|
+
end
|
|
57
85
|
end
|
data/lib/tappay/configuration.rb
CHANGED
|
@@ -4,7 +4,8 @@ module Tappay
|
|
|
4
4
|
class Configuration
|
|
5
5
|
attr_accessor :partner_key, :merchant_id, :merchant_group_id, :instalment_merchant_id,
|
|
6
6
|
:line_pay_merchant_id, :jko_pay_merchant_id, :currency,
|
|
7
|
-
:google_pay_merchant_id, :apple_pay_merchant_id
|
|
7
|
+
:google_pay_merchant_id, :apple_pay_merchant_id,
|
|
8
|
+
:ipass_money_merchant_id
|
|
8
9
|
attr_writer :api_version
|
|
9
10
|
|
|
10
11
|
def initialize
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Tappay
|
|
4
|
+
module IPassMoney
|
|
5
|
+
class Pay < PaymentBase
|
|
6
|
+
def endpoint_url
|
|
7
|
+
Tappay::Endpoints::Payment.pay_by_prime_url
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
private
|
|
11
|
+
|
|
12
|
+
def get_merchant_id
|
|
13
|
+
# If merchant_group_id is set, it takes precedence
|
|
14
|
+
return nil if Tappay.configuration.merchant_group_id
|
|
15
|
+
|
|
16
|
+
# Otherwise, use ipass_money_merchant_id or fall back to default merchant_id
|
|
17
|
+
Tappay.configuration.ipass_money_merchant_id || super
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def additional_required_options
|
|
21
|
+
[:prime, :frontend_redirect_url, :backend_notify_url, :cardholder]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def validate_options!
|
|
25
|
+
super
|
|
26
|
+
validate_result_url_format!
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def validate_result_url_format!
|
|
30
|
+
# First validate that if result_url is provided, it's a hash with required fields
|
|
31
|
+
if options.key?(:result_url)
|
|
32
|
+
raise ValidationError, "result_url must be a hash" unless options[:result_url].is_a?(Hash)
|
|
33
|
+
|
|
34
|
+
result_url = options[:result_url]
|
|
35
|
+
required_fields = %w[frontend_redirect_url backend_notify_url]
|
|
36
|
+
missing = required_fields.select { |field| result_url[field.to_sym].nil? && result_url[field].nil? }
|
|
37
|
+
|
|
38
|
+
if missing.any?
|
|
39
|
+
raise ValidationError, "result_url must contain both frontend_redirect_url and backend_notify_url"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Then validate frontend_redirect_url and backend_notify_url are present and not empty
|
|
44
|
+
if !options[:frontend_redirect_url].to_s.strip.empty? && !options[:backend_notify_url].to_s.strip.empty?
|
|
45
|
+
return
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
raise ValidationError, "result_url must contain both frontend_redirect_url and backend_notify_url"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
protected
|
|
52
|
+
|
|
53
|
+
def payment_data
|
|
54
|
+
super.merge(
|
|
55
|
+
prime: options[:prime],
|
|
56
|
+
result_url: {
|
|
57
|
+
frontend_redirect_url: options[:frontend_redirect_url],
|
|
58
|
+
backend_notify_url: options[:backend_notify_url]
|
|
59
|
+
}
|
|
60
|
+
)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
data/lib/tappay/version.rb
CHANGED
data/lib/tappay.rb
CHANGED
|
@@ -20,6 +20,7 @@ require_relative "tappay/line_pay/pay"
|
|
|
20
20
|
require_relative "tappay/jko_pay/pay"
|
|
21
21
|
require_relative "tappay/apple_pay/pay"
|
|
22
22
|
require_relative "tappay/google_pay/pay"
|
|
23
|
+
require_relative "tappay/ipass_money/pay"
|
|
23
24
|
|
|
24
25
|
module Tappay
|
|
25
26
|
class Error < StandardError; 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:
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Zac
|
|
@@ -9,20 +9,6 @@ bindir: exe
|
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
|
-
- !ruby/object:Gem::Dependency
|
|
13
|
-
name: httparty
|
|
14
|
-
requirement: !ruby/object:Gem::Requirement
|
|
15
|
-
requirements:
|
|
16
|
-
- - "~>"
|
|
17
|
-
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.21.0
|
|
19
|
-
type: :runtime
|
|
20
|
-
prerelease: false
|
|
21
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
-
requirements:
|
|
23
|
-
- - "~>"
|
|
24
|
-
- !ruby/object:Gem::Version
|
|
25
|
-
version: 0.21.0
|
|
26
12
|
- !ruby/object:Gem::Dependency
|
|
27
13
|
name: rake
|
|
28
14
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -71,14 +57,14 @@ dependencies:
|
|
|
71
57
|
requirements:
|
|
72
58
|
- - "~>"
|
|
73
59
|
- !ruby/object:Gem::Version
|
|
74
|
-
version: '
|
|
60
|
+
version: '3.1'
|
|
75
61
|
type: :development
|
|
76
62
|
prerelease: false
|
|
77
63
|
version_requirements: !ruby/object:Gem::Requirement
|
|
78
64
|
requirements:
|
|
79
65
|
- - "~>"
|
|
80
66
|
- !ruby/object:Gem::Version
|
|
81
|
-
version: '
|
|
67
|
+
version: '3.1'
|
|
82
68
|
- !ruby/object:Gem::Dependency
|
|
83
69
|
name: webmock
|
|
84
70
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -140,6 +126,7 @@ files:
|
|
|
140
126
|
- lib/tappay/endpoints.rb
|
|
141
127
|
- lib/tappay/errors.rb
|
|
142
128
|
- lib/tappay/google_pay/pay.rb
|
|
129
|
+
- lib/tappay/ipass_money/pay.rb
|
|
143
130
|
- lib/tappay/jko_pay/pay.rb
|
|
144
131
|
- lib/tappay/line_pay/pay.rb
|
|
145
132
|
- lib/tappay/payment_base.rb
|
|
@@ -168,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
168
155
|
- !ruby/object:Gem::Version
|
|
169
156
|
version: '0'
|
|
170
157
|
requirements: []
|
|
171
|
-
rubygems_version:
|
|
158
|
+
rubygems_version: 4.0.6
|
|
172
159
|
specification_version: 4
|
|
173
160
|
summary: Ruby wrapper for TapPay payment gateway
|
|
174
161
|
test_files: []
|