paystack-gateway 0.1.1 → 0.2.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/.rubocop.yml +12 -2
- data/CHANGELOG.md +57 -0
- data/README.md +81 -102
- data/lib/paystack_gateway/api_error.rb +3 -1
- data/lib/paystack_gateway/apple_pay.rb +92 -0
- data/lib/paystack_gateway/balance.rb +62 -0
- data/lib/paystack_gateway/bank.rb +181 -0
- data/lib/paystack_gateway/bulk_charge.rb +197 -0
- data/lib/paystack_gateway/charge.rb +346 -0
- data/lib/paystack_gateway/configuration.rb +13 -2
- data/lib/paystack_gateway/customer.rb +498 -0
- data/lib/paystack_gateway/customers.rb +1 -42
- data/lib/paystack_gateway/dedicated_virtual_account.rb +353 -0
- data/lib/paystack_gateway/dedicated_virtual_accounts.rb +1 -64
- data/lib/paystack_gateway/direct_debit.rb +64 -0
- data/lib/paystack_gateway/dispute.rb +380 -0
- data/lib/paystack_gateway/extensions/customer_extensions.rb +14 -0
- data/lib/paystack_gateway/extensions/plan_extensions.rb +36 -0
- data/lib/paystack_gateway/extensions/refund_extensions.rb +43 -0
- data/lib/paystack_gateway/extensions/transaction_extensions.rb +40 -0
- data/lib/paystack_gateway/extensions/transaction_response_extension.rb +31 -0
- data/lib/paystack_gateway/extensions/transfer_extensions.rb +34 -0
- data/lib/paystack_gateway/integration.rb +60 -0
- data/lib/paystack_gateway/legacy/customers.rb +48 -0
- data/lib/paystack_gateway/legacy/dedicated_virtual_accounts.rb +70 -0
- data/lib/paystack_gateway/legacy/miscellaneous.rb +30 -0
- data/lib/paystack_gateway/legacy/plans.rb +86 -0
- data/lib/paystack_gateway/legacy/refunds.rb +65 -0
- data/lib/paystack_gateway/legacy/subaccounts.rb +41 -0
- data/lib/paystack_gateway/legacy/transaction_response.rb +37 -0
- data/lib/paystack_gateway/legacy/transactions.rb +91 -0
- data/lib/paystack_gateway/legacy/transfer_recipients.rb +27 -0
- data/lib/paystack_gateway/legacy/transfers.rb +63 -0
- data/lib/paystack_gateway/legacy/verification.rb +37 -0
- data/lib/paystack_gateway/miscellaneous.rb +75 -13
- data/lib/paystack_gateway/order.rb +259 -0
- data/lib/paystack_gateway/page.rb +317 -0
- data/lib/paystack_gateway/payment_request.rb +454 -0
- data/lib/paystack_gateway/plan.rb +247 -0
- data/lib/paystack_gateway/plans.rb +1 -80
- data/lib/paystack_gateway/product.rb +303 -0
- data/lib/paystack_gateway/refund.rb +197 -0
- data/lib/paystack_gateway/refunds.rb +1 -59
- data/lib/paystack_gateway/request_module.rb +12 -11
- data/lib/paystack_gateway/settlement.rb +60 -0
- data/lib/paystack_gateway/split.rb +286 -0
- data/lib/paystack_gateway/storefront.rb +329 -0
- data/lib/paystack_gateway/subaccount.rb +263 -0
- data/lib/paystack_gateway/subaccounts.rb +1 -35
- data/lib/paystack_gateway/subscription.rb +256 -0
- data/lib/paystack_gateway/terminal.rb +236 -0
- data/lib/paystack_gateway/transaction.rb +592 -0
- data/lib/paystack_gateway/transaction_response.rb +1 -33
- data/lib/paystack_gateway/transactions.rb +1 -86
- data/lib/paystack_gateway/transfer.rb +410 -0
- data/lib/paystack_gateway/transfer_recipient.rb +237 -0
- data/lib/paystack_gateway/transfer_recipients.rb +1 -21
- data/lib/paystack_gateway/transfers.rb +1 -57
- data/lib/paystack_gateway/verification.rb +1 -31
- data/lib/paystack_gateway/version.rb +1 -1
- data/lib/paystack_gateway/virtual_terminal.rb +297 -0
- data/lib/paystack_gateway.rb +50 -18
- metadata +50 -7
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PaystackGateway
|
|
4
|
+
# https://paystack.com/docs/api/charge
|
|
5
|
+
#
|
|
6
|
+
# Charges
|
|
7
|
+
# A collection of endpoints for configuring and managing the payment channels when initiating a payment
|
|
8
|
+
module Charge
|
|
9
|
+
include PaystackGateway::RequestModule
|
|
10
|
+
|
|
11
|
+
# Successful response from calling #create.
|
|
12
|
+
class CreateResponse < PaystackGateway::Response
|
|
13
|
+
delegate :id,
|
|
14
|
+
:domain,
|
|
15
|
+
:reference,
|
|
16
|
+
:receipt_number,
|
|
17
|
+
:amount,
|
|
18
|
+
:gateway_response,
|
|
19
|
+
:paid_at,
|
|
20
|
+
:created_at,
|
|
21
|
+
:channel,
|
|
22
|
+
:currency,
|
|
23
|
+
:ip_address,
|
|
24
|
+
:metadata,
|
|
25
|
+
:log,
|
|
26
|
+
:fees,
|
|
27
|
+
:fees_split,
|
|
28
|
+
:authorization,
|
|
29
|
+
:customer,
|
|
30
|
+
:plan,
|
|
31
|
+
:split,
|
|
32
|
+
:order_id,
|
|
33
|
+
:paidAt,
|
|
34
|
+
:createdAt,
|
|
35
|
+
:requested_amount,
|
|
36
|
+
:pos_transaction_data,
|
|
37
|
+
:source,
|
|
38
|
+
:fees_breakdown,
|
|
39
|
+
:connect,
|
|
40
|
+
:transaction_date,
|
|
41
|
+
:plan_object,
|
|
42
|
+
:subaccount, to: :data
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Error response from #create.
|
|
46
|
+
class CreateError < ApiError; end
|
|
47
|
+
|
|
48
|
+
# https://paystack.com/docs/api/charge/#create
|
|
49
|
+
# Create Charge: POST /charge
|
|
50
|
+
# Initiate a payment by integrating the payment channel of your choice.
|
|
51
|
+
#
|
|
52
|
+
# @param email [String] (required)
|
|
53
|
+
# Customer's email address
|
|
54
|
+
# @param amount [Integer] (required)
|
|
55
|
+
# Amount should be in kobo if currency is NGN, pesewas, if currency is GHS, and cents,
|
|
56
|
+
# if currency is ZAR
|
|
57
|
+
# @param authorization_code [String]
|
|
58
|
+
# An authorization code to charge.
|
|
59
|
+
# @param pin [String]
|
|
60
|
+
# 4-digit PIN (send with a non-reusable authorization code)
|
|
61
|
+
# @param reference [String]
|
|
62
|
+
# Unique transaction reference. Only -, .`, = and alphanumeric characters allowed.
|
|
63
|
+
# @param birthday [String]
|
|
64
|
+
# The customer's birthday in the format YYYY-MM-DD e.g 2017-05-16
|
|
65
|
+
# @param device_id [String]
|
|
66
|
+
# This is the unique identifier of the device a user uses in making payment. Only
|
|
67
|
+
# -, .`, = and alphanumeric characters are allowed.
|
|
68
|
+
# @param metadata [Hash]
|
|
69
|
+
# JSON object of custom data
|
|
70
|
+
# @param bank [Hash]
|
|
71
|
+
# The bank object if charging a bank account
|
|
72
|
+
# @option bank [String] :code
|
|
73
|
+
# Customer's bank code
|
|
74
|
+
# @option bank [String] :account_number
|
|
75
|
+
# Customer's account number
|
|
76
|
+
# @param mobile_money [Hash]
|
|
77
|
+
# Details of the mobile service provider
|
|
78
|
+
# @option mobile_money [String] :phone
|
|
79
|
+
# Customer's phone number
|
|
80
|
+
# @option mobile_money [String] :provider
|
|
81
|
+
# The telco provider of customer's phone number. This can be fetched from the List
|
|
82
|
+
# Bank endpoint
|
|
83
|
+
# @param ussd [Hash]
|
|
84
|
+
# The USSD code for the provider to charge
|
|
85
|
+
# @option ussd ["737", "919", "822", "966"] :type
|
|
86
|
+
# The three-digit USSD code.
|
|
87
|
+
# @param eft [Hash]
|
|
88
|
+
# Details of the EFT provider
|
|
89
|
+
# @option eft [String] :provider
|
|
90
|
+
# The EFT provider
|
|
91
|
+
#
|
|
92
|
+
# @return [CreateResponse] successful response
|
|
93
|
+
# @raise [CreateError] if the request fails
|
|
94
|
+
api_method def self.create(
|
|
95
|
+
email:,
|
|
96
|
+
amount:,
|
|
97
|
+
authorization_code: nil,
|
|
98
|
+
pin: nil,
|
|
99
|
+
reference: nil,
|
|
100
|
+
birthday: nil,
|
|
101
|
+
device_id: nil,
|
|
102
|
+
metadata: nil,
|
|
103
|
+
bank: nil,
|
|
104
|
+
mobile_money: nil,
|
|
105
|
+
ussd: nil,
|
|
106
|
+
eft: nil
|
|
107
|
+
)
|
|
108
|
+
use_connection do |connection|
|
|
109
|
+
connection.post(
|
|
110
|
+
'/charge',
|
|
111
|
+
{
|
|
112
|
+
email:,
|
|
113
|
+
amount:,
|
|
114
|
+
authorization_code:,
|
|
115
|
+
pin:,
|
|
116
|
+
reference:,
|
|
117
|
+
birthday:,
|
|
118
|
+
device_id:,
|
|
119
|
+
metadata:,
|
|
120
|
+
bank:,
|
|
121
|
+
mobile_money:,
|
|
122
|
+
ussd:,
|
|
123
|
+
eft:,
|
|
124
|
+
}.compact,
|
|
125
|
+
)
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# Successful response from calling #submit_pin.
|
|
130
|
+
class SubmitPinResponse < PaystackGateway::Response
|
|
131
|
+
delegate :amount,
|
|
132
|
+
:currency,
|
|
133
|
+
:transaction_date,
|
|
134
|
+
:reference,
|
|
135
|
+
:domain,
|
|
136
|
+
:redirect_url,
|
|
137
|
+
:metadata,
|
|
138
|
+
:gateway_response,
|
|
139
|
+
:channel,
|
|
140
|
+
:fees,
|
|
141
|
+
:authorization,
|
|
142
|
+
:customer, to: :data
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Error response from #submit_pin.
|
|
146
|
+
class SubmitPinError < ApiError; end
|
|
147
|
+
|
|
148
|
+
# https://paystack.com/docs/api/charge/#submit_pin
|
|
149
|
+
# Submit PIN: POST /charge/submit_pin
|
|
150
|
+
# Submit PIN to continue a charge
|
|
151
|
+
#
|
|
152
|
+
# @param pin [String] (required)
|
|
153
|
+
# Customer's PIN for the ongoing transaction
|
|
154
|
+
# @param reference [String] (required)
|
|
155
|
+
# Transaction reference that requires the PIN
|
|
156
|
+
#
|
|
157
|
+
# @return [SubmitPinResponse] successful response
|
|
158
|
+
# @raise [SubmitPinError] if the request fails
|
|
159
|
+
api_method def self.submit_pin(pin:, reference:)
|
|
160
|
+
use_connection do |connection|
|
|
161
|
+
connection.post(
|
|
162
|
+
'/charge/submit_pin',
|
|
163
|
+
{ pin:, reference: }.compact,
|
|
164
|
+
)
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
# Successful response from calling #submit_otp.
|
|
169
|
+
class SubmitOtpResponse < PaystackGateway::Response
|
|
170
|
+
delegate :amount,
|
|
171
|
+
:currency,
|
|
172
|
+
:transaction_date,
|
|
173
|
+
:reference,
|
|
174
|
+
:domain,
|
|
175
|
+
:redirect_url,
|
|
176
|
+
:metadata,
|
|
177
|
+
:gateway_response,
|
|
178
|
+
:channel,
|
|
179
|
+
:fees,
|
|
180
|
+
:authorization,
|
|
181
|
+
:customer, to: :data
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
# Error response from #submit_otp.
|
|
185
|
+
class SubmitOtpError < ApiError; end
|
|
186
|
+
|
|
187
|
+
# https://paystack.com/docs/api/charge/#submit_otp
|
|
188
|
+
# Submit OTP: POST /charge/submit_otp
|
|
189
|
+
# Submit OTP to complete a charge
|
|
190
|
+
#
|
|
191
|
+
# @param otp [String] (required)
|
|
192
|
+
# Customer's OTP for ongoing transaction
|
|
193
|
+
# @param reference [String] (required)
|
|
194
|
+
# The reference of the ongoing transaction
|
|
195
|
+
#
|
|
196
|
+
# @return [SubmitOtpResponse] successful response
|
|
197
|
+
# @raise [SubmitOtpError] if the request fails
|
|
198
|
+
api_method def self.submit_otp(otp:, reference:)
|
|
199
|
+
use_connection do |connection|
|
|
200
|
+
connection.post(
|
|
201
|
+
'/charge/submit_otp',
|
|
202
|
+
{ otp:, reference: }.compact,
|
|
203
|
+
)
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
# Successful response from calling #submit_phone.
|
|
208
|
+
class SubmitPhoneResponse < PaystackGateway::Response
|
|
209
|
+
delegate :amount,
|
|
210
|
+
:currency,
|
|
211
|
+
:transaction_date,
|
|
212
|
+
:reference,
|
|
213
|
+
:domain,
|
|
214
|
+
:redirect_url,
|
|
215
|
+
:metadata,
|
|
216
|
+
:gateway_response,
|
|
217
|
+
:channel,
|
|
218
|
+
:fees,
|
|
219
|
+
:authorization,
|
|
220
|
+
:customer,
|
|
221
|
+
:display_text, to: :data
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
# Error response from #submit_phone.
|
|
225
|
+
class SubmitPhoneError < ApiError; end
|
|
226
|
+
|
|
227
|
+
# https://paystack.com/docs/api/charge/#submit_phone
|
|
228
|
+
# Submit Phone: POST /charge/submit_phone
|
|
229
|
+
# Submit phone number when requested
|
|
230
|
+
#
|
|
231
|
+
# @param phone [String] (required)
|
|
232
|
+
# Customer's mobile number
|
|
233
|
+
# @param reference [String] (required)
|
|
234
|
+
# The reference of the ongoing transaction
|
|
235
|
+
#
|
|
236
|
+
# @return [SubmitPhoneResponse] successful response
|
|
237
|
+
# @raise [SubmitPhoneError] if the request fails
|
|
238
|
+
api_method def self.submit_phone(phone:, reference:)
|
|
239
|
+
use_connection do |connection|
|
|
240
|
+
connection.post(
|
|
241
|
+
'/charge/submit_phone',
|
|
242
|
+
{ phone:, reference: }.compact,
|
|
243
|
+
)
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
# Successful response from calling #submit_birthday.
|
|
248
|
+
class SubmitBirthdayResponse < PaystackGateway::Response
|
|
249
|
+
delegate :display_text, to: :data
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
# Error response from #submit_birthday.
|
|
253
|
+
class SubmitBirthdayError < ApiError; end
|
|
254
|
+
|
|
255
|
+
# https://paystack.com/docs/api/charge/#submit_birthday
|
|
256
|
+
# Submit Birthday: POST /charge/submit_birthday
|
|
257
|
+
# Submit the customer's birthday when requested
|
|
258
|
+
#
|
|
259
|
+
# @param birthday [String] (required)
|
|
260
|
+
# Customer's birthday in the format YYYY-MM-DD e.g 2016-09-21
|
|
261
|
+
# @param reference [String] (required)
|
|
262
|
+
# The reference of the ongoing transaction
|
|
263
|
+
#
|
|
264
|
+
# @return [SubmitBirthdayResponse] successful response
|
|
265
|
+
# @raise [SubmitBirthdayError] if the request fails
|
|
266
|
+
api_method def self.submit_birthday(birthday:, reference:)
|
|
267
|
+
use_connection do |connection|
|
|
268
|
+
connection.post(
|
|
269
|
+
'/charge/submit_birthday',
|
|
270
|
+
{ birthday:, reference: }.compact,
|
|
271
|
+
)
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
# Successful response from calling #submit_address.
|
|
276
|
+
class SubmitAddressResponse < PaystackGateway::Response; end
|
|
277
|
+
|
|
278
|
+
# Error response from #submit_address.
|
|
279
|
+
class SubmitAddressError < ApiError; end
|
|
280
|
+
|
|
281
|
+
# https://paystack.com/docs/api/charge/#submit_address
|
|
282
|
+
# Submit Address: POST /charge/submit_address
|
|
283
|
+
# Send the details of the customer's address for address verification
|
|
284
|
+
#
|
|
285
|
+
# @param address [String] (required)
|
|
286
|
+
# Customer's address
|
|
287
|
+
# @param city [String] (required)
|
|
288
|
+
# Customer's city
|
|
289
|
+
# @param state [String] (required)
|
|
290
|
+
# Customer's state
|
|
291
|
+
# @param zip_code [String] (required)
|
|
292
|
+
# Customer's zipcode
|
|
293
|
+
# @param reference [String] (required)
|
|
294
|
+
# The reference of the ongoing transaction
|
|
295
|
+
#
|
|
296
|
+
# @return [SubmitAddressResponse] successful response
|
|
297
|
+
# @raise [SubmitAddressError] if the request fails
|
|
298
|
+
api_method def self.submit_address(address:, city:, state:, zip_code:, reference:)
|
|
299
|
+
use_connection do |connection|
|
|
300
|
+
connection.post(
|
|
301
|
+
'/charge/submit_address',
|
|
302
|
+
{ address:, city:, state:, zip_code:, reference: }.compact,
|
|
303
|
+
)
|
|
304
|
+
end
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
# Successful response from calling #check.
|
|
308
|
+
class CheckResponse < PaystackGateway::Response
|
|
309
|
+
delegate :amount,
|
|
310
|
+
:currency,
|
|
311
|
+
:transaction_date,
|
|
312
|
+
:reference,
|
|
313
|
+
:domain,
|
|
314
|
+
:redirect_url,
|
|
315
|
+
:metadata,
|
|
316
|
+
:gateway_response,
|
|
317
|
+
:channel,
|
|
318
|
+
:fees,
|
|
319
|
+
:authorization,
|
|
320
|
+
:customer, to: :data
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
# Error response from #check.
|
|
324
|
+
class CheckError < ApiError; end
|
|
325
|
+
|
|
326
|
+
# https://paystack.com/docs/api/charge/#check
|
|
327
|
+
# Check pending charge: GET /charge/{reference}
|
|
328
|
+
# When you get `pending` as a charge status or if there was an exception when calling
|
|
329
|
+
# any of the `/charge` endpoints, wait 10 seconds or more, then make a check to see
|
|
330
|
+
# if its status has changed. Don't call too early as you may get a lot more pending
|
|
331
|
+
# than you should.
|
|
332
|
+
#
|
|
333
|
+
# @param reference [String] (required)
|
|
334
|
+
# The reference of the ongoing transaction
|
|
335
|
+
#
|
|
336
|
+
# @return [CheckResponse] successful response
|
|
337
|
+
# @raise [CheckError] if the request fails
|
|
338
|
+
api_method def self.check(reference:)
|
|
339
|
+
use_connection do |connection|
|
|
340
|
+
connection.get(
|
|
341
|
+
"/charge/#{reference}",
|
|
342
|
+
)
|
|
343
|
+
end
|
|
344
|
+
end
|
|
345
|
+
end
|
|
346
|
+
end
|
|
@@ -7,11 +7,22 @@ module PaystackGateway
|
|
|
7
7
|
# Encapsulates the configuration options for PaystackGateway including the
|
|
8
8
|
# secret key, logger, logging_options, and log filter.
|
|
9
9
|
class Configuration
|
|
10
|
-
attr_accessor :secret_key, :logger, :logging_options, :log_filter
|
|
10
|
+
attr_accessor :secret_key, :logger, :logging_options, :log_filter, :use_extensions
|
|
11
11
|
|
|
12
12
|
def initialize
|
|
13
|
-
@logger = Logger.new($stdout)
|
|
13
|
+
@logger = Logger.new($stdout, level: :info)
|
|
14
14
|
@log_filter = lambda(&:dup)
|
|
15
|
+
@use_extensions = true
|
|
15
16
|
end
|
|
16
17
|
end
|
|
18
|
+
|
|
19
|
+
class << self
|
|
20
|
+
attr_writer :config
|
|
21
|
+
|
|
22
|
+
delegate :secret_key, :logger, :logging_options, :log_filter, :use_extensions,
|
|
23
|
+
to: :config
|
|
24
|
+
|
|
25
|
+
def config = @config ||= Configuration.new
|
|
26
|
+
def configure = yield(config)
|
|
27
|
+
end
|
|
17
28
|
end
|