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.
@@ -1,191 +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
- # The `Customers` class provides methods for interacting with the Paystack Customers API.
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
- # Creates a new customer.
35
- #
36
- # @param payload [Hash] The payload containing customer details.
37
- # @option payload [String] :email (required) Customer's email address
38
- # @option payload [String] :first_name Customer's first name
39
- # @option payload [String] :last_name Customer's last name
40
- # @option payload [String] :phone Customer's phone number
41
- # @option payload [Hash] :metadata Additional customer information
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 the payload is invalid or the API request fails.
44
- def create(payload)
45
- validate_fields!(
46
- payload: payload,
47
- validations: {
48
- email: {type: :email, required: true},
49
- first_name: {type: :string, required: false},
50
- last_name: {type: :string, required: false},
51
- phone: {type: :string, required: false}
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
- response = @connection.post("customer", payload)
56
- handle_response(response)
55
+ handle_response(@connection.get("/customer", wire_query))
57
56
  end
58
57
 
59
- # Lists all customers.
58
+ # Create Customer.
59
+ #
60
+ # Create a customer on your integration
60
61
  #
61
- # @param per_page [Integer] Number of records per page (default: 50)
62
- # @param page [Integer] Page number to retrieve (default: 1)
63
- # @param from [String] Start date for filtering
64
- # @param to [String] End date for filtering
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
- def list(per_page: 50, page: 1, **params)
68
- validate_positive_integer!(value: per_page, name: "per_page", allow_nil: true)
69
- validate_positive_integer!(value: page, name: "page", allow_nil: true)
70
-
71
- if params[:from]
72
- validate_date_format!(date_str: params[:from], name: "from")
73
- end
74
-
75
- if params[:to]
76
- validate_date_format!(date_str: params[:to], name: "to")
77
- end
78
-
79
- query_params = {perPage: per_page, page: page}.merge(params)
80
- response = @connection.get("customer", query_params)
81
- handle_response(response)
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")
73
+
74
+ wire_body = to_wire({email:, first_name:, last_name:, phone:, metadata:}, WIRE_NAMES)
75
+
76
+ handle_response(@connection.post("/customer", wire_body))
82
77
  end
83
78
 
84
- # Fetches details of a single customer by email or code.
79
+ # Fetch Customer.
85
80
  #
86
- # @param email_or_code [String] Email or customer code
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
87
84
  # @return [PaystackSdk::Response] The response from the Paystack API.
88
- # @raise [PaystackSdk::Error] If the parameter is invalid or the API request fails.
89
- def fetch(email_or_code)
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:)
90
88
  validate_presence!(value: email_or_code, name: "email_or_code")
91
- response = @connection.get("customer/#{email_or_code}")
92
- handle_response(response)
89
+
90
+ handle_response(
91
+ @connection.get("/customer/#{escape_path(email_or_code, name: "email_or_code")}")
92
+ )
93
93
  end
94
94
 
95
- # Updates a customer's details.
95
+ # Update Customer.
96
+ #
97
+ # Update a customer's details on your integration
96
98
  #
97
- # @param code [String] Customer's code
98
- # @param payload [Hash] The payload containing customer details to update
99
- # @option payload [String] :first_name Customer's first name
100
- # @option payload [String] :last_name Customer's last name
101
- # @option payload [String] :phone Customer's phone number
102
- # @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.
103
104
  # @return [PaystackSdk::Response] The response from the Paystack API.
104
- # @raise [PaystackSdk::Error] If the parameters are invalid or the API request fails.
105
- def update(code, payload)
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)
106
108
  validate_presence!(value: code, name: "code")
107
- validate_hash!(input: payload, name: "payload")
108
109
 
109
- response = @connection.put("customer/#{code}", payload)
110
- handle_response(response)
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))
111
113
  end
112
114
 
113
- # Validates a customer's identity.
114
- #
115
- # @param code [String] Customer's code
116
- # @param payload [Hash] The payload containing validation details
117
- # @option payload [String] :country (required) 2 letter country code
118
- # @option payload [String] :type (required) Type of identification
119
- # @option payload [String] :account_number Bank account number (required for bank_account type)
120
- # @option payload [String] :bvn Bank Verification Number
121
- # @option payload [String] :bank_code Bank code
122
- # @option payload [String] :first_name Customer's first name
123
- # @option payload [String] :last_name Customer's last name
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.
124
121
  # @return [PaystackSdk::Response] The response from the Paystack API.
125
- # @raise [PaystackSdk::Error] If the parameters are invalid or the API request fails.
126
- def validate(code, payload)
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))
135
+ end
136
+
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.
151
+ # @return [PaystackSdk::Response] The response from the Paystack API.
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
+ )
127
166
  validate_presence!(value: code, name: "code")
128
- validate_fields!(
129
- payload: payload,
130
- validations: {
131
- country: {type: :string, required: true},
132
- type: {type: :string, required: true},
133
- account_number: {type: :string, required: true},
134
- bank_code: {type: :string, required: true}
135
- }
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
136
188
  )
137
189
 
138
- response = @connection.post("customer/#{code}/identification", payload)
139
- handle_response(response)
190
+ handle_response(
191
+ @connection.post("/customer/#{escape_path(code, name: "code")}/identification", wire_body)
192
+ )
140
193
  end
141
194
 
142
- # Sets the risk action for a customer.
195
+ # Initialize Authorization.
196
+ #
197
+ # Initiate a request to create a reusable authorization code for recurring transactions
143
198
  #
144
- # @param payload [Hash] The payload containing risk action details
145
- # @option payload [String] :customer (required) Customer's code or email address
146
- # @option payload [String] :risk_action (required) Risk action to set ('default', 'allow', or 'deny')
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]
147
204
  # @return [PaystackSdk::Response] The response from the Paystack API.
148
- # @raise [PaystackSdk::MissingParamError] If required parameters are missing
149
- # @raise [PaystackSdk::InvalidValueError] If risk_action is not one of the allowed values
150
- # @raise [PaystackSdk::APIError] If the API request fails.
151
- #
152
- # @example
153
- # ```ruby
154
- # payload = { customer: "CUS_xxxxx", risk_action: "allow" }
155
- # response = customers.set_risk_action(payload)
156
- # if response.success?
157
- # puts "Risk action updated successfully"
158
- # end
159
- # ```
160
- def set_risk_action(payload)
161
- validate_fields!(
162
- payload: payload,
163
- validations: {
164
- customer: {type: :string, required: true},
165
- risk_action: {type: :inclusion, required: true, allowed_values: %w[default allow deny]}
166
- }
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")
212
+
213
+ wire_body = to_wire({email:, channel:, callback_url:, account:, address:}, WIRE_NAMES)
214
+
215
+ handle_response(@connection.post("/customer/authorization/initialize", wire_body))
216
+ end
217
+
218
+ # Verify Authorization.
219
+ #
220
+ # Check the status of an authorization request
221
+ #
222
+ # @param reference [String] The reference returned in the initialization response
223
+ # @return [PaystackSdk::Response] The response from the Paystack API.
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")}")
167
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)
168
266
 
169
- response = @connection.post("customer/set_risk_action", payload)
170
- handle_response(response)
267
+ handle_response(
268
+ @connection.post("/customer/#{escape_path(id, name: "id")}/initialize-direct-debit", wire_body)
269
+ )
171
270
  end
172
271
 
173
- # Deactivates a customer's authorization.
272
+ # Direct Debit Activation Charge.
273
+ #
274
+ # Trigger an activation charge on an inactive mandate on behalf of your customer
174
275
  #
175
- # @param payload [Hash] The payload containing authorization details
176
- # @option payload [String] :authorization_code (required) Authorization code to deactivate
276
+ # @param id [Integer] The customer ID attached to the authorization
277
+ # @param authorization_id [Integer] The authorization ID gotten from the initiation response
177
278
  # @return [PaystackSdk::Response] The response from the Paystack API.
178
- # @raise [PaystackSdk::Error] If the parameters are invalid or the API request fails.
179
- def deactivate_authorization(payload)
180
- validate_fields!(
181
- payload: payload,
182
- validations: {
183
- authorization_code: {type: :string, required: true}
184
- }
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)
185
289
  )
290
+ end
186
291
 
187
- response = @connection.post("customer/deactivate_authorization", payload)
188
- handle_response(response)
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
+ )
189
306
  end
190
307
  end
191
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