Skip to content

Commit 8c67456

Browse files
Merge pull request #5 from MusheAbdulHakim/main
Main
2 parents bf6d1be + 7d47d3f commit 8c67456

100 files changed

Lines changed: 3737 additions & 1092 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/formats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ jobs:
4545
- name: Coding Style Checks
4646
run: composer test:lint
4747

48-
- name: Type Checks
49-
run: composer test:types
48+
# - name: Type Checks
49+
# run: composer test:types
5050

.scrutinizer.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

.travis.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

README.md

Lines changed: 181 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,81 +12,222 @@
1212

1313

1414
------
15-
This package provides a wonderful **PHP** client that allows you to interact
16-
with [Paystack Api](https://paystack.com/docs)
17-
18-
**This SDK** is a PHP & Laravel Package, (Designed to help working with paystack api easier and faster).
19-
2015

2116
## Requirement
2217
> **Requires [Composer](https://getcomposer.org/)**
2318
> **Requires [PHP 8.2+](https://php.net/releases/)**
19+
# Paystack PHP SDK
2420

21+
A robust, fluent and object-oriented PHP SDK for the [Paystack API](https://paystack.com/docs), designed for ease of use and extensibility.
2522

23+
---
2624

27-
<a name="Installation"></a>
28-
## Installation
2925

30-
```bash
31-
composer require musheabdulhakim/paystack
32-
```
26+
## Table of Contents
3327

34-
## Basic usage
28+
* [Introduction](#introduction)
29+
* [Key Features](#key-features)
30+
* [Installation](#installation)
31+
* [Quick Start](#quick-start)
32+
* [API Reference](#api-reference)
33+
* [Extending the SDK](#extending-the-sdk)
34+
* [Contributing](#contributing)
35+
* [License](#license)
3536

36-
```php
37+
---
3738

38-
use MusheAbdulHakim\Paystack\Paystack;
39+
## Introduction
3940

40-
$paystack = Paystack::client('your-api-key');
41+
The SDK provides a comprehensive and intuitive way to interact with the [Paystack API](https://paystack.com/docs/api/). Designed with developer experience in mind, it offers a fluent, object-oriented interface to various Paystack endpoints, making payment integration seamless and efficient for your PHP applications.
4142

42-
//or
43+
This SDK supports a wide array of Paystack services, including:
4344

44-
$paystack = Paystack::client('secret-api-key','https://api.paystack.co');
45-
```
45+
* **Transactions:** Initialize, verify, list, fetch, charge authorizations, refunds, and more.
46+
* **Customers:** Manage customer records, including creation, updates, and identity validation.
47+
* **Transfers:** Facilitate single and bulk transfers to bank accounts and mobile money wallets.
48+
* **Subscriptions:** Handle recurring payments by managing plans and customer subscriptions.
49+
* **Dedicated Accounts (Virtual Accounts):** Create and manage unique bank accounts for customers.
50+
* **Transaction Splits:** Automatically divide payments among multiple recipients.
51+
* **Terminals:** Interact with physical Paystack POS devices.
52+
* **Disputes:** Manage and resolve chargebacks effectively.
53+
* **Miscellaneous:** Access general data like lists of banks, countries, and states.
4654

47-
### Example
48-
```php
55+
---
56+
57+
## Key Features
4958

59+
* **Fluent API:** Enjoy a clean and readable codebase with chained method calls (e.g., `client()->transaction()->initialize(...)`).
60+
* **Object-Oriented Design:** Paystack API endpoints are encapsulated into dedicated classes for better organization and maintainability.
61+
* **PSR-18 HTTP Client Support:** Leverage any PSR-18 compatible HTTP client for flexible and robust request handling.
62+
* **Strong Typing:** Benefits from PHP's type hints for enhanced code quality and improved IDE support.
63+
* **Extensible Architecture:** Designed for easy extension, allowing you to add custom transporters or build new API modules.
5064

51-
$customers = $paystack->customer()->list();
65+
---
5266

53-
$initialize_transaction = $paystack->transaction()->initialize([
54-
//
55-
]);
67+
## Installation
5668

69+
The easiest way to install the Paystack PHP SDK is via Composer:
5770

58-
```
71+
```bash
72+
composer require musheabdulhakim/paystack
73+
````
74+
75+
-----
5976

60-
##### Refer to the documentation [here](https://musheabdulhakim.github.io/Paystack/)
77+
## Quick Start
6178

62-
### Configuration
79+
To get started, initialize the Paystack client with your secret key. You can then immediately begin interacting with any available Paystack API endpoint.
80+
81+
#### Simple Initialization
6382

6483
```php
84+
<?php
85+
86+
require 'vendor/autoload.php';
6587
66-
'PAYSTACK_API_URI' => 'https://api.paystack.co',
88+
use MusheAbdulHakim\Paystack\Paystack;
89+
90+
// Replace with your actual Paystack secret key
91+
$secretKey = 'sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxx';
92+
93+
// Initialize the Paystack client
94+
$client = Paystack::client($secretKey);
95+
96+
// Example: Initialize a new transaction
97+
try {
98+
$response = $client->transaction()->initialize([
99+
'amount' => 500000, // Amount in kobo (e.g., NGN 5000.00)
100+
'email' => 'customer@example.com',
101+
'callback_url' => '[https://yourwebsite.com/verify-payment](https://yourwebsite.com/verify-payment)',
102+
]);
103+
104+
echo "Transaction initialized successfully! Authorization URL: " . $response['authorization_url'] . "\n";
105+
} catch (\Exception $e) {
106+
echo "Error initializing transaction: " . $e->getMessage() . "\n";
107+
}
108+
109+
// Example: List all customers
110+
try {
111+
$customers = $client->customer()->list(['perPage' => 5]);
112+
echo "Customers:\n";
113+
print_r($customers);
114+
} catch (\Exception $e) {
115+
echo "Error listing customers: " . $e->getMessage() . "\n";
116+
}
117+
118+
?>
119+
```
120+
121+
#### Advanced Initialization with Factory
67122

68-
'PAYSTACK_SECRET_KEY' => '',
123+
For more granular control over the underlying HTTP client, base URI, or default headers, use the `Paystack::factory()` method. This is useful for advanced scenarios like proxying requests, custom logging, or integrating with a specific PSR-18 client implementation (e.g., Guzzle).
69124
70-
'PAYSTACK_PUBLIC_KEY' => '',
125+
```php
126+
<?php
127+
128+
require 'vendor/autoload.php';
129+
130+
use MusheAbdulHakim\Paystack\Paystack;
131+
use Psr\Http\Client\ClientInterface;
132+
use Psr\Http\Message\RequestFactoryInterface;
133+
use Psr\Http\Message\StreamFactoryInterface;
134+
135+
// Replace with your actual Paystack secret key
136+
$secretKey = 'sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxx';
137+
138+
// Example of a dummy PSR-18 HTTP Client (replace with a real implementation like Guzzle)
139+
class MyCustomHttpClient implements ClientInterface {
140+
public function sendRequest(\Psr\Http\Message\RequestInterface $request): \Psr\Http\Message\ResponseInterface {
141+
// Dummy response for demonstration
142+
return new \GuzzleHttp\Psr7\Response(200, [], '{"status": true, "message": "Custom client response"}');
143+
}
144+
}
145+
146+
// Example of a dummy PSR-17 Request Factory
147+
class MyCustomRequestFactory implements RequestFactoryInterface {
148+
public function createRequest(string $method, \Psr\Http\Message\UriInterface|string $uri): \Psr\Http\Message\RequestInterface {
149+
return new \GuzzleHttp\Psr7\Request($method, $uri);
150+
}
151+
}
152+
153+
// Example of a dummy PSR-17 Stream Factory
154+
class MyCustomStreamFactory implements StreamFactoryInterface {
155+
public function createStream(string $content = ''): \Psr\Http\Message\StreamInterface {
156+
return \GuzzleHttp\Psr7\Utils::streamFor($content);
157+
}
158+
}
159+
160+
$client = Paystack::factory()
161+
->withSecretKey($secretKey)
162+
->withBaseUri('[https://api.paystack.com/](https://api.paystack.com/)') // Set a custom base URI
163+
->withHeaders([ // Add default headers to all requests
164+
'X-Custom-Header' => 'My-App-Identifier',
165+
'User-Agent' => 'MyCustomPaystackClient/1.0',
166+
])
167+
->withQueryParameters(['perPage' => 50]) // Add default query parameters
168+
->withHttpClient(new MyCustomHttpClient()) // Provide your custom HTTP client
169+
->withRequestFactory(new MyCustomRequestFactory()) // Provide your custom request factory
170+
->withStreamFactory(new MyCustomStreamFactory()) // Provide your custom stream factory
171+
->make();
172+
173+
// Now, all requests made through $client will use your custom configurations.
174+
try {
175+
$response = $client->miscellaneous()->banks(['country' => 'nigeria']);
176+
echo "Nigerian Banks (via custom client):\n";
177+
print_r($response);
178+
} catch (\Exception $e) {
179+
echo "Error fetching banks: " . $e->getMessage() . "\n";
180+
}
181+
182+
?>
71183
```
72184
185+
-----
73186
187+
## API Reference
74188
75-
## Contribution
189+
The SDK is structured with dedicated classes for each major Paystack API resource, providing clear and organized access to their respective methods. Click on the links below to view detailed documentation and sample code for each class.
76190
191+
* **[Apple Pay](./docs/ApplePay.md)**: Manage Apple Pay domains (register, list, unregister).
192+
* **[Bulk Charges](./docs/BulkCharge.md)**: Initiate, list, fetch, pause, and resume bulk charge operations.
193+
* **[Charges](./docs/Charge.md)**: Directly charge customers, handle authentication steps (PIN, OTP, etc.), and check pending charge status.
194+
* **[Customers](./docs/Customer.md)**: Create, list, fetch, update, validate customer details, and manage risk actions.
195+
* **[Disputes](./docs/Dispute.md)**: List, fetch, update, resolve disputes, and upload/manage evidence.
196+
* **[Integration](./docs/Integration.md)**: Fetch and update payment session timeout settings.
197+
* **[Miscellaneous](./docs/Miscellaneous.md)**: Retrieve lists of banks, countries, and states.
198+
* **[Payment Pages](./docs/PaymentPage.md)**: Create, list, fetch, update payment pages, check slug availability, and add products.
199+
* **[Payment Requests](./docs/PaymentRequest.md)**: Create, list, fetch, verify, notify, finalize, update, and archive payment requests (invoices).
200+
* **[Plans](./docs/Plan.md)**: Create, list, fetch, and update subscription plans.
201+
* **[Products](./docs/Product.md)**: Create, list, fetch, and update products.
202+
* **[Refunds](./docs/Refund.md)**: Create, list, and fetch details of refunds for transactions.
203+
* **[Settlements](./docs/Settlement.md)**: List settlements and retrieve transactions associated with them.
204+
* **[Subaccounts](./docs/SubAccount.md)**: Create, list, fetch, and update subaccounts for splitting payments.
205+
* **[Subscriptions](./docs/Subscription.md)**: Create, list, fetch, enable, disable subscriptions, and generate/send management links.
206+
* **[Terminals](./docs/Terminal.md)**: Send events to terminals, check event status, get terminal presence, list, fetch, update, commission, and decommission devices.
207+
* **[Transactions](./docs/Transaction.md)**: Initialize, verify, list, fetch transactions, charge authorizations, view timelines, get totals, export data, and perform partial debits.
208+
* **[Transaction Splits](./docs/TransactionSplit.md)**: Create, list, fetch, update transaction splits, and manage subaccounts within a split.
209+
* **[Transfers](./docs/Transfer.md)**: Initiate single and bulk transfers, finalize transfers with OTP, list, fetch, and verify status.
210+
* **[Transfer Control](./docs/TransferControl.md)**: Retrieve account balance and ledger, and manage OTP settings for transfers.
211+
* **[Transfer Recipients](./docs/TransferRecipient.md)**: Create single and bulk transfer recipients, list, fetch, update, and delete them.
212+
* **[Verifications](./docs/Verification.md)**: Resolve bank accounts, validate bank accounts, and resolve card BINs.
213+
* **[Virtual Accounts](./docs/VirtualAccount.md)**: Create, assign, list, fetch, requery, deactivate virtual accounts, manage split transactions, and retrieve bank providers.
77214
78-
🧹 Keep a modern codebase with **php-cs-fixer**:
215+
-----
79216
80-
```bash
81-
composer lint
82-
```
217+
## Extending the SDK
83218
84-
🚀 Run the entire test suite:
219+
The SDK is built with extensibility at its core. If you need to customize how HTTP requests are sent (e.g., for specific logging, advanced error handling, or integrating with a custom HTTP client not directly supported by PSR-18), you can implement your own `Transporter` and provide it to the `Factory`. This allows you to tailor the SDK's behavior to your exact needs.
85220
86-
```bash
87-
composer test
88-
```
221+
You can also easily add new API modules if Paystack introduces new endpoints not yet covered by the SDK, or if you wish to group specific functionalities into your own custom classes.
222+
223+
-----
224+
225+
## Contributing
226+
227+
We welcome contributions to the Paystack PHP SDK\! Whether it's bug reports, feature requests, or pull requests, your input is valuable. Please refer to the [CONTRIBUTING.md](./CONTRIBUTING.md) file (if available) for guidelines on how to contribute.
228+
229+
-----
89230
90-
Report all your issues [Here](https://github.com/MusheAbdulHakim/Paystack/issues)
231+
## License
91232
92-
All your pull requests are welcome :).
233+
This Paystack PHP SDK is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

0 commit comments

Comments
 (0)