paystack_sdk 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/CHANGELOG.md +67 -0
- data/README.md +624 -86
- data/lib/paystack_sdk/client.rb +64 -21
- 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 +190 -76
- data/lib/paystack_sdk/resources/customers.rb +260 -139
- 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 +88 -9
- data/lib/paystack_sdk/utils/connection_utils.rb +100 -5
- data/lib/paystack_sdk/version.rb +1 -1
- data/lib/paystack_sdk/webhook.rb +152 -0
- data/lib/paystack_sdk.rb +27 -2
- metadata +57 -4
- data/lib/paystack_sdk/resources/verification.rb +0 -36
|
@@ -1,187 +1,308 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
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 Customer`. Hand-written extras go in lib/paystack_sdk/resources/extensions/customers.rb.
|
|
5
|
+
# scaffold-digest: a6f9d22c6371a27b341370a5137dda91fe7a082cd0a60f49cdfadd3789cc924d
|
|
6
|
+
|
|
3
7
|
require_relative "base"
|
|
4
8
|
|
|
5
9
|
module PaystackSdk
|
|
6
10
|
module Resources
|
|
7
|
-
#
|
|
8
|
-
# It allows you to create, list, fetch, update, and manage customers on your integration.
|
|
9
|
-
#
|
|
10
|
-
# Example usage:
|
|
11
|
-
# ```ruby
|
|
12
|
-
# customers = PaystackSdk::Resources::Customers.new(secret_key:)
|
|
13
|
-
#
|
|
14
|
-
# # Create a customer
|
|
15
|
-
# payload = { email: "customer@email.com", first_name: "Zero", last_name: "Sum" }
|
|
16
|
-
# response = customers.create(payload)
|
|
17
|
-
# if response.success?
|
|
18
|
-
# puts "Customer created successfully."
|
|
19
|
-
# puts "Customer code: #{response.customer_code}"
|
|
20
|
-
# else
|
|
21
|
-
# puts "Error creating customer: #{response.error_message}"
|
|
22
|
-
# end
|
|
23
|
-
#
|
|
24
|
-
# # List customers
|
|
25
|
-
# response = customers.list(per_page: 50, page: 1)
|
|
26
|
-
#
|
|
27
|
-
# # Fetch a customer
|
|
28
|
-
# response = customers.fetch("CUS_xxxxx")
|
|
29
|
-
#
|
|
30
|
-
# # Update a customer
|
|
31
|
-
# response = customers.update("CUS_xxxxx", { first_name: "John" })
|
|
32
|
-
# ```
|
|
11
|
+
# Customer operations.
|
|
33
12
|
class Customers < PaystackSdk::Resources::Base
|
|
34
|
-
#
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
#
|
|
38
|
-
#
|
|
39
|
-
#
|
|
40
|
-
#
|
|
41
|
-
# @
|
|
13
|
+
# Ruby keyword => the parameter name Paystack documents.
|
|
14
|
+
WIRE_NAMES = {next_cursor: "next", per_page: "perPage"}.freeze
|
|
15
|
+
|
|
16
|
+
# List Customers.
|
|
17
|
+
#
|
|
18
|
+
# List customers on your integration
|
|
19
|
+
#
|
|
20
|
+
# @param use_cursor [Boolean] A flag to indicate if cursor based pagination should be used
|
|
21
|
+
# @param next_cursor [String] An alphanumeric value returned for every cursor based retrieval, used to retrieve the next set of data
|
|
22
|
+
# @param previous [String] An alphanumeric value returned for every cursor based retrieval, used to retrieve the previous set of data
|
|
23
|
+
# @param from [String] The start date
|
|
24
|
+
# @param to [String] The end date
|
|
25
|
+
# @param per_page [Integer] The number of records to fetch per request
|
|
26
|
+
# @param page [Integer] The offset to retrieve data from
|
|
42
27
|
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
43
|
-
# @raise [PaystackSdk::Error] If
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
28
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
29
|
+
# @see https://paystack.com/docs/api/customer/#list
|
|
30
|
+
def list(
|
|
31
|
+
use_cursor: nil,
|
|
32
|
+
next_cursor: nil,
|
|
33
|
+
previous: nil,
|
|
34
|
+
from: nil,
|
|
35
|
+
to: nil,
|
|
36
|
+
per_page: nil,
|
|
37
|
+
page: nil
|
|
38
|
+
)
|
|
39
|
+
validate_positive_integer!(value: per_page, name: "perPage")
|
|
40
|
+
validate_positive_integer!(value: page, name: "page")
|
|
41
|
+
|
|
42
|
+
wire_query = to_wire(
|
|
43
|
+
{
|
|
44
|
+
use_cursor:,
|
|
45
|
+
next_cursor:,
|
|
46
|
+
previous:,
|
|
47
|
+
from: format_datetime(from, name: "from"),
|
|
48
|
+
to: format_datetime(to, name: "to"),
|
|
49
|
+
per_page:,
|
|
50
|
+
page:
|
|
51
|
+
},
|
|
52
|
+
WIRE_NAMES
|
|
53
53
|
)
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
handle_response(response)
|
|
55
|
+
handle_response(@connection.get("/customer", wire_query))
|
|
57
56
|
end
|
|
58
57
|
|
|
59
|
-
#
|
|
58
|
+
# Create Customer.
|
|
59
|
+
#
|
|
60
|
+
# Create a customer on your integration
|
|
60
61
|
#
|
|
61
|
-
# @param
|
|
62
|
-
# @param
|
|
63
|
-
# @param
|
|
64
|
-
# @param
|
|
62
|
+
# @param email [String] Customer's email address
|
|
63
|
+
# @param first_name [String] Customer's first name
|
|
64
|
+
# @param last_name [String] Customer's last name
|
|
65
|
+
# @param phone [String] Customer's phone number
|
|
66
|
+
# @param metadata [Hash] A set of key/value pairs that you can attach to the customer.
|
|
65
67
|
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
66
|
-
# @raise [PaystackSdk::Error] If the API request fails.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
validate_date_format!(date_str: params[:from], name: "from") if params[:from]
|
|
68
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
69
|
+
# @see https://paystack.com/docs/api/customer/#create
|
|
70
|
+
def create(email:, first_name: nil, last_name: nil, phone: nil, metadata: nil)
|
|
71
|
+
validate_presence!(value: email, name: "email")
|
|
72
|
+
validate_email!(email: email, name: "email")
|
|
72
73
|
|
|
73
|
-
|
|
74
|
+
wire_body = to_wire({email:, first_name:, last_name:, phone:, metadata:}, WIRE_NAMES)
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
response = @connection.get("customer", query_params)
|
|
77
|
-
handle_response(response)
|
|
76
|
+
handle_response(@connection.post("/customer", wire_body))
|
|
78
77
|
end
|
|
79
78
|
|
|
80
|
-
#
|
|
79
|
+
# Fetch Customer.
|
|
81
80
|
#
|
|
82
|
-
#
|
|
81
|
+
# Get details of a customer on your integration.
|
|
82
|
+
#
|
|
83
|
+
# @param email_or_code [String] The code for the customer gotten from the response of the customer creation
|
|
83
84
|
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
84
|
-
# @raise [PaystackSdk::Error] If
|
|
85
|
-
|
|
85
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
86
|
+
# @see https://paystack.com/docs/api/customer/#fetch
|
|
87
|
+
def fetch(email_or_code:)
|
|
86
88
|
validate_presence!(value: email_or_code, name: "email_or_code")
|
|
87
|
-
|
|
88
|
-
handle_response(
|
|
89
|
+
|
|
90
|
+
handle_response(
|
|
91
|
+
@connection.get("/customer/#{escape_path(email_or_code, name: "email_or_code")}")
|
|
92
|
+
)
|
|
89
93
|
end
|
|
90
94
|
|
|
91
|
-
#
|
|
95
|
+
# Update Customer.
|
|
96
|
+
#
|
|
97
|
+
# Update a customer's details on your integration
|
|
92
98
|
#
|
|
93
|
-
# @param code [String]
|
|
94
|
-
# @param
|
|
95
|
-
# @
|
|
96
|
-
# @
|
|
97
|
-
# @
|
|
98
|
-
# @option payload [Hash] :metadata Additional customer information
|
|
99
|
+
# @param code [String] The code for the customer gotten from the response of the customer creation
|
|
100
|
+
# @param first_name [String] Customer's first name
|
|
101
|
+
# @param last_name [String] Customer's last name
|
|
102
|
+
# @param phone [String] Customer's phone number
|
|
103
|
+
# @param metadata [Hash] A set of key/value pairs that you can attach to the customer.
|
|
99
104
|
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
100
|
-
# @raise [PaystackSdk::Error] If
|
|
101
|
-
|
|
105
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
106
|
+
# @see https://paystack.com/docs/api/customer/#update
|
|
107
|
+
def update(code:, first_name: nil, last_name: nil, phone: nil, metadata: nil)
|
|
102
108
|
validate_presence!(value: code, name: "code")
|
|
103
|
-
validate_hash!(input: payload, name: "payload")
|
|
104
109
|
|
|
105
|
-
|
|
106
|
-
|
|
110
|
+
wire_body = to_wire({first_name:, last_name:, phone:, metadata:}, WIRE_NAMES)
|
|
111
|
+
|
|
112
|
+
handle_response(@connection.put("/customer/#{escape_path(code, name: "code")}", wire_body))
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Set Risk Action.
|
|
116
|
+
#
|
|
117
|
+
# Set customer's risk action by whitelisting or blacklisting the customer
|
|
118
|
+
#
|
|
119
|
+
# @param customer [String] The customer code from the response of the customer creation
|
|
120
|
+
# @param risk_action [String] This determines the fraud rules that should be applied to the customer One of: allow, deny, default.
|
|
121
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
122
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
123
|
+
# @see https://paystack.com/docs/api/customer/#whitelist-blacklist
|
|
124
|
+
def set_risk_action(customer:, risk_action: nil)
|
|
125
|
+
validate_presence!(value: customer, name: "customer")
|
|
126
|
+
validate_allowed_values!(
|
|
127
|
+
value: risk_action,
|
|
128
|
+
allowed_values: %w[allow deny default],
|
|
129
|
+
name: "risk_action"
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
wire_body = to_wire({customer:, risk_action:}, WIRE_NAMES)
|
|
133
|
+
|
|
134
|
+
handle_response(@connection.post("/customer/set_risk_action", wire_body))
|
|
107
135
|
end
|
|
108
136
|
|
|
109
|
-
#
|
|
110
|
-
#
|
|
111
|
-
#
|
|
112
|
-
#
|
|
113
|
-
# @
|
|
114
|
-
# @
|
|
115
|
-
# @
|
|
116
|
-
# @
|
|
117
|
-
# @
|
|
118
|
-
# @
|
|
119
|
-
# @
|
|
137
|
+
# Validate Customer.
|
|
138
|
+
#
|
|
139
|
+
# Validate a customer's identity
|
|
140
|
+
#
|
|
141
|
+
# @param code [String] The code for the customer gotten from the response of the customer creation
|
|
142
|
+
# @param first_name [String] Customer's first name
|
|
143
|
+
# @param last_name [String] Customer's last name
|
|
144
|
+
# @param type [String] Predefined types of identification.
|
|
145
|
+
# @param country [String] Two-letter country code of identification issuer
|
|
146
|
+
# @param bvn [String] Customer's Bank Verification Number
|
|
147
|
+
# @param bank_code [String] You can get the list of bank codes by calling the List Banks endpoint (https://api.paystack.co/bank).
|
|
148
|
+
# @param account_number [String] Customer's bank account number.
|
|
149
|
+
# @param middle_name [String] Customer's middle name
|
|
150
|
+
# @param value [String] Customer's identification number.
|
|
120
151
|
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
121
|
-
# @raise [PaystackSdk::Error] If
|
|
122
|
-
|
|
152
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
153
|
+
# @see https://paystack.com/docs/api/customer/#validate
|
|
154
|
+
def validate(
|
|
155
|
+
code:,
|
|
156
|
+
first_name:,
|
|
157
|
+
last_name:,
|
|
158
|
+
type:,
|
|
159
|
+
country:,
|
|
160
|
+
bvn:,
|
|
161
|
+
bank_code:,
|
|
162
|
+
account_number:,
|
|
163
|
+
middle_name: nil,
|
|
164
|
+
value: nil
|
|
165
|
+
)
|
|
123
166
|
validate_presence!(value: code, name: "code")
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
167
|
+
validate_presence!(value: first_name, name: "first_name")
|
|
168
|
+
validate_presence!(value: last_name, name: "last_name")
|
|
169
|
+
validate_presence!(value: type, name: "type")
|
|
170
|
+
validate_presence!(value: country, name: "country")
|
|
171
|
+
validate_presence!(value: bvn, name: "bvn")
|
|
172
|
+
validate_presence!(value: bank_code, name: "bank_code")
|
|
173
|
+
validate_presence!(value: account_number, name: "account_number")
|
|
174
|
+
|
|
175
|
+
wire_body = to_wire(
|
|
176
|
+
{
|
|
177
|
+
first_name:,
|
|
178
|
+
last_name:,
|
|
179
|
+
type:,
|
|
180
|
+
country:,
|
|
181
|
+
bvn:,
|
|
182
|
+
bank_code:,
|
|
183
|
+
account_number:,
|
|
184
|
+
middle_name:,
|
|
185
|
+
value:
|
|
186
|
+
},
|
|
187
|
+
WIRE_NAMES
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
handle_response(
|
|
191
|
+
@connection.post("/customer/#{escape_path(code, name: "code")}/identification", wire_body)
|
|
132
192
|
)
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# Initialize Authorization.
|
|
196
|
+
#
|
|
197
|
+
# Initiate a request to create a reusable authorization code for recurring transactions
|
|
198
|
+
#
|
|
199
|
+
# @param email [String] Customer's email address
|
|
200
|
+
# @param channel [String] direct_debit is the only supported option for now One of: direct_debit.
|
|
201
|
+
# @param callback_url [String] Fully qualified url (e.g.
|
|
202
|
+
# @param account [Hash]
|
|
203
|
+
# @param address [Hash]
|
|
204
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
205
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
206
|
+
# @see https://paystack.com/docs/api/customer/#initialize-authorization
|
|
207
|
+
def initialize_authorization(email:, channel:, callback_url: nil, account: nil, address: nil)
|
|
208
|
+
validate_presence!(value: email, name: "email")
|
|
209
|
+
validate_email!(email: email, name: "email")
|
|
210
|
+
validate_presence!(value: channel, name: "channel")
|
|
211
|
+
validate_allowed_values!(value: channel, allowed_values: %w[direct_debit], name: "channel")
|
|
133
212
|
|
|
134
|
-
|
|
135
|
-
|
|
213
|
+
wire_body = to_wire({email:, channel:, callback_url:, account:, address:}, WIRE_NAMES)
|
|
214
|
+
|
|
215
|
+
handle_response(@connection.post("/customer/authorization/initialize", wire_body))
|
|
136
216
|
end
|
|
137
217
|
|
|
138
|
-
#
|
|
218
|
+
# Verify Authorization.
|
|
219
|
+
#
|
|
220
|
+
# Check the status of an authorization request
|
|
139
221
|
#
|
|
140
|
-
# @param
|
|
141
|
-
# @option payload [String] :customer (required) Customer's code or email address
|
|
142
|
-
# @option payload [String] :risk_action (required) Risk action to set ('default', 'allow', or 'deny')
|
|
222
|
+
# @param reference [String] The reference returned in the initialization response
|
|
143
223
|
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
144
|
-
# @raise [PaystackSdk::
|
|
145
|
-
# @
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
# response = customers.set_risk_action(payload)
|
|
152
|
-
# if response.success?
|
|
153
|
-
# puts "Risk action updated successfully"
|
|
154
|
-
# end
|
|
155
|
-
# ```
|
|
156
|
-
def set_risk_action(payload)
|
|
157
|
-
validate_fields!(
|
|
158
|
-
payload: payload,
|
|
159
|
-
validations: {
|
|
160
|
-
customer: {type: :string, required: true},
|
|
161
|
-
risk_action: {type: :inclusion, required: true, allowed_values: %w[default allow deny]}
|
|
162
|
-
}
|
|
224
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
225
|
+
# @see https://paystack.com/docs/api/customer/#verify-authorization
|
|
226
|
+
def verify_authorization(reference:)
|
|
227
|
+
validate_presence!(value: reference, name: "reference")
|
|
228
|
+
|
|
229
|
+
handle_response(
|
|
230
|
+
@connection.get("/customer/authorization/verify/#{escape_path(reference, name: "reference")}")
|
|
163
231
|
)
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
# Deactivate Authorization.
|
|
235
|
+
#
|
|
236
|
+
# Deactivate an authorization for any payment channel.
|
|
237
|
+
#
|
|
238
|
+
# @param authorization_code [String] Authorization code to be deactivated
|
|
239
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
240
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
241
|
+
# @see https://paystack.com/docs/api/customer/#deactivate-authorization
|
|
242
|
+
def deactivate_authorization(authorization_code:)
|
|
243
|
+
validate_presence!(value: authorization_code, name: "authorization_code")
|
|
244
|
+
|
|
245
|
+
wire_body = to_wire({authorization_code:}, WIRE_NAMES)
|
|
246
|
+
|
|
247
|
+
handle_response(@connection.post("/customer/authorization/deactivate", wire_body))
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
# Initialize Direct Debit.
|
|
251
|
+
#
|
|
252
|
+
# Initialize the process of linking an account to a customer for Direct Debit transactions
|
|
253
|
+
#
|
|
254
|
+
# @param id [Integer] The ID of the customer to initialize the direct debit for
|
|
255
|
+
# @param account [Hash]
|
|
256
|
+
# @param address [Hash]
|
|
257
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
258
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
259
|
+
# @see https://paystack.com/docs/api/customer/#initialize-direct-debit
|
|
260
|
+
def initialize_direct_debit(id:, account:, address:)
|
|
261
|
+
validate_presence!(value: id, name: "id")
|
|
262
|
+
validate_presence!(value: account, name: "account")
|
|
263
|
+
validate_presence!(value: address, name: "address")
|
|
264
|
+
|
|
265
|
+
wire_body = to_wire({account:, address:}, WIRE_NAMES)
|
|
164
266
|
|
|
165
|
-
|
|
166
|
-
|
|
267
|
+
handle_response(
|
|
268
|
+
@connection.post("/customer/#{escape_path(id, name: "id")}/initialize-direct-debit", wire_body)
|
|
269
|
+
)
|
|
167
270
|
end
|
|
168
271
|
|
|
169
|
-
#
|
|
272
|
+
# Direct Debit Activation Charge.
|
|
273
|
+
#
|
|
274
|
+
# Trigger an activation charge on an inactive mandate on behalf of your customer
|
|
170
275
|
#
|
|
171
|
-
# @param
|
|
172
|
-
# @
|
|
276
|
+
# @param id [Integer] The customer ID attached to the authorization
|
|
277
|
+
# @param authorization_id [Integer] The authorization ID gotten from the initiation response
|
|
173
278
|
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
174
|
-
# @raise [PaystackSdk::Error] If
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
279
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
280
|
+
# @see https://paystack.com/docs/api/customer/#direct-debit-activation-charge
|
|
281
|
+
def direct_debit_activation_charge(id:, authorization_id:)
|
|
282
|
+
validate_presence!(value: id, name: "id")
|
|
283
|
+
validate_presence!(value: authorization_id, name: "authorization_id")
|
|
284
|
+
|
|
285
|
+
wire_body = to_wire({authorization_id:}, WIRE_NAMES)
|
|
286
|
+
|
|
287
|
+
handle_response(
|
|
288
|
+
@connection.put("/customer/#{escape_path(id, name: "id")}/directdebit-activation-charge", wire_body)
|
|
181
289
|
)
|
|
290
|
+
end
|
|
182
291
|
|
|
183
|
-
|
|
184
|
-
|
|
292
|
+
# Fetch Mandate Authorizations.
|
|
293
|
+
#
|
|
294
|
+
# Get the list of direct debit mandates associated with a customer
|
|
295
|
+
#
|
|
296
|
+
# @param id [Integer] The customer ID for the authorizations to fetch
|
|
297
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
298
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
299
|
+
# @see https://paystack.com/docs/api/customer/#directdebit-mandate-authorizations
|
|
300
|
+
def fetch_mandate_authorizations(id:)
|
|
301
|
+
validate_presence!(value: id, name: "id")
|
|
302
|
+
|
|
303
|
+
handle_response(
|
|
304
|
+
@connection.get("/customer/#{escape_path(id, name: "id")}/directdebit-mandate-authorizations")
|
|
305
|
+
)
|
|
185
306
|
end
|
|
186
307
|
end
|
|
187
308
|
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PaystackSdk
|
|
4
|
+
module Resources
|
|
5
|
+
module Extensions
|
|
6
|
+
# Hand-written additions to {PaystackSdk::Resources::Charges}, which bin/paystack-scaffold
|
|
7
|
+
# generates from Paystack's OpenAPI spec and includes this module into.
|
|
8
|
+
module Charges
|
|
9
|
+
# The provider codes Paystack documents for the `mobile_money` object.
|
|
10
|
+
#
|
|
11
|
+
# @see https://paystack.com/docs/api/charge/#create
|
|
12
|
+
# @see https://paystack.com/docs/payments/payment-channels/#mobile-money
|
|
13
|
+
MOBILE_MONEY_PROVIDERS = %w[mtn atl vod mpesa orange wave mpesa_offline mptill].freeze
|
|
14
|
+
|
|
15
|
+
# Charges a mobile money wallet: a {#create} call with a checked `mobile_money` object.
|
|
16
|
+
#
|
|
17
|
+
# Mobile money is available to businesses in Ghana, Kenya and Côte d'Ivoire. The charge usually
|
|
18
|
+
# comes back with status `pay_offline` (the customer approves it on their phone; show them
|
|
19
|
+
# `display_text` and wait for the `charge.success` webhook) or `send_otp` (collect the OTP and
|
|
20
|
+
# call {#submit_otp}).
|
|
21
|
+
#
|
|
22
|
+
# @param email [String] Customer's email address
|
|
23
|
+
# @param amount [Integer] Amount in the subunit of the currency (pesewas, cents)
|
|
24
|
+
# @param mobile_money [Hash] The wallet to charge, with symbol or string keys:
|
|
25
|
+
# `phone` (the customer's number) or, for M-PESA Till (`mptill`), `account` (the till number),
|
|
26
|
+
# and `provider`, one of {MOBILE_MONEY_PROVIDERS} in any case (sent in lowercase).
|
|
27
|
+
# @param currency [String, nil] 3-letter currency code, e.g. GHS or KES; Paystack uses your
|
|
28
|
+
# integration's currency when it is left out.
|
|
29
|
+
# @param reference [String, nil] Unique transaction reference
|
|
30
|
+
# @param metadata [Hash, nil] Custom data for your post-payment processes
|
|
31
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
32
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
33
|
+
# @see https://paystack.com/docs/payments/payment-channels/#mobile-money
|
|
34
|
+
def mobile_money(email:, amount:, mobile_money:, currency: nil, reference: nil, metadata: nil)
|
|
35
|
+
wallet = checked_mobile_money(mobile_money)
|
|
36
|
+
validate_currency!(currency: currency, name: "currency")
|
|
37
|
+
|
|
38
|
+
create(email:, amount:, currency:, reference:, metadata:, mobile_money: wallet)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
# Checks the `mobile_money` object and returns a copy with symbol keys and a lowercase provider.
|
|
44
|
+
# The caller's hash is never changed.
|
|
45
|
+
def checked_mobile_money(details)
|
|
46
|
+
validate_presence!(value: details, name: "mobile_money")
|
|
47
|
+
validate_hash!(input: details, name: "mobile_money")
|
|
48
|
+
|
|
49
|
+
wallet = details.transform_keys(&:to_sym)
|
|
50
|
+
validate_presence!(value: wallet[:phone] || wallet[:account], name: "mobile_money phone (or account)")
|
|
51
|
+
|
|
52
|
+
provider = wallet[:provider]&.to_s&.downcase
|
|
53
|
+
validate_allowed_values!(
|
|
54
|
+
value: provider,
|
|
55
|
+
allowed_values: MOBILE_MONEY_PROVIDERS,
|
|
56
|
+
name: "mobile_money provider",
|
|
57
|
+
allow_nil: false
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
wallet.merge(provider: provider)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
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 Miscellaneous`. Hand-written extras go in lib/paystack_sdk/resources/extensions/miscellaneous.rb.
|
|
5
|
+
# scaffold-digest: 8e7d4c28f7e3c3f3baf040728f045e40db76fde00fb4b14a38b64ea234035f27
|
|
6
|
+
|
|
7
|
+
require_relative "base"
|
|
8
|
+
|
|
9
|
+
module PaystackSdk
|
|
10
|
+
module Resources
|
|
11
|
+
# Miscellaneous operations.
|
|
12
|
+
class Miscellaneous < PaystackSdk::Resources::Base
|
|
13
|
+
# Ruby keyword => the parameter name Paystack documents.
|
|
14
|
+
WIRE_NAMES = {}.freeze
|
|
15
|
+
|
|
16
|
+
# Resolve Card BIN.
|
|
17
|
+
#
|
|
18
|
+
# Get the details of a card BIN
|
|
19
|
+
#
|
|
20
|
+
# @param bin [String] The card bank identification number
|
|
21
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
22
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
23
|
+
# @see https://paystack.com/docs/api/verification/#resolve-card
|
|
24
|
+
def resolve_card_bin(bin:)
|
|
25
|
+
validate_presence!(value: bin, name: "bin")
|
|
26
|
+
|
|
27
|
+
handle_response(@connection.get("/decision/bin/#{escape_path(bin, name: "bin")}"))
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# List Countries.
|
|
31
|
+
#
|
|
32
|
+
# List all supported countries on Paystack
|
|
33
|
+
#
|
|
34
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
35
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
36
|
+
# @see https://paystack.com/docs/api/miscellaneous/#country
|
|
37
|
+
def list_countries
|
|
38
|
+
handle_response(@connection.get("/country"))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# List States (AVS).
|
|
42
|
+
#
|
|
43
|
+
# Get a list of states for a country for address verification
|
|
44
|
+
#
|
|
45
|
+
# @param country [String] The country code of the states to list.
|
|
46
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
47
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
48
|
+
# @see https://paystack.com/docs/api/miscellaneous/#avs-states
|
|
49
|
+
def list_states(country:)
|
|
50
|
+
validate_presence!(value: country, name: "country")
|
|
51
|
+
|
|
52
|
+
wire_query = to_wire({country:}, WIRE_NAMES)
|
|
53
|
+
|
|
54
|
+
handle_response(@connection.get("/address_verification/states", wire_query))
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|