pesepay 0.1.0 → 0.1.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 +4 -4
- data/.github/workflows/main.yml +16 -16
- data/.gitignore +13 -13
- data/.rspec +3 -3
- data/.rubocop.yml +13 -13
- data/CHANGELOG.md +5 -5
- data/CODE_OF_CONDUCT.md +84 -84
- data/Gemfile +14 -14
- data/Gemfile.lock +58 -57
- data/LICENSE.txt +21 -21
- data/README.md +154 -144
- data/Rakefile +12 -12
- data/bin/console +15 -15
- data/bin/setup +8 -8
- data/lib/pesepay/version.rb +5 -5
- data/lib/pesepay.rb +266 -262
- data/pesepay.gemspec +37 -37
- metadata +3 -6
data/lib/pesepay.rb
CHANGED
|
@@ -1,262 +1,266 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "pesepay/version"
|
|
4
|
-
require "cgi"
|
|
5
|
-
require "digest"
|
|
6
|
-
require "uri"
|
|
7
|
-
require "net/http"
|
|
8
|
-
require "openssl"
|
|
9
|
-
require "base64"
|
|
10
|
-
require "json"
|
|
11
|
-
|
|
12
|
-
module Pesepay
|
|
13
|
-
class Pesepay
|
|
14
|
-
attr_accessor :result_url, :return_url
|
|
15
|
-
|
|
16
|
-
def initialize(integration_key, encryption_key)
|
|
17
|
-
@integration_key = integration_key
|
|
18
|
-
@encryption_key = encryption_key
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def create_transaction(amount, currency_code, reason_for_payment, reference)
|
|
22
|
-
Transaction.new(amount, currency_code, reason_for_payment, reference)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def create_seamless_transaction(currency_code, payment_method_code, customer_email = nil, customer_phone = nil, customer_name = nil)
|
|
26
|
-
Payment.new(currency_code, payment_method_code, customer_email, customer_phone, customer_name)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def initiate_transaction(transaction)
|
|
30
|
-
response = create_transaction_request(transaction)
|
|
31
|
-
process_response(response)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def make_seamless_payment(payment, reason_for_payment, amount, payment_method_required_fields, reference = nil)
|
|
35
|
-
response = create_seamless_payment_request(payment, reason_for_payment, amount, payment_method_required_fields, reference)
|
|
36
|
-
process_response(response)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def get_payment_method_code(currency_code)
|
|
40
|
-
response = get_payment_method_code_request(currency_code)
|
|
41
|
-
process_get_code_method(response)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def poll_transaction(poll_url)
|
|
45
|
-
url = URI(poll_url)
|
|
46
|
-
|
|
47
|
-
http = Net::HTTP.new(url.host, url.port)
|
|
48
|
-
http.use_ssl = true
|
|
49
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
50
|
-
|
|
51
|
-
request = Net::HTTP::Get.new(url)
|
|
52
|
-
request["Authorization"] = @integration_key
|
|
53
|
-
request["Content-Type"] = "application/json"
|
|
54
|
-
response = http.request(request)
|
|
55
|
-
|
|
56
|
-
process_poll_response(response)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def check_payment(reference_number)
|
|
60
|
-
url = "https://api.pesepay.com/api/payments-engine/v1/payments/check-payment?
|
|
61
|
-
poll_transaction(url)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
private
|
|
65
|
-
|
|
66
|
-
def create_transaction_request(transaction)
|
|
67
|
-
data = build_transaction_data(transaction)
|
|
68
|
-
|
|
69
|
-
url = URI("https://api.pesepay.com/api/payments-engine/v1/payments/initiate")
|
|
70
|
-
|
|
71
|
-
http = Net::HTTP.new(url.host, url.port)
|
|
72
|
-
http.use_ssl = true
|
|
73
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
74
|
-
|
|
75
|
-
request = Net::HTTP::Post.new(url)
|
|
76
|
-
request["Authorization"] = @integration_key
|
|
77
|
-
request["Content-Type"] = "application/json"
|
|
78
|
-
request.body = { payload: data }.to_json
|
|
79
|
-
http.request(request)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def create_seamless_payment_request(payment, reason_for_payment, amount, payment_method_required_fields, reference)
|
|
83
|
-
data = build_seamless_payment_data(payment, reason_for_payment, amount, payment_method_required_fields, reference)
|
|
84
|
-
|
|
85
|
-
url = URI("https://api.pesepay.com/api/payments-engine/v2/payments/make-payment")
|
|
86
|
-
|
|
87
|
-
http = Net::HTTP.new(url.host, url.port)
|
|
88
|
-
http.use_ssl = true
|
|
89
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
90
|
-
|
|
91
|
-
request = Net::HTTP::Post.new(url)
|
|
92
|
-
request["Authorization"] = @integration_key
|
|
93
|
-
request["Content-Type"] = "application/json"
|
|
94
|
-
request.body = { payload: data }.to_json
|
|
95
|
-
http.request(request)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def get_payment_method_code_request(currency_code)
|
|
99
|
-
url = URI("https://api.pesepay.com/api/payments-engine/v1/payment-methods/for-currency?currencyCode=#{currency_code}")
|
|
100
|
-
|
|
101
|
-
http = Net::HTTP.new(url.host, url.port)
|
|
102
|
-
http.use_ssl = true
|
|
103
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
104
|
-
|
|
105
|
-
request = Net::HTTP::Get.new(url)
|
|
106
|
-
http.request(request)
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def process_get_code_method(response)
|
|
110
|
-
if response.code == "200"
|
|
111
|
-
response_body = JSON.parse(response.body)
|
|
112
|
-
payment_method_code = response_body[0]["code"]
|
|
113
|
-
return payment_method_code
|
|
114
|
-
else
|
|
115
|
-
Response.new(false, message: "Unable to get payment method code")
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def process_response(response)
|
|
120
|
-
if response.code == "200"
|
|
121
|
-
response_body = JSON.parse(response.body.gsub("'", '"'))
|
|
122
|
-
inner_payload = response_body["payload"]
|
|
123
|
-
raw_response = decrypt(inner_payload, @encryption_key)
|
|
124
|
-
json_string = JSON.parse(raw_response)
|
|
125
|
-
ref_no = json_string["
|
|
126
|
-
poll_url = json_string["
|
|
127
|
-
redirect_url = json_string["
|
|
128
|
-
Response.new(true,
|
|
129
|
-
else
|
|
130
|
-
message = JSON.parse(response.body)["message"]
|
|
131
|
-
Response.new(false, message: message)
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
def process_poll_response(response)
|
|
136
|
-
if response.code == "200"
|
|
137
|
-
response_body = JSON.parse(response.body)
|
|
138
|
-
inner_payload = response_body["payload"]
|
|
139
|
-
raw_response = decrypt(inner_payload)
|
|
140
|
-
json_string = JSON.parse(raw_response)
|
|
141
|
-
reference_number = json_string["
|
|
142
|
-
poll_url = json_string["
|
|
143
|
-
paid = json_string["transactionStatus"] == "SUCCESS"
|
|
144
|
-
|
|
145
|
-
StatusResponse.new(reference_number, poll_url, paid)
|
|
146
|
-
else
|
|
147
|
-
message = JSON.parse(response.body)["message"]
|
|
148
|
-
StatusResponse.new(nil, nil, false, message)
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
def build_transaction_data(transaction)
|
|
153
|
-
payload = {
|
|
154
|
-
"amountDetails": {
|
|
155
|
-
"amount": transaction.amount,
|
|
156
|
-
"currencyCode": transaction.currency_code,
|
|
157
|
-
},
|
|
158
|
-
"reasonForPayment": transaction.reason_for_payment,
|
|
159
|
-
"resultUrl": @result_url,
|
|
160
|
-
"returnUrl": @return_url,
|
|
161
|
-
"merchantReference": transaction.reference,
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
encrypted = encrypt(payload.to_json, @encryption_key)
|
|
165
|
-
encrypted
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
def build_seamless_payment_data(payment, reason_for_payment, amount, payment_method_required_fields, reference)
|
|
169
|
-
payload = {
|
|
170
|
-
"amountDetails": {
|
|
171
|
-
"amount": amount,
|
|
172
|
-
"currencyCode": payment.currency_code,
|
|
173
|
-
},
|
|
174
|
-
"merchantReference": reference,
|
|
175
|
-
"reasonForPayment": reason_for_payment,
|
|
176
|
-
"resultUrl": @result_url,
|
|
177
|
-
"returnUrl": @return_url,
|
|
178
|
-
"paymentMethodCode": payment.payment_method_code,
|
|
179
|
-
"customer": {
|
|
180
|
-
"email": payment.customer_email,
|
|
181
|
-
"phoneNumber": payment.customer_phone,
|
|
182
|
-
"name": payment.customer_name,
|
|
183
|
-
},
|
|
184
|
-
"paymentMethodRequiredFields": payment_method_required_fields,
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
encrypted = encrypt(payload.to_json, @encryption_key)
|
|
188
|
-
encrypted
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
def encrypt(payload, key)
|
|
192
|
-
init_vector = key[0, 16]
|
|
193
|
-
cryptor = OpenSSL::Cipher::AES.new(256, :CBC)
|
|
194
|
-
cryptor.encrypt
|
|
195
|
-
cryptor.key = key
|
|
196
|
-
cryptor.iv = init_vector
|
|
197
|
-
ciphertext = cryptor.update(pad(payload)) + cryptor.final
|
|
198
|
-
Base64.strict_encode64(ciphertext)
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
def decrypt(payload, key)
|
|
202
|
-
ciphertext = Base64.strict_decode64(payload)
|
|
203
|
-
init_vector = key[0, 16]
|
|
204
|
-
cryptor = OpenSSL::Cipher::AES.new(256, :CBC)
|
|
205
|
-
cryptor.decrypt
|
|
206
|
-
cryptor.key = key
|
|
207
|
-
cryptor.iv = init_vector
|
|
208
|
-
plaintext = cryptor.update(ciphertext) + cryptor.final
|
|
209
|
-
plaintext
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
def pad(input)
|
|
213
|
-
padding_length = 16 - (input.length % 16)
|
|
214
|
-
input + (padding_length.chr * padding_length)
|
|
215
|
-
end
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
class Response
|
|
219
|
-
attr_reader :success, :
|
|
220
|
-
|
|
221
|
-
def initialize(success,
|
|
222
|
-
@success = success
|
|
223
|
-
@
|
|
224
|
-
@
|
|
225
|
-
@
|
|
226
|
-
@message = message
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
@
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "pesepay/version"
|
|
4
|
+
require "cgi"
|
|
5
|
+
require "digest"
|
|
6
|
+
require "uri"
|
|
7
|
+
require "net/http"
|
|
8
|
+
require "openssl"
|
|
9
|
+
require "base64"
|
|
10
|
+
require "json"
|
|
11
|
+
|
|
12
|
+
module Pesepay
|
|
13
|
+
class Pesepay
|
|
14
|
+
attr_accessor :result_url, :return_url
|
|
15
|
+
|
|
16
|
+
def initialize(integration_key, encryption_key)
|
|
17
|
+
@integration_key = integration_key
|
|
18
|
+
@encryption_key = encryption_key
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def create_transaction(amount, currency_code, reason_for_payment, reference)
|
|
22
|
+
Transaction.new(amount, currency_code, reason_for_payment, reference)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def create_seamless_transaction(currency_code, payment_method_code, customer_email = nil, customer_phone = nil, customer_name = nil)
|
|
26
|
+
Payment.new(currency_code, payment_method_code, customer_email, customer_phone, customer_name)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def initiate_transaction(transaction)
|
|
30
|
+
response = create_transaction_request(transaction)
|
|
31
|
+
process_response(response)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def make_seamless_payment(payment, reason_for_payment, amount, payment_method_required_fields, reference = nil)
|
|
35
|
+
response = create_seamless_payment_request(payment, reason_for_payment, amount, payment_method_required_fields, reference)
|
|
36
|
+
process_response(response)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def get_payment_method_code(currency_code)
|
|
40
|
+
response = get_payment_method_code_request(currency_code)
|
|
41
|
+
process_get_code_method(response)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def poll_transaction(poll_url)
|
|
45
|
+
url = URI(poll_url)
|
|
46
|
+
|
|
47
|
+
http = Net::HTTP.new(url.host, url.port)
|
|
48
|
+
http.use_ssl = true
|
|
49
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
50
|
+
|
|
51
|
+
request = Net::HTTP::Get.new(url)
|
|
52
|
+
request["Authorization"] = @integration_key
|
|
53
|
+
request["Content-Type"] = "application/json"
|
|
54
|
+
response = http.request(request)
|
|
55
|
+
|
|
56
|
+
process_poll_response(response)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def check_payment(reference_number)
|
|
60
|
+
url = "https://api.pesepay.com/api/payments-engine/v1/payments/check-payment?reference_number=#{reference_number}"
|
|
61
|
+
poll_transaction(url)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
private
|
|
65
|
+
|
|
66
|
+
def create_transaction_request(transaction)
|
|
67
|
+
data = build_transaction_data(transaction)
|
|
68
|
+
|
|
69
|
+
url = URI("https://api.pesepay.com/api/payments-engine/v1/payments/initiate")
|
|
70
|
+
|
|
71
|
+
http = Net::HTTP.new(url.host, url.port)
|
|
72
|
+
http.use_ssl = true
|
|
73
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
74
|
+
|
|
75
|
+
request = Net::HTTP::Post.new(url)
|
|
76
|
+
request["Authorization"] = @integration_key
|
|
77
|
+
request["Content-Type"] = "application/json"
|
|
78
|
+
request.body = { payload: data }.to_json
|
|
79
|
+
http.request(request)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def create_seamless_payment_request(payment, reason_for_payment, amount, payment_method_required_fields, reference)
|
|
83
|
+
data = build_seamless_payment_data(payment, reason_for_payment, amount, payment_method_required_fields, reference)
|
|
84
|
+
|
|
85
|
+
url = URI("https://api.pesepay.com/api/payments-engine/v2/payments/make-payment")
|
|
86
|
+
|
|
87
|
+
http = Net::HTTP.new(url.host, url.port)
|
|
88
|
+
http.use_ssl = true
|
|
89
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
90
|
+
|
|
91
|
+
request = Net::HTTP::Post.new(url)
|
|
92
|
+
request["Authorization"] = @integration_key
|
|
93
|
+
request["Content-Type"] = "application/json"
|
|
94
|
+
request.body = { payload: data }.to_json
|
|
95
|
+
http.request(request)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def get_payment_method_code_request(currency_code)
|
|
99
|
+
url = URI("https://api.pesepay.com/api/payments-engine/v1/payment-methods/for-currency?currencyCode=#{currency_code}")
|
|
100
|
+
|
|
101
|
+
http = Net::HTTP.new(url.host, url.port)
|
|
102
|
+
http.use_ssl = true
|
|
103
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
104
|
+
|
|
105
|
+
request = Net::HTTP::Get.new(url)
|
|
106
|
+
http.request(request)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def process_get_code_method(response)
|
|
110
|
+
if response.code == "200"
|
|
111
|
+
response_body = JSON.parse(response.body)
|
|
112
|
+
payment_method_code = response_body[0]["code"]
|
|
113
|
+
return payment_method_code
|
|
114
|
+
else
|
|
115
|
+
Response.new(false, message: "Unable to get payment method code")
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def process_response(response)
|
|
120
|
+
if response.code == "200"
|
|
121
|
+
response_body = JSON.parse(response.body.gsub("'", '"'))
|
|
122
|
+
inner_payload = response_body["payload"]
|
|
123
|
+
raw_response = decrypt(inner_payload, @encryption_key)
|
|
124
|
+
json_string = JSON.parse(raw_response)
|
|
125
|
+
ref_no = json_string["reference_number"]
|
|
126
|
+
poll_url = json_string["poll_url"]
|
|
127
|
+
redirect_url = json_string["redirect_url"]
|
|
128
|
+
Response.new(true, reference_number: ref_no, poll_url: poll_url, redirect_url: redirect_url, json_string: json_string)
|
|
129
|
+
else
|
|
130
|
+
message = JSON.parse(response.body)["message"]
|
|
131
|
+
Response.new(false, message: message)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def process_poll_response(response)
|
|
136
|
+
if response.code == "200"
|
|
137
|
+
response_body = JSON.parse(response.body)
|
|
138
|
+
inner_payload = response_body["payload"]
|
|
139
|
+
raw_response = decrypt(inner_payload)
|
|
140
|
+
json_string = JSON.parse(raw_response)
|
|
141
|
+
reference_number = json_string["reference_number"]
|
|
142
|
+
poll_url = json_string["poll_url"]
|
|
143
|
+
paid = json_string["transactionStatus"] == "SUCCESS"
|
|
144
|
+
|
|
145
|
+
StatusResponse.new(reference_number, poll_url, paid, json_string)
|
|
146
|
+
else
|
|
147
|
+
message = JSON.parse(response.body)["message"]
|
|
148
|
+
StatusResponse.new(nil, nil, false, message)
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def build_transaction_data(transaction)
|
|
153
|
+
payload = {
|
|
154
|
+
"amountDetails": {
|
|
155
|
+
"amount": transaction.amount,
|
|
156
|
+
"currencyCode": transaction.currency_code,
|
|
157
|
+
},
|
|
158
|
+
"reasonForPayment": transaction.reason_for_payment,
|
|
159
|
+
"resultUrl": @result_url,
|
|
160
|
+
"returnUrl": @return_url,
|
|
161
|
+
"merchantReference": transaction.reference,
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
encrypted = encrypt(payload.to_json, @encryption_key)
|
|
165
|
+
encrypted
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def build_seamless_payment_data(payment, reason_for_payment, amount, payment_method_required_fields, reference)
|
|
169
|
+
payload = {
|
|
170
|
+
"amountDetails": {
|
|
171
|
+
"amount": amount,
|
|
172
|
+
"currencyCode": payment.currency_code,
|
|
173
|
+
},
|
|
174
|
+
"merchantReference": reference,
|
|
175
|
+
"reasonForPayment": reason_for_payment,
|
|
176
|
+
"resultUrl": @result_url,
|
|
177
|
+
"returnUrl": @return_url,
|
|
178
|
+
"paymentMethodCode": payment.payment_method_code,
|
|
179
|
+
"customer": {
|
|
180
|
+
"email": payment.customer_email,
|
|
181
|
+
"phoneNumber": payment.customer_phone,
|
|
182
|
+
"name": payment.customer_name,
|
|
183
|
+
},
|
|
184
|
+
"paymentMethodRequiredFields": payment_method_required_fields,
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
encrypted = encrypt(payload.to_json, @encryption_key)
|
|
188
|
+
encrypted
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def encrypt(payload, key)
|
|
192
|
+
init_vector = key[0, 16]
|
|
193
|
+
cryptor = OpenSSL::Cipher::AES.new(256, :CBC)
|
|
194
|
+
cryptor.encrypt
|
|
195
|
+
cryptor.key = key
|
|
196
|
+
cryptor.iv = init_vector
|
|
197
|
+
ciphertext = cryptor.update(pad(payload)) + cryptor.final
|
|
198
|
+
Base64.strict_encode64(ciphertext)
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def decrypt(payload, key)
|
|
202
|
+
ciphertext = Base64.strict_decode64(payload)
|
|
203
|
+
init_vector = key[0, 16]
|
|
204
|
+
cryptor = OpenSSL::Cipher::AES.new(256, :CBC)
|
|
205
|
+
cryptor.decrypt
|
|
206
|
+
cryptor.key = key
|
|
207
|
+
cryptor.iv = init_vector
|
|
208
|
+
plaintext = cryptor.update(ciphertext) + cryptor.final
|
|
209
|
+
plaintext
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def pad(input)
|
|
213
|
+
padding_length = 16 - (input.length % 16)
|
|
214
|
+
input + (padding_length.chr * padding_length)
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
class Response
|
|
219
|
+
attr_reader :success, :reference_number, :poll_url, :redirect_url, :message, :raw_data
|
|
220
|
+
|
|
221
|
+
def initialize(success, reference_number: nil, poll_url: nil, redirect_url: nil, message: nil, json_string: nil)
|
|
222
|
+
@success = success
|
|
223
|
+
@reference_number = reference_number
|
|
224
|
+
@poll_url = poll_url
|
|
225
|
+
@redirect_url = redirect_url
|
|
226
|
+
@message = message
|
|
227
|
+
@raw_data = json_string
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
class StatusResponse
|
|
234
|
+
attr_reader :reference_number, :poll_url, :paid, :raw_data
|
|
235
|
+
|
|
236
|
+
def initialize(reference_number: nil, poll_url: nil, paid: false, json_string: nil)
|
|
237
|
+
@paid = paid
|
|
238
|
+
@reference_number = reference_number
|
|
239
|
+
@poll_url = poll_url
|
|
240
|
+
@raw_data = json_string
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
class Transaction
|
|
245
|
+
attr_accessor :amount, :currency_code, :reason_for_payment, :reference
|
|
246
|
+
|
|
247
|
+
def initialize(amount, currency_code, reason_for_payment, reference)
|
|
248
|
+
@amount = amount
|
|
249
|
+
@currency_code = currency_code
|
|
250
|
+
@reason_for_payment = reason_for_payment
|
|
251
|
+
@reference = reference
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
class Payment
|
|
256
|
+
attr_accessor :currency_code, :payment_method_code, :customer_email, :customer_phone, :customer_name
|
|
257
|
+
|
|
258
|
+
def initialize(currency_code, payment_method_code, customer_email = nil, customer_phone = nil, customer_name = nil)
|
|
259
|
+
@currency_code = currency_code
|
|
260
|
+
@payment_method_code = payment_method_code
|
|
261
|
+
@customer_email = customer_email
|
|
262
|
+
@customer_phone = customer_phone
|
|
263
|
+
@customer_name = customer_name
|
|
264
|
+
end
|
|
265
|
+
end
|
|
266
|
+
end
|
data/pesepay.gemspec
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "lib/pesepay/version"
|
|
4
|
-
|
|
5
|
-
Gem::Specification.new do |spec|
|
|
6
|
-
spec.name = "pesepay"
|
|
7
|
-
spec.version = Pesepay::VERSION
|
|
8
|
-
spec.authors = ["gitnyasha"]
|
|
9
|
-
spec.email = ["marshall.chikari@gmail.com"]
|
|
10
|
-
|
|
11
|
-
spec.summary = "Pesepay ruby library."
|
|
12
|
-
spec.description = "A ruby library for Pesepay Payment Gateway API."
|
|
13
|
-
spec.homepage = "https://github.com/gitnyasha/pesepay-ruby"
|
|
14
|
-
spec.license = "MIT"
|
|
15
|
-
spec.required_ruby_version = ">= 2.4.0"
|
|
16
|
-
|
|
17
|
-
spec.metadata["allowed_push_host"] = "https://rubygems.org/"
|
|
18
|
-
|
|
19
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
|
20
|
-
spec.metadata["source_code_uri"] = "https://github.com/gitnyasha/pesepay-ruby"
|
|
21
|
-
spec.metadata["changelog_uri"] = "https://github.com/gitnyasha/pesepay-ruby"
|
|
22
|
-
|
|
23
|
-
# Specify which files should be added to the gem when it is released.
|
|
24
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
25
|
-
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
26
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
|
27
|
-
end
|
|
28
|
-
spec.bindir = "exe"
|
|
29
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
30
|
-
spec.require_paths = ["lib"]
|
|
31
|
-
|
|
32
|
-
# Uncomment to register a new dependency of your gem
|
|
33
|
-
# spec.add_dependency "example-gem", "~> 1.0"
|
|
34
|
-
|
|
35
|
-
# For more information and examples about making a new gem, checkout our
|
|
36
|
-
# guide at: https://bundler.io/guides/creating_gem.html
|
|
37
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/pesepay/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "pesepay"
|
|
7
|
+
spec.version = Pesepay::VERSION
|
|
8
|
+
spec.authors = ["gitnyasha"]
|
|
9
|
+
spec.email = ["marshall.chikari@gmail.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "Pesepay ruby library."
|
|
12
|
+
spec.description = "A ruby library for Pesepay Payment Gateway API."
|
|
13
|
+
spec.homepage = "https://github.com/gitnyasha/pesepay-ruby"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
spec.required_ruby_version = ">= 2.4.0"
|
|
16
|
+
|
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org/"
|
|
18
|
+
|
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/gitnyasha/pesepay-ruby"
|
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/gitnyasha/pesepay-ruby"
|
|
22
|
+
|
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
|
27
|
+
end
|
|
28
|
+
spec.bindir = "exe"
|
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
30
|
+
spec.require_paths = ["lib"]
|
|
31
|
+
|
|
32
|
+
# Uncomment to register a new dependency of your gem
|
|
33
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
|
34
|
+
|
|
35
|
+
# For more information and examples about making a new gem, checkout our
|
|
36
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
|
37
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pesepay
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- gitnyasha
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies: []
|
|
13
12
|
description: A ruby library for Pesepay Payment Gateway API.
|
|
14
13
|
email:
|
|
@@ -41,7 +40,6 @@ metadata:
|
|
|
41
40
|
homepage_uri: https://github.com/gitnyasha/pesepay-ruby
|
|
42
41
|
source_code_uri: https://github.com/gitnyasha/pesepay-ruby
|
|
43
42
|
changelog_uri: https://github.com/gitnyasha/pesepay-ruby
|
|
44
|
-
post_install_message:
|
|
45
43
|
rdoc_options: []
|
|
46
44
|
require_paths:
|
|
47
45
|
- lib
|
|
@@ -56,8 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
56
54
|
- !ruby/object:Gem::Version
|
|
57
55
|
version: '0'
|
|
58
56
|
requirements: []
|
|
59
|
-
rubygems_version: 3.
|
|
60
|
-
signing_key:
|
|
57
|
+
rubygems_version: 3.7.1
|
|
61
58
|
specification_version: 4
|
|
62
59
|
summary: Pesepay ruby library.
|
|
63
60
|
test_files: []
|