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,116 @@
|
|
|
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 Refund`. Hand-written extras go in lib/paystack_sdk/resources/extensions/refunds.rb.
|
|
5
|
+
# scaffold-digest: c3b04aa2ea57cc443996cfdf4b3432aa4839b01df431c881aa247d2c97514a1b
|
|
6
|
+
|
|
7
|
+
require_relative "base"
|
|
8
|
+
|
|
9
|
+
module PaystackSdk
|
|
10
|
+
module Resources
|
|
11
|
+
# Refund operations.
|
|
12
|
+
class Refunds < PaystackSdk::Resources::Base
|
|
13
|
+
# Ruby keyword => the parameter name Paystack documents.
|
|
14
|
+
WIRE_NAMES = {per_page: "perPage", transaction_id: "transaction"}.freeze
|
|
15
|
+
|
|
16
|
+
# List Refunds.
|
|
17
|
+
#
|
|
18
|
+
# List previously created refunds
|
|
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
|
+
# @param transaction_id [Integer] The ID of the refunded transaction.
|
|
25
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
26
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
27
|
+
# @see https://paystack.com/docs/api/refund/#list
|
|
28
|
+
def list(per_page: nil, page: nil, from: nil, to: nil, transaction_id: nil)
|
|
29
|
+
validate_positive_integer!(value: per_page, name: "perPage")
|
|
30
|
+
validate_positive_integer!(value: page, name: "page")
|
|
31
|
+
|
|
32
|
+
wire_query = to_wire(
|
|
33
|
+
{
|
|
34
|
+
per_page:,
|
|
35
|
+
page:,
|
|
36
|
+
from: format_datetime(from, name: "from"),
|
|
37
|
+
to: format_datetime(to, name: "to"),
|
|
38
|
+
transaction_id:
|
|
39
|
+
},
|
|
40
|
+
WIRE_NAMES
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
handle_response(@connection.get("/refund", wire_query))
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Create Refund.
|
|
47
|
+
#
|
|
48
|
+
# Initiate a refund for a previously completed transaction
|
|
49
|
+
#
|
|
50
|
+
# @param transaction [String] The reference or ID of a previously completed transaction.
|
|
51
|
+
# @param amount [Integer] Amount to be refunded to the customer.
|
|
52
|
+
# @param currency [String] Three-letter ISO currency One of: GHS, KES, NGN, USD, ZAR.
|
|
53
|
+
# @param customer_note [String] Customer reason
|
|
54
|
+
# @param merchant_note [String] Merchant reason
|
|
55
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
56
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
57
|
+
# @see https://paystack.com/docs/api/refund/#create
|
|
58
|
+
def create(transaction:, amount: nil, currency: nil, customer_note: nil, merchant_note: nil)
|
|
59
|
+
validate_presence!(value: transaction, name: "transaction")
|
|
60
|
+
validate_positive_integer!(value: amount, name: "amount")
|
|
61
|
+
validate_allowed_values!(
|
|
62
|
+
value: currency,
|
|
63
|
+
allowed_values: %w[GHS KES NGN USD ZAR],
|
|
64
|
+
name: "currency"
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
wire_body = to_wire(
|
|
68
|
+
{
|
|
69
|
+
transaction:,
|
|
70
|
+
amount:,
|
|
71
|
+
currency:,
|
|
72
|
+
customer_note:,
|
|
73
|
+
merchant_note:
|
|
74
|
+
},
|
|
75
|
+
WIRE_NAMES
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
handle_response(@connection.post("/refund", wire_body))
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Retry Refund.
|
|
82
|
+
#
|
|
83
|
+
# Retry a refund with a `needs-attention` status by providing the bank account details of a customer.
|
|
84
|
+
#
|
|
85
|
+
# @param id [Integer] The identifier of the refund
|
|
86
|
+
# @param refund_account_details [Hash] An object that contains the customer’s account details for refund
|
|
87
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
88
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
89
|
+
# @see https://paystack.com/docs/api/refund/#retry
|
|
90
|
+
def retry_with_customer_details(id:, refund_account_details:)
|
|
91
|
+
validate_presence!(value: id, name: "id")
|
|
92
|
+
validate_presence!(value: refund_account_details, name: "refund_account_details")
|
|
93
|
+
|
|
94
|
+
wire_body = to_wire({refund_account_details:}, WIRE_NAMES)
|
|
95
|
+
|
|
96
|
+
handle_response(
|
|
97
|
+
@connection.post("/refund/retry_with_customer_details/#{escape_path(id, name: "id")}", wire_body)
|
|
98
|
+
)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Fetch Refund.
|
|
102
|
+
#
|
|
103
|
+
# Get a previously created refund
|
|
104
|
+
#
|
|
105
|
+
# @param id [Integer] The identifier of the refund
|
|
106
|
+
# @return [PaystackSdk::Response] The response from the Paystack API.
|
|
107
|
+
# @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
|
|
108
|
+
# @see https://paystack.com/docs/api/refund/#fetch
|
|
109
|
+
def fetch(id:)
|
|
110
|
+
validate_presence!(value: id, name: "id")
|
|
111
|
+
|
|
112
|
+
handle_response(@connection.get("/refund/#{escape_path(id, name: "id")}"))
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|