paystack_sdk 0.1.0 → 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/CHANGELOG.md +67 -0
- data/README.md +624 -86
- data/lib/paystack_sdk/client.rb +72 -14
- data/lib/paystack_sdk/middleware/transport_errors.rb +23 -0
- data/lib/paystack_sdk/request_helpers.rb +117 -0
- data/lib/paystack_sdk/resources/banks.rb +163 -13
- data/lib/paystack_sdk/resources/base.rb +4 -2
- data/lib/paystack_sdk/resources/charges.rb +219 -0
- data/lib/paystack_sdk/resources/customers.rb +262 -145
- data/lib/paystack_sdk/resources/extensions/charges.rb +65 -0
- data/lib/paystack_sdk/resources/miscellaneous.rb +58 -0
- data/lib/paystack_sdk/resources/refunds.rb +116 -0
- data/lib/paystack_sdk/resources/transactions.rb +365 -238
- data/lib/paystack_sdk/resources/transfer_recipients.rb +135 -27
- data/lib/paystack_sdk/resources/transfers.rb +260 -25
- data/lib/paystack_sdk/response.rb +95 -18
- data/lib/paystack_sdk/utils/connection_utils.rb +100 -5
- data/lib/paystack_sdk/validations.rb +24 -20
- data/lib/paystack_sdk/version.rb +1 -1
- data/lib/paystack_sdk/webhook.rb +152 -0
- data/lib/paystack_sdk.rb +27 -2
- metadata +70 -16
- data/lib/paystack_sdk/resources/verification.rb +0 -36
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Generated by bin/paystack-scaffold from Paystack's OpenAPI spec (PaystackOSS/openapi@d9d444d).
|
|
4
|
+
# Do not edit by hand: regenerate it with `bin/paystack-scaffold Charge`. Hand-written extras go in lib/paystack_sdk/resources/extensions/charges.rb.
|
|
5
|
+
# scaffold-digest: 8744e957871c8477379f6dc1389cc1e79df5884a4e594936b9ce64ffb6907ef2
|
|
6
|
+
|
|
7
|
+
require_relative "base"
|
|
8
|
+
require_relative "extensions/charges"
|
|
9
|
+
|
|
10
|
+
module PaystackSdk
|
|
11
|
+
module Resources
|
|
12
|
+
# Charge operations.
|
|
13
|
+
class Charges < PaystackSdk::Resources::Base
|
|
14
|
+
include Extensions::Charges
|
|
15
|
+
|
|
16
|
+
# Ruby keyword => the parameter name Paystack documents.
|
|
17
|
+
WIRE_NAMES = {}.freeze
|
|
18
|
+
|
|
19
|
+
# Create Charge.
|
|
20
|
+
#
|
|
21
|
+
# Initiate a payment by integrating the payment channel of your choice.
|
|
22
|
+
#
|
|
23
|
+
# @param email [String] Customer's email address
|
|
24
|
+
# @param amount [Integer] Amount should be in kobo if currency is NGN, pesewas, if currency is GHS, and cents, if currency is ZAR
|
|
25
|
+
# @param authorization_code [String] An authorization code to charge.
|
|
26
|
+
# @param pin [String] 4-digit PIN (send with a non-reusable authorization code)
|
|
27
|
+
# @param reference [String] Unique transaction reference.
|
|
28
|
+
# @param birthday [String] The customer's birthday in the format YYYY-MM-DD e.g 2017-05-16
|
|
29
|
+
# @param device_id [String] This is the unique identifier of the device a user uses in making payment.
|
|
30
|
+
# @param metadata [Hash] JSON object of custom data
|
|
31
|
+
# @param bank [Hash] The bank object if charging a bank account
|
|
32
|
+
# @param mobile_money [Hash] Details of the mobile service provider
|
|
33
|
+
# @param ussd [Hash] The USSD code for the provider to charge
|
|
34
|
+
# @param eft [Hash] Details of the EFT provider
|
|
35
|
+
# @param currency [String] The currency to charge in (GHS, KES and so on); Paystack uses your integration's currency when it is left out.
|
|
36
|
+
# @param split_code [String] The split code (SPL_...) of a previously created split.
|
|
37
|
+
# @param subaccount [String] The code (ACCT_...) of the subaccount that owns the payment.
|
|
38
|
+
# @param bank_transfer [Hash] Settings for the Pay with Transfer and Pesalink channel (account_expires_at, the expiry time of the account).
|
|
39
|
+
# @param qr [Hash] The QR provider details (provider, scan-to-pay being the only one); South Africa only.
|
|
40
|
+
# @param capitec_pay [Hash] The Capitec Pay account holder (identifier_key, one of CELLPHONE, IDNUMBER or ACCOUNTNUMBER, and identifier_value); South Africa only.
|
|
41
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
42
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
43
|
+
# @see https://paystack.com/docs/api/charge/#create
|
|
44
|
+
def create(
|
|
45
|
+
email:,
|
|
46
|
+
amount:,
|
|
47
|
+
authorization_code: nil,
|
|
48
|
+
pin: nil,
|
|
49
|
+
reference: nil,
|
|
50
|
+
birthday: nil,
|
|
51
|
+
device_id: nil,
|
|
52
|
+
metadata: nil,
|
|
53
|
+
bank: nil,
|
|
54
|
+
mobile_money: nil,
|
|
55
|
+
ussd: nil,
|
|
56
|
+
eft: nil,
|
|
57
|
+
currency: nil,
|
|
58
|
+
split_code: nil,
|
|
59
|
+
subaccount: nil,
|
|
60
|
+
bank_transfer: nil,
|
|
61
|
+
qr: nil,
|
|
62
|
+
capitec_pay: nil
|
|
63
|
+
)
|
|
64
|
+
validate_presence!(value: email, name: "email")
|
|
65
|
+
validate_email!(email: email, name: "email")
|
|
66
|
+
validate_presence!(value: amount, name: "amount")
|
|
67
|
+
validate_positive_integer!(value: amount, name: "amount")
|
|
68
|
+
validate_reference_format!(reference: reference, name: "reference") unless reference.nil?
|
|
69
|
+
|
|
70
|
+
wire_body = to_wire(
|
|
71
|
+
{
|
|
72
|
+
email:,
|
|
73
|
+
amount:,
|
|
74
|
+
authorization_code:,
|
|
75
|
+
pin:,
|
|
76
|
+
reference:,
|
|
77
|
+
birthday: format_date(birthday, name: "birthday"),
|
|
78
|
+
device_id:,
|
|
79
|
+
metadata:,
|
|
80
|
+
bank:,
|
|
81
|
+
mobile_money:,
|
|
82
|
+
ussd:,
|
|
83
|
+
eft:,
|
|
84
|
+
currency:,
|
|
85
|
+
split_code:,
|
|
86
|
+
subaccount:,
|
|
87
|
+
bank_transfer:,
|
|
88
|
+
qr:,
|
|
89
|
+
capitec_pay:
|
|
90
|
+
},
|
|
91
|
+
WIRE_NAMES
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
handle_response(@connection.post("/charge", wire_body))
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Submit PIN.
|
|
98
|
+
#
|
|
99
|
+
# Submit PIN to continue a charge
|
|
100
|
+
#
|
|
101
|
+
# @param pin [String] Customer's PIN for the ongoing transaction
|
|
102
|
+
# @param reference [String] Transaction reference that requires the PIN
|
|
103
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
104
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
105
|
+
# @see https://paystack.com/docs/api/charge/#submit-pin
|
|
106
|
+
def submit_pin(pin:, reference:)
|
|
107
|
+
validate_presence!(value: pin, name: "pin")
|
|
108
|
+
validate_presence!(value: reference, name: "reference")
|
|
109
|
+
validate_reference_format!(reference: reference, name: "reference")
|
|
110
|
+
|
|
111
|
+
wire_body = to_wire({pin:, reference:}, WIRE_NAMES)
|
|
112
|
+
|
|
113
|
+
handle_response(@connection.post("/charge/submit_pin", wire_body))
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Submit OTP.
|
|
117
|
+
#
|
|
118
|
+
# Submit OTP to complete a charge
|
|
119
|
+
#
|
|
120
|
+
# @param otp [String] Customer's OTP for ongoing transaction
|
|
121
|
+
# @param reference [String] The reference of the ongoing transaction
|
|
122
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
123
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
124
|
+
# @see https://paystack.com/docs/api/charge/#submit-otp
|
|
125
|
+
def submit_otp(otp:, reference:)
|
|
126
|
+
validate_presence!(value: otp, name: "otp")
|
|
127
|
+
validate_presence!(value: reference, name: "reference")
|
|
128
|
+
validate_reference_format!(reference: reference, name: "reference")
|
|
129
|
+
|
|
130
|
+
wire_body = to_wire({otp:, reference:}, WIRE_NAMES)
|
|
131
|
+
|
|
132
|
+
handle_response(@connection.post("/charge/submit_otp", wire_body))
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# Submit Phone.
|
|
136
|
+
#
|
|
137
|
+
# Submit phone number when requested
|
|
138
|
+
#
|
|
139
|
+
# @param phone [String] Customer's mobile number
|
|
140
|
+
# @param reference [String] The reference of the ongoing transaction
|
|
141
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
142
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
143
|
+
# @see https://paystack.com/docs/api/charge/#submit-phone
|
|
144
|
+
def submit_phone(phone:, reference:)
|
|
145
|
+
validate_presence!(value: phone, name: "phone")
|
|
146
|
+
validate_presence!(value: reference, name: "reference")
|
|
147
|
+
validate_reference_format!(reference: reference, name: "reference")
|
|
148
|
+
|
|
149
|
+
wire_body = to_wire({phone:, reference:}, WIRE_NAMES)
|
|
150
|
+
|
|
151
|
+
handle_response(@connection.post("/charge/submit_phone", wire_body))
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# Submit Birthday.
|
|
155
|
+
#
|
|
156
|
+
# Submit the customer's birthday when requested
|
|
157
|
+
#
|
|
158
|
+
# @param birthday [String] Customer's birthday in the format YYYY-MM-DD e.g 2016-09-21
|
|
159
|
+
# @param reference [String] The reference of the ongoing transaction
|
|
160
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
161
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
162
|
+
# @see https://paystack.com/docs/api/charge/#submit-birthday
|
|
163
|
+
def submit_birthday(birthday:, reference:)
|
|
164
|
+
validate_presence!(value: birthday, name: "birthday")
|
|
165
|
+
validate_presence!(value: reference, name: "reference")
|
|
166
|
+
validate_reference_format!(reference: reference, name: "reference")
|
|
167
|
+
|
|
168
|
+
wire_body = to_wire(
|
|
169
|
+
{
|
|
170
|
+
birthday: format_date(birthday, name: "birthday"),
|
|
171
|
+
reference:
|
|
172
|
+
},
|
|
173
|
+
WIRE_NAMES
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
handle_response(@connection.post("/charge/submit_birthday", wire_body))
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
# Submit Address.
|
|
180
|
+
#
|
|
181
|
+
# Send the details of the customer's address for address verification
|
|
182
|
+
#
|
|
183
|
+
# @param address [String] Customer's address
|
|
184
|
+
# @param city [String] Customer's city
|
|
185
|
+
# @param state [String] Customer's state
|
|
186
|
+
# @param zip_code [String] Customer's zipcode
|
|
187
|
+
# @param reference [String] The reference of the ongoing transaction
|
|
188
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
189
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
190
|
+
# @see https://paystack.com/docs/api/charge/#submit-address
|
|
191
|
+
def submit_address(address:, city:, state:, zip_code:, reference:)
|
|
192
|
+
validate_presence!(value: address, name: "address")
|
|
193
|
+
validate_presence!(value: city, name: "city")
|
|
194
|
+
validate_presence!(value: state, name: "state")
|
|
195
|
+
validate_presence!(value: zip_code, name: "zip_code")
|
|
196
|
+
validate_presence!(value: reference, name: "reference")
|
|
197
|
+
validate_reference_format!(reference: reference, name: "reference")
|
|
198
|
+
|
|
199
|
+
wire_body = to_wire({address:, city:, state:, zip_code:, reference:}, WIRE_NAMES)
|
|
200
|
+
|
|
201
|
+
handle_response(@connection.post("/charge/submit_address", wire_body))
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
# Check pending charge.
|
|
205
|
+
#
|
|
206
|
+
# When you get `pending` as a charge status or if there was an exception when calling any of the `/charge` endpoints, wait 10 seconds or more, then make a check to see if its status has changed.
|
|
207
|
+
#
|
|
208
|
+
# @param reference [String] The reference of the ongoing transaction
|
|
209
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
210
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
211
|
+
# @see https://paystack.com/docs/api/charge/#check
|
|
212
|
+
def check_pending(reference:)
|
|
213
|
+
validate_presence!(value: reference, name: "reference")
|
|
214
|
+
|
|
215
|
+
handle_response(@connection.get("/charge/#{escape_path(reference, name: "reference")}"))
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
end
|