Skip to content

Commit d04d6a3

Browse files
committed
Adds Verification resource with validation and regression tests
Introduces a new Verification resource supporting functionality for resolving bank accounts, card BINs, and account validation with required and optional fields. Registers the Verification resource in the main client for streamlined access and implements regression tests to ensure reliability of all methods. Also fixes an incorrect link in the banks API and updates the SDK version to 0.0.9.
1 parent 3bd89d5 commit d04d6a3

File tree

5 files changed

+157
-1
lines changed

5 files changed

+157
-1
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Changelog
22

3+
## [0.0.9] - 2025-06-26
4+
5+
### Added
6+
7+
- Verification resource with support for:
8+
- Resolving bank accounts
9+
- Resolving card BINs
10+
- Validating accounts (with required and optional fields)
11+
- Registered `verification` resource in the main client for easy access
12+
- Regression tests for all Verification resource methods, including required field validation and full parameter support
13+
14+
### Changed
15+
16+
- Fix the link for listing banks API
17+
318
## [0.0.8] - 2025-06-26
419

520
### Added

lib/paystack_sdk/client.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
require_relative "resources/transfer_recipients"
66
require_relative "resources/transfers"
77
require_relative "resources/banks"
8+
require_relative "resources/verification"
89
require_relative "utils/connection_utils"
910

1011
module PaystackSdk
@@ -106,5 +107,19 @@ def transfers
106107
def banks
107108
@banks ||= Resources::Banks.new(@connection)
108109
end
110+
111+
# Provides access to the `Verification` resource.
112+
#
113+
# @return [PaystackSdk::Resources::Verification] An instance of the
114+
# `Verification` resource.
115+
#
116+
# @example
117+
# ```ruby
118+
# verification = client.verification
119+
# response = verification.resolve_account(account_number: ..., bank_code: ...)
120+
# ```
121+
def verification
122+
@verification ||= Resources::Verification.new(@connection)
123+
end
109124
end
110125
end
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
require_relative "../validations"
2+
require_relative "base"
3+
4+
module PaystackSdk
5+
module Resources
6+
class Verification < Base
7+
# Resolve Bank Account
8+
# @see https://paystack.com/docs/api/verification/#resolve-bank-account
9+
def resolve_account(account_number:, bank_code:)
10+
validate_presence!(value: account_number, name: "account_number")
11+
validate_presence!(value: bank_code, name: "bank_code")
12+
handle_response(@connection.get("/bank/resolve", {account_number: account_number, bank_code: bank_code}))
13+
end
14+
15+
# Resolve Card BIN
16+
# @see https://paystack.com/docs/api/verification/#resolve-card-bin
17+
def resolve_card_bin(bin)
18+
validate_presence!(value: bin, name: "bin")
19+
handle_response(@connection.get("/decision/bin/#{bin}"))
20+
end
21+
22+
# Validate Account
23+
# @see https://paystack.com/docs/api/verification/#validate-account
24+
# Required: account_number, account_name, account_type, bank_code, country_code, document_type
25+
# Optional: document_number
26+
def validate_account(params)
27+
validate_required_params!(
28+
payload: params,
29+
required_params: %i[account_number account_name account_type bank_code country_code document_type],
30+
operation_name: "Validate Account"
31+
)
32+
handle_response(@connection.post("/bank/validate", params))
33+
end
34+
end
35+
end
36+
end

lib/paystack_sdk/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module PaystackSdk
4-
VERSION = "0.0.8"
4+
VERSION = "0.0.9"
55
end
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe PaystackSdk::Resources::Verification do
4+
let(:connection) { instance_double("PaystackSdk::Connection") }
5+
let(:verification) { described_class.new(connection) }
6+
7+
describe "#resolve_account" do
8+
it "resolves a bank account and wraps response" do
9+
response_double = double("Response", success?: true)
10+
expect(connection).to receive(:get)
11+
.with("/bank/resolve", {account_number: "0001234567", bank_code: "058"})
12+
.and_return(response_double)
13+
expect(PaystackSdk::Response).to receive(:new).with(response_double)
14+
verification.resolve_account(account_number: "0001234567", bank_code: "058")
15+
end
16+
17+
it "raises error for missing account_number" do
18+
expect {
19+
verification.resolve_account(account_number: nil, bank_code: "058")
20+
}.to raise_error(PaystackSdk::MissingParamError, /account_number/)
21+
end
22+
23+
it "raises error for missing bank_code" do
24+
expect {
25+
verification.resolve_account(account_number: "0001234567", bank_code: nil)
26+
}.to raise_error(PaystackSdk::MissingParamError, /bank_code/)
27+
end
28+
end
29+
30+
describe "#resolve_card_bin" do
31+
it "resolves a card bin and wraps response" do
32+
response_double = double("Response", success?: true)
33+
expect(connection).to receive(:get)
34+
.with("/decision/bin/539983")
35+
.and_return(response_double)
36+
expect(PaystackSdk::Response).to receive(:new).with(response_double)
37+
verification.resolve_card_bin("539983")
38+
end
39+
40+
it "raises error for missing bin" do
41+
expect {
42+
verification.resolve_card_bin(nil)
43+
}.to raise_error(PaystackSdk::MissingParamError, /bin/)
44+
end
45+
end
46+
47+
describe "#validate_account" do
48+
let(:required_params) do
49+
{
50+
account_number: "0001234567",
51+
account_name: "Jane Doe",
52+
account_type: "personal",
53+
bank_code: "058",
54+
country_code: "NG",
55+
document_type: "identityNumber"
56+
}
57+
end
58+
59+
it "validates an account and wraps response" do
60+
response_double = double("Response", success?: true)
61+
expect(connection).to receive(:post)
62+
.with("/bank/validate", required_params)
63+
.and_return(response_double)
64+
expect(PaystackSdk::Response).to receive(:new).with(response_double)
65+
verification.validate_account(required_params)
66+
end
67+
68+
it "raises error for missing required fields" do
69+
%i[account_number account_name account_type bank_code country_code document_type].each do |field|
70+
params = required_params.dup
71+
params.delete(field)
72+
expect {
73+
verification.validate_account(params)
74+
}.to raise_error(PaystackSdk::MissingParamError, /#{field}/)
75+
end
76+
end
77+
78+
it "validates an account with all params and wraps response" do
79+
all_params = required_params.merge(
80+
document_number: "1234567890123"
81+
)
82+
response_double = double("Response", success?: true)
83+
expect(connection).to receive(:post)
84+
.with("/bank/validate", all_params)
85+
.and_return(response_double)
86+
expect(PaystackSdk::Response).to receive(:new).with(response_double)
87+
verification.validate_account(all_params)
88+
end
89+
end
90+
end

0 commit comments

Comments
 (0)