paystack_sdk 0.3.0 → 0.4.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 +18 -0
- data/README.md +401 -2
- data/lib/paystack_sdk/client.rb +90 -0
- data/lib/paystack_sdk/resources/apple_pay.rb +74 -0
- data/lib/paystack_sdk/resources/bulk_charges.rb +131 -0
- data/lib/paystack_sdk/resources/direct_debits.rb +61 -0
- data/lib/paystack_sdk/resources/integrations.rb +48 -0
- data/lib/paystack_sdk/resources/orders.rb +146 -0
- data/lib/paystack_sdk/resources/pages.rb +192 -0
- data/lib/paystack_sdk/resources/products.rb +167 -0
- data/lib/paystack_sdk/resources/storefronts.rb +204 -0
- data/lib/paystack_sdk/resources/terminals.rb +170 -0
- data/lib/paystack_sdk/resources/virtual_terminals.rb +186 -0
- data/lib/paystack_sdk/version.rb +1 -1
- metadata +11 -1
|
@@ -0,0 +1,131 @@
|
|
|
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 Bulk Charge`. Hand-written extras go in lib/paystack_sdk/resources/extensions/bulk_charges.rb.
|
|
5
|
+
# scaffold-digest: 37ac5fa2bfe1cd33e4f7ea6bb85671348dea9151f67bf30475dc69262c2ffbb9
|
|
6
|
+
|
|
7
|
+
require_relative "base"
|
|
8
|
+
|
|
9
|
+
module PaystackSdk
|
|
10
|
+
module Resources
|
|
11
|
+
# Bulk Charge operations.
|
|
12
|
+
class BulkCharges < PaystackSdk::Resources::Base
|
|
13
|
+
# Ruby keyword => the parameter name Paystack documents.
|
|
14
|
+
WIRE_NAMES = {per_page: "perPage"}.freeze
|
|
15
|
+
|
|
16
|
+
# List Bulk Charge Batches.
|
|
17
|
+
#
|
|
18
|
+
# List all bulk charge batches.
|
|
19
|
+
#
|
|
20
|
+
# @param per_page [Integer] Number of records to fetch per page
|
|
21
|
+
# @param page [Integer] The offset to retrieve data from
|
|
22
|
+
# @param status [String] Filter by the status of the charges One of: active, paused, complete.
|
|
23
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
24
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
25
|
+
# @see https://paystack.com/docs/api/bulk-charge/#list
|
|
26
|
+
def list_batches(per_page: nil, page: nil, status: nil)
|
|
27
|
+
validate_positive_integer!(value: per_page, name: "perPage")
|
|
28
|
+
validate_positive_integer!(value: page, name: "page")
|
|
29
|
+
validate_allowed_values!(
|
|
30
|
+
value: status,
|
|
31
|
+
allowed_values: %w[active paused complete],
|
|
32
|
+
name: "status"
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
wire_query = to_wire({per_page:, page:, status:}, WIRE_NAMES)
|
|
36
|
+
|
|
37
|
+
handle_response(@connection.get("/bulkcharge", wire_query))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Initiate Bulk Charge.
|
|
41
|
+
#
|
|
42
|
+
# Charge multiple customers in batches
|
|
43
|
+
#
|
|
44
|
+
# @param charges [Array] The request body: an array of hashes, each with authorization, amount, and optionally reference, attempt_partial_debit, at_least, metadata
|
|
45
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
46
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
47
|
+
# @see https://paystack.com/docs/api/bulk-charge/#initiate
|
|
48
|
+
def initiate(charges:)
|
|
49
|
+
validate_presence!(value: charges, name: "charges")
|
|
50
|
+
|
|
51
|
+
handle_response(@connection.post("/bulkcharge", charges))
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Fetch Bulk Charge Batch.
|
|
55
|
+
#
|
|
56
|
+
# This endpoint retrieves a specific batch code.
|
|
57
|
+
#
|
|
58
|
+
# @param id_or_code [String] The code for the charge whose batches you want to retrieve
|
|
59
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
60
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
61
|
+
# @see https://paystack.com/docs/api/bulk-charge/#fetch-batch
|
|
62
|
+
def fetch_batch(id_or_code:)
|
|
63
|
+
validate_presence!(value: id_or_code, name: "id_or_code")
|
|
64
|
+
|
|
65
|
+
handle_response(
|
|
66
|
+
@connection.get("/bulkcharge/#{escape_path(id_or_code, name: "id_or_code")}")
|
|
67
|
+
)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# List Charges in a Batch.
|
|
71
|
+
#
|
|
72
|
+
# This endpoint retrieves the charges associated with a specified batch code
|
|
73
|
+
#
|
|
74
|
+
# @param id_or_code [String] An code for the batch whose charges you want to retrieve
|
|
75
|
+
# @param per_page [Integer] Number of records to fetch per page
|
|
76
|
+
# @param page [Integer] The offset to retrieve data from
|
|
77
|
+
# @param status [String] Filter by the status of the charges One of: success, failed, pending, error, inactive_authorization.
|
|
78
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
79
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
80
|
+
# @see https://paystack.com/docs/api/bulk-charge/#fetch-charge
|
|
81
|
+
def fetch_charges(id_or_code:, per_page: nil, page: nil, status: nil)
|
|
82
|
+
validate_presence!(value: id_or_code, name: "id_or_code")
|
|
83
|
+
validate_positive_integer!(value: per_page, name: "perPage")
|
|
84
|
+
validate_positive_integer!(value: page, name: "page")
|
|
85
|
+
validate_allowed_values!(
|
|
86
|
+
value: status,
|
|
87
|
+
allowed_values: %w[success failed pending error inactive_authorization],
|
|
88
|
+
name: "status"
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
wire_query = to_wire({per_page:, page:, status:}, WIRE_NAMES)
|
|
92
|
+
|
|
93
|
+
handle_response(
|
|
94
|
+
@connection.get("/bulkcharge/#{escape_path(id_or_code, name: "id_or_code")}/charges", wire_query)
|
|
95
|
+
)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Pause Bulk Charge Batch.
|
|
99
|
+
#
|
|
100
|
+
# Pause the processing of a charge batch
|
|
101
|
+
#
|
|
102
|
+
# @param batch_code [String] The batch code for the bulk charge you want to pause
|
|
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/bulk-charge/#pause
|
|
106
|
+
def pause_batch(batch_code:)
|
|
107
|
+
validate_presence!(value: batch_code, name: "batch_code")
|
|
108
|
+
|
|
109
|
+
handle_response(
|
|
110
|
+
@connection.get("/bulkcharge/pause/#{escape_path(batch_code, name: "batch_code")}")
|
|
111
|
+
)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# Resume Bulk Charge Batch.
|
|
115
|
+
#
|
|
116
|
+
# Resume the processing of a previously paused charge batch
|
|
117
|
+
#
|
|
118
|
+
# @param batch_code [String] The batch code for the bulk charge you want to pause
|
|
119
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
120
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
121
|
+
# @see https://paystack.com/docs/api/bulk-charge/#resume
|
|
122
|
+
def resume_batch(batch_code:)
|
|
123
|
+
validate_presence!(value: batch_code, name: "batch_code")
|
|
124
|
+
|
|
125
|
+
handle_response(
|
|
126
|
+
@connection.get("/bulkcharge/resume/#{escape_path(batch_code, name: "batch_code")}")
|
|
127
|
+
)
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
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 Direct Debit`. Hand-written extras go in lib/paystack_sdk/resources/extensions/direct_debits.rb.
|
|
5
|
+
# scaffold-digest: 481405483446315741944cfcc9fecdadc3da399105e39d724083c79c03e6a510
|
|
6
|
+
|
|
7
|
+
require_relative "base"
|
|
8
|
+
|
|
9
|
+
module PaystackSdk
|
|
10
|
+
module Resources
|
|
11
|
+
# Direct Debit operations.
|
|
12
|
+
class DirectDebits < PaystackSdk::Resources::Base
|
|
13
|
+
# Ruby keyword => the parameter name Paystack documents.
|
|
14
|
+
WIRE_NAMES = {}.freeze
|
|
15
|
+
|
|
16
|
+
# Trigger Activation Charge.
|
|
17
|
+
#
|
|
18
|
+
# Trigger activation charge for specified customers
|
|
19
|
+
#
|
|
20
|
+
# @param customer_ids [Array] Array of customer IDs to trigger activation charge for
|
|
21
|
+
# @note Charges the bank accounts behind the given customers' pending mandates to activate
|
|
22
|
+
# them; in live mode this moves real money. It was not called against the test API while
|
|
23
|
+
# this method was built, so its behaviour is documented, not verified. For one customer's
|
|
24
|
+
# inactive mandate, `customers.direct_debit_activation_charge` takes an `authorization_id`
|
|
25
|
+
# instead.
|
|
26
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
27
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
28
|
+
# @see https://paystack.com/docs/api/directdebit/#activation-charge
|
|
29
|
+
def trigger_activation_charge(customer_ids:)
|
|
30
|
+
validate_presence!(value: customer_ids, name: "customer_ids")
|
|
31
|
+
|
|
32
|
+
wire_body = to_wire({customer_ids:}, WIRE_NAMES)
|
|
33
|
+
|
|
34
|
+
handle_response(@connection.put("/directdebit/activation-charge", wire_body))
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# List Mandate Authorizations.
|
|
38
|
+
#
|
|
39
|
+
# Get a list of all the direct debit mandates on your integration
|
|
40
|
+
#
|
|
41
|
+
# @param cursor [String] The cursor value of the next set of authorizations to fetch.
|
|
42
|
+
# @param status [String] Filter by the authorization status One of: pending, active, revoked.
|
|
43
|
+
# @param per_page [Integer] The number of authorizations to fetch per request
|
|
44
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
45
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
46
|
+
# @see https://paystack.com/docs/api/directdebit/#mandate-authorizations
|
|
47
|
+
def list_mandate_authorizations(cursor: nil, status: nil, per_page: nil)
|
|
48
|
+
validate_allowed_values!(
|
|
49
|
+
value: status,
|
|
50
|
+
allowed_values: %w[pending active revoked],
|
|
51
|
+
name: "status"
|
|
52
|
+
)
|
|
53
|
+
validate_positive_integer!(value: per_page, name: "per_page")
|
|
54
|
+
|
|
55
|
+
wire_query = to_wire({cursor:, status:, per_page:}, WIRE_NAMES)
|
|
56
|
+
|
|
57
|
+
handle_response(@connection.get("/directdebit/mandate-authorizations", wire_query))
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
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 Integration`. Hand-written extras go in lib/paystack_sdk/resources/extensions/integrations.rb.
|
|
5
|
+
# scaffold-digest: c66a97cf4f3ad0acac37d43be91b77b75dbe9756c9a950a6ade38570bcff1155
|
|
6
|
+
|
|
7
|
+
require_relative "base"
|
|
8
|
+
|
|
9
|
+
module PaystackSdk
|
|
10
|
+
module Resources
|
|
11
|
+
# Integration operations.
|
|
12
|
+
class Integrations < PaystackSdk::Resources::Base
|
|
13
|
+
# Ruby keyword => the parameter name Paystack documents.
|
|
14
|
+
WIRE_NAMES = {}.freeze
|
|
15
|
+
|
|
16
|
+
# Fetch Payment Session Timeout.
|
|
17
|
+
#
|
|
18
|
+
# Fetch the session timeout of a transaction
|
|
19
|
+
#
|
|
20
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
21
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
22
|
+
# @see https://paystack.com/docs/api/integration/#fetch-timeout
|
|
23
|
+
def fetch_payment_session_timeout
|
|
24
|
+
handle_response(@connection.get("/integration/payment_session_timeout"))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Update Payment Session Timeout.
|
|
28
|
+
#
|
|
29
|
+
# Update the session timeout of a transaction
|
|
30
|
+
#
|
|
31
|
+
# @param timeout [Integer] Time in seconds before a transaction becomes invalid
|
|
32
|
+
# @note Changes the payment session timeout of the whole integration (account-wide), and the
|
|
33
|
+
# setting may be shared with LIVE mode even when you call it with a test key (sk_test_). It
|
|
34
|
+
# has not been verified against the live API. Read the current value with
|
|
35
|
+
# `fetch_payment_session_timeout` first, and do not call this to try the API out.
|
|
36
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
37
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
38
|
+
# @see https://paystack.com/docs/api/integration/#update-timeout
|
|
39
|
+
def update_payment_session_timeout(timeout:)
|
|
40
|
+
validate_presence!(value: timeout, name: "timeout")
|
|
41
|
+
|
|
42
|
+
wire_body = to_wire({timeout:}, WIRE_NAMES)
|
|
43
|
+
|
|
44
|
+
handle_response(@connection.put("/integration/payment_session_timeout", wire_body))
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,146 @@
|
|
|
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 Order`. Hand-written extras go in lib/paystack_sdk/resources/extensions/orders.rb.
|
|
5
|
+
# scaffold-digest: 5f9842687d96069840a503e158175f928f772920f8a52ddf21c682e186ede2fb
|
|
6
|
+
|
|
7
|
+
require_relative "base"
|
|
8
|
+
|
|
9
|
+
module PaystackSdk
|
|
10
|
+
module Resources
|
|
11
|
+
# Order operations.
|
|
12
|
+
class Orders < PaystackSdk::Resources::Base
|
|
13
|
+
# Ruby keyword => the parameter name Paystack documents.
|
|
14
|
+
WIRE_NAMES = {per_page: "perPage"}.freeze
|
|
15
|
+
|
|
16
|
+
# List Orders.
|
|
17
|
+
#
|
|
18
|
+
# List the previously created orders
|
|
19
|
+
#
|
|
20
|
+
# @param per_page [Integer] Number of records to fetch per page
|
|
21
|
+
# @param page [Integer] The section to retrieve
|
|
22
|
+
# @param from [String] The start date
|
|
23
|
+
# @param to [String] The end date
|
|
24
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
25
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
26
|
+
# @see https://paystack.com/docs/api/order/#list
|
|
27
|
+
def list(per_page: nil, page: nil, from: nil, to: nil)
|
|
28
|
+
validate_positive_integer!(value: per_page, name: "perPage")
|
|
29
|
+
validate_positive_integer!(value: page, name: "page")
|
|
30
|
+
|
|
31
|
+
wire_query = to_wire(
|
|
32
|
+
{
|
|
33
|
+
per_page:,
|
|
34
|
+
page:,
|
|
35
|
+
from: format_datetime(from, name: "from"),
|
|
36
|
+
to: format_datetime(to, name: "to")
|
|
37
|
+
},
|
|
38
|
+
WIRE_NAMES
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
handle_response(@connection.get("/order", wire_query))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Create Order.
|
|
45
|
+
#
|
|
46
|
+
# Create an order for selected items
|
|
47
|
+
#
|
|
48
|
+
# @param email [String] The email of the customer placing the order
|
|
49
|
+
# @param first_name [String] The customer's first name
|
|
50
|
+
# @param last_name [String] The customer's last name
|
|
51
|
+
# @param phone [String] The customer's mobile number
|
|
52
|
+
# @param currency [String] Currency in which amount is set One of: GHS, KES, NGN, USD, ZAR.
|
|
53
|
+
# @param items [Array]
|
|
54
|
+
# @param shipping [Hash] The shipping details of the order
|
|
55
|
+
# @param is_gift [Boolean] A flag to indicate if the order is for someone else
|
|
56
|
+
# @param pay_for_me [Boolean] A flag to indicate if the someone else should pay for the order
|
|
57
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
58
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
59
|
+
# @see https://paystack.com/docs/api/order/#create
|
|
60
|
+
def create(
|
|
61
|
+
email:,
|
|
62
|
+
first_name:,
|
|
63
|
+
last_name:,
|
|
64
|
+
phone:,
|
|
65
|
+
currency:,
|
|
66
|
+
items:,
|
|
67
|
+
shipping:,
|
|
68
|
+
is_gift: nil,
|
|
69
|
+
pay_for_me: nil
|
|
70
|
+
)
|
|
71
|
+
validate_presence!(value: email, name: "email")
|
|
72
|
+
validate_email!(email: email, name: "email")
|
|
73
|
+
validate_presence!(value: first_name, name: "first_name")
|
|
74
|
+
validate_presence!(value: last_name, name: "last_name")
|
|
75
|
+
validate_presence!(value: phone, name: "phone")
|
|
76
|
+
validate_presence!(value: currency, name: "currency")
|
|
77
|
+
validate_allowed_values!(
|
|
78
|
+
value: currency,
|
|
79
|
+
allowed_values: %w[GHS KES NGN USD ZAR],
|
|
80
|
+
name: "currency"
|
|
81
|
+
)
|
|
82
|
+
validate_presence!(value: items, name: "items")
|
|
83
|
+
validate_presence!(value: shipping, name: "shipping")
|
|
84
|
+
|
|
85
|
+
wire_body = to_wire(
|
|
86
|
+
{
|
|
87
|
+
email:,
|
|
88
|
+
first_name:,
|
|
89
|
+
last_name:,
|
|
90
|
+
phone:,
|
|
91
|
+
currency:,
|
|
92
|
+
items:,
|
|
93
|
+
shipping:,
|
|
94
|
+
is_gift:,
|
|
95
|
+
pay_for_me:
|
|
96
|
+
},
|
|
97
|
+
WIRE_NAMES
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
handle_response(@connection.post("/order", wire_body))
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Fetch Order.
|
|
104
|
+
#
|
|
105
|
+
# Fetch the details of a previously created order
|
|
106
|
+
#
|
|
107
|
+
# @param id [Integer] The unique identifier of the order
|
|
108
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
109
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
110
|
+
# @see https://paystack.com/docs/api/order/#fetch
|
|
111
|
+
def fetch(id:)
|
|
112
|
+
validate_presence!(value: id, name: "id")
|
|
113
|
+
|
|
114
|
+
handle_response(@connection.get("/order/#{escape_path(id, name: "id")}"))
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Fetch Product Orders.
|
|
118
|
+
#
|
|
119
|
+
# Fetch all orders for a particular product
|
|
120
|
+
#
|
|
121
|
+
# @param id [Integer] The unique identifier of the order
|
|
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/order/#fetch-product-orders
|
|
125
|
+
def fetch_product_orders(id:)
|
|
126
|
+
validate_presence!(value: id, name: "id")
|
|
127
|
+
|
|
128
|
+
handle_response(@connection.get("/order/product/#{escape_path(id, name: "id")}"))
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# Validate Order.
|
|
132
|
+
#
|
|
133
|
+
# Validate a pay for me order
|
|
134
|
+
#
|
|
135
|
+
# @param code [String] The unique code of a previously created order
|
|
136
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
137
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
138
|
+
# @see https://paystack.com/docs/api/order/#validate
|
|
139
|
+
def validate(code:)
|
|
140
|
+
validate_presence!(value: code, name: "code")
|
|
141
|
+
|
|
142
|
+
handle_response(@connection.get("/order/#{escape_path(code, name: "code")}/validate"))
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
@@ -0,0 +1,192 @@
|
|
|
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 Page`. Hand-written extras go in lib/paystack_sdk/resources/extensions/pages.rb.
|
|
5
|
+
# scaffold-digest: f15b7bfc076c2ac6bb204df7507b0749dc9129df3b73b6317943835374ffb891
|
|
6
|
+
|
|
7
|
+
require_relative "base"
|
|
8
|
+
|
|
9
|
+
module PaystackSdk
|
|
10
|
+
module Resources
|
|
11
|
+
# Page operations.
|
|
12
|
+
class Pages < PaystackSdk::Resources::Base
|
|
13
|
+
# Ruby keyword => the parameter name Paystack documents.
|
|
14
|
+
WIRE_NAMES = {per_page: "perPage"}.freeze
|
|
15
|
+
|
|
16
|
+
# List Pages.
|
|
17
|
+
#
|
|
18
|
+
# List all previously created payment pages
|
|
19
|
+
#
|
|
20
|
+
# @param per_page [Integer] Number of records to fetch per page
|
|
21
|
+
# @param page [Integer] The section to retrieve
|
|
22
|
+
# @param from [String] The start date
|
|
23
|
+
# @param to [String] The end date
|
|
24
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
25
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
26
|
+
# @see https://paystack.com/docs/api/page/#list
|
|
27
|
+
def list(per_page: nil, page: nil, from: nil, to: nil)
|
|
28
|
+
validate_positive_integer!(value: per_page, name: "perPage")
|
|
29
|
+
validate_positive_integer!(value: page, name: "page")
|
|
30
|
+
|
|
31
|
+
wire_query = to_wire(
|
|
32
|
+
{
|
|
33
|
+
per_page:,
|
|
34
|
+
page:,
|
|
35
|
+
from: format_datetime(from, name: "from"),
|
|
36
|
+
to: format_datetime(to, name: "to")
|
|
37
|
+
},
|
|
38
|
+
WIRE_NAMES
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
handle_response(@connection.get("/page", wire_query))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Create Page.
|
|
45
|
+
#
|
|
46
|
+
# Create a webpage to receive payments
|
|
47
|
+
#
|
|
48
|
+
# @param name [String] Name of page
|
|
49
|
+
# @param description [String] The description of the page
|
|
50
|
+
# @param amount [Integer] Amount should be in kobo if currency is NGN, pesewas, if currency is GHS, and cents, if currency is ZAR
|
|
51
|
+
# @param currency [String] The transaction currency. One of: NGN, GHS, ZAR, KES, USD.
|
|
52
|
+
# @param slug [String] URL slug you would like to be associated with this page.
|
|
53
|
+
# @param type [String] The type of payment page to create. One of: payment, subscription, product, plan.
|
|
54
|
+
# @param plan [String] The ID of the plan to subscribe customers on this payment page to when `type` is set to `subscription`.
|
|
55
|
+
# @param fixed_amount [Boolean] Specifies whether to collect a fixed amount on the payment page.
|
|
56
|
+
# @param split_code [String] The split code of the transaction split.
|
|
57
|
+
# @param metadata [Hash] JSON object of custom data
|
|
58
|
+
# @param redirect_url [String] If you would like Paystack to redirect to a URL upon successful payment, specify the URL here.
|
|
59
|
+
# @param success_message [String] A success message to display to the customer after a successful transaction
|
|
60
|
+
# @param notification_email [String] An email address that will receive transaction notifications for this payment page
|
|
61
|
+
# @param collect_phone [Boolean] Specify whether to collect phone numbers on the payment page
|
|
62
|
+
# @param custom_fields [Array] If you would like to accept custom fields, specify them here.
|
|
63
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
64
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
65
|
+
# @see https://paystack.com/docs/api/page/#create
|
|
66
|
+
def create(
|
|
67
|
+
name:,
|
|
68
|
+
description: nil,
|
|
69
|
+
amount: nil,
|
|
70
|
+
currency: nil,
|
|
71
|
+
slug: nil,
|
|
72
|
+
type: nil,
|
|
73
|
+
plan: nil,
|
|
74
|
+
fixed_amount: nil,
|
|
75
|
+
split_code: nil,
|
|
76
|
+
metadata: nil,
|
|
77
|
+
redirect_url: nil,
|
|
78
|
+
success_message: nil,
|
|
79
|
+
notification_email: nil,
|
|
80
|
+
collect_phone: nil,
|
|
81
|
+
custom_fields: nil
|
|
82
|
+
)
|
|
83
|
+
validate_presence!(value: name, name: "name")
|
|
84
|
+
validate_positive_integer!(value: amount, name: "amount")
|
|
85
|
+
validate_allowed_values!(
|
|
86
|
+
value: currency,
|
|
87
|
+
allowed_values: %w[NGN GHS ZAR KES USD],
|
|
88
|
+
name: "currency"
|
|
89
|
+
)
|
|
90
|
+
validate_allowed_values!(
|
|
91
|
+
value: type,
|
|
92
|
+
allowed_values: %w[payment subscription product plan],
|
|
93
|
+
name: "type"
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
wire_body = to_wire(
|
|
97
|
+
{
|
|
98
|
+
name:,
|
|
99
|
+
description:,
|
|
100
|
+
amount:,
|
|
101
|
+
currency:,
|
|
102
|
+
slug:,
|
|
103
|
+
type:,
|
|
104
|
+
plan:,
|
|
105
|
+
fixed_amount:,
|
|
106
|
+
split_code:,
|
|
107
|
+
metadata:,
|
|
108
|
+
redirect_url:,
|
|
109
|
+
success_message:,
|
|
110
|
+
notification_email:,
|
|
111
|
+
collect_phone:,
|
|
112
|
+
custom_fields:
|
|
113
|
+
},
|
|
114
|
+
WIRE_NAMES
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
handle_response(@connection.post("/page", wire_body))
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# Fetch Page.
|
|
121
|
+
#
|
|
122
|
+
# Get a previously created payment page
|
|
123
|
+
#
|
|
124
|
+
# @param id_or_slug [String] The unique identifier of a payment page
|
|
125
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
126
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
127
|
+
# @see https://paystack.com/docs/api/page/#fetch
|
|
128
|
+
def fetch(id_or_slug:)
|
|
129
|
+
validate_presence!(value: id_or_slug, name: "id_or_slug")
|
|
130
|
+
|
|
131
|
+
handle_response(@connection.get("/page/#{escape_path(id_or_slug, name: "id_or_slug")}"))
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Update Page.
|
|
135
|
+
#
|
|
136
|
+
# Update a previously created payment page
|
|
137
|
+
#
|
|
138
|
+
# @param id_or_slug [String] The unique identifier of a payment page
|
|
139
|
+
# @param name [String] Name of page
|
|
140
|
+
# @param description [String] The description of the page
|
|
141
|
+
# @param amount [Integer] Amount should be in the subunit of the currency
|
|
142
|
+
# @param active [Boolean] Set to false to deactivate page url
|
|
143
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
144
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
145
|
+
# @see https://paystack.com/docs/api/page/#update
|
|
146
|
+
def update(id_or_slug:, name: nil, description: nil, amount: nil, active: nil)
|
|
147
|
+
validate_presence!(value: id_or_slug, name: "id_or_slug")
|
|
148
|
+
validate_positive_integer!(value: amount, name: "amount")
|
|
149
|
+
|
|
150
|
+
wire_body = to_wire({name:, description:, amount:, active:}, WIRE_NAMES)
|
|
151
|
+
|
|
152
|
+
handle_response(
|
|
153
|
+
@connection.put("/page/#{escape_path(id_or_slug, name: "id_or_slug")}", wire_body)
|
|
154
|
+
)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# Check Slug Availability.
|
|
158
|
+
#
|
|
159
|
+
# Check if a custom slug is available for use when creating a payment page
|
|
160
|
+
#
|
|
161
|
+
# @param slug [String] The custom slug to check
|
|
162
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
163
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
164
|
+
# @see https://paystack.com/docs/api/page/#check-slug
|
|
165
|
+
def check_slug_availability(slug:)
|
|
166
|
+
validate_presence!(value: slug, name: "slug")
|
|
167
|
+
|
|
168
|
+
handle_response(
|
|
169
|
+
@connection.get("/page/check_slug_availability/#{escape_path(slug, name: "slug")}")
|
|
170
|
+
)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
# Add Products.
|
|
174
|
+
#
|
|
175
|
+
# Add products to a previously created payment page.
|
|
176
|
+
#
|
|
177
|
+
# @param id [Integer]
|
|
178
|
+
# @param products [Array] A list of IDs of products to add to a page.
|
|
179
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
180
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
181
|
+
# @see https://paystack.com/docs/api/page/#add-products
|
|
182
|
+
def add_products(id:, products:)
|
|
183
|
+
validate_presence!(value: id, name: "id")
|
|
184
|
+
validate_presence!(value: products, name: "products")
|
|
185
|
+
|
|
186
|
+
wire_body = to_wire({products:}, WIRE_NAMES)
|
|
187
|
+
|
|
188
|
+
handle_response(@connection.post("/page/#{escape_path(id, name: "id")}/product", wire_body))
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
end
|