Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflow/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Deploy Docusaurus to GitHub Pages

on:
push:
branches:
- main

permissions:
contents: write

jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: website/package-lock.json

- name: Install dependencies
run: |
cd website
npm ci

- name: Build Docusaurus site
run: |
cd website
npm run build

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.ACCESS_TOKEN }}
publish_dir: ./docs
commit_message: "docs: automatic update via GitHub Actions"
1 change: 0 additions & 1 deletion .phpdoc/.gitignore

This file was deleted.

Empty file.
5 changes: 0 additions & 5 deletions .phpdoc/template/css/template.css.twig

This file was deleted.

Empty file.
138 changes: 104 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
# Paystack PHP SDK
[API Doc]( https://matscode.github.io/paystack-php-sdk ) | [Demo](https://github.com/matscode/paystack-php-sdk-sandbox)
[Documentation]( https://matscode.github.io/paystack-php-sdk )

Visit [matscode/paystack](https://github.com/matscode/paystack) for `v1.9.1` and below of this SDK
For version 1 of this SDK, visit [matscode/paystack](https://github.com/matscode/paystack).

### Available resources
- Transaction (`Initialize`, `List`, `Verify`)
- Bank (`List`, `Resolve account`)
- **Transaction** (`Initialize`, `List`, `Verify`, `isSuccessful`, Fluent Setters)
- **Plan** (`Create`, `List`, `Fetch`, `Update`)
- **Subscription** (`Create`, `List`, `Fetch`, `Disable`, `Enable`)
- **Miscellaneous** (`Bank`, `Country`, `Card`)

### Resource roadmap
More resources would be added in time
- `Customers`
- `Plans`
- `Subscription`
- `Transfers`
- `others...`

This SDK communicates with [Paystack API](https://paystack.com/). You need to have a paystack merchant account and paystack secret key to use this SDK.

Development is actively ongoing while releases are Stable.
<br>
If you find a BUG/Security Issue, do be kind to open an issue or email [Me](mailto:matscode@gmail.com).
If you find a BUG/Security Issue, do be kind to open an issue or [contact me](https://matsco.de).

## Requirements
- GuzzleHttp
- PHP 7.4+ / 8.x

## Installation
``` bash
composer require matscode/paystack-php-sdk
```

``` php
require_once __DIR__ . "/vendor/autoload.php";
```

### Manual
- Download the archive
- Extract into your project
Expand All @@ -49,58 +45,132 @@ $paystackSecret = 'sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$Paystack = new Paystack($paystackSecret);
```

---

## Transaction Resource
#### Initialize Charge
```php
$response = $Paystack->transaction->initialize([
'email' => 'customer.email@gmail.com',
'amount' => 500000, // amount is in kobo
'callback_url' => 'https://www.app.local/paystack/transaction/verify'
]);
'email' => 'customer.email@gmail.com',
'amount' => 500000, // amount is in kobo
'callback_url' => 'https://www.app.local/paystack/transaction/verify'
]);
```
OR
``` php
// Set data to post using this method
// Set data to post using fluent methods
$response = $Paystack->transaction
->setCallbackUrl('https://www.app.local/paystack/transaction/verify')
->setEmail('customer.email@gmail.com')
->setAmount(75000) // amount is treated in Naira while using this setAmount() method
->initialize();
->setCallbackUrl('https://www.app.local/paystack/transaction/verify')
->setEmail('customer.email@gmail.com')
->setAmount(75000) // amount is treated in kobo/pesewas
->initialize();
```
Now do a redirect to payment page (using authorization_url)
<br>
Recommended to check if `authorization_url` is set, and save your transaction reference code. useful to verify Transaction status
Recommended to check if `authorization_url` is set, and save your transaction reference code useful to verify Transaction status.

``` php
// recommend to save Transaction reference in database and do a redirect
header('Location: ' . $response->data->authorization_url);
```

#### Verifying Transaction
``` php
$reference_code = $_GET['reference']
$reference_code = $_GET['reference'];
$response = $Paystack->transaction->verify($reference_code);
```
OR
``` php
// This method does the check for you and return `(bool) true|false`
$response = $Paystack->transaction->isSuccessful($reference_code);
// This method does the check for you and returns `(bool) true|false`
$isSuccessful = $Paystack->transaction->isSuccessful($reference_code);
```

## Bank Resource
#### List Transactions
```php
$response = $Paystack->transaction->list(50, 1);
```

---

## Miscellaneous Resources

#### Get list of banks
```php
$response = $Paystack->bank->list();
// Supports optional filters such as country, perPage, use_cursor, etc.
$response = $Paystack->miscellaneous->bank->list(['country' => 'nigeria']);
```

#### Resolve account info
```php
$bank_code='0000';
$account_number='0987654321'
$response = $Paystack->bank->resolve($bank_code, $account_number);
//result: returns account information is found, throws exception otherwise
$bank_code = '063';
$account_number = '0022728151';
$response = $Paystack->miscellaneous->bank->resolve($bank_code, $account_number);
```

#### Validate account info
```php
$response = $Paystack->miscellaneous->bank->validate([
'bank_code' => '632005',
'country_code' => 'ZA',
'account_number' => '0123456789',
'account_name' => 'Ann Bron',
'account_type' => 'personal',
'document_type' => 'identityNumber',
'document_number' => '1234567890123'
]);
```

#### Get supported countries
```php
$response = $Paystack->miscellaneous->country->list();
```

#### Resolve Card Information (BIN lookup)
```php
// Shields underlying fintech complexity behind a clean method name
$response = $Paystack->miscellaneous->card->resolveInfo('539983');
```

---

## Plan Resource
#### Create a plan
```php
$response = $Paystack->plan->create([
'name' => 'Monthly Retainer',
'amount' => 500000,
'interval' => 'monthly'
]);
```

#### List, Fetch, and Update Plans
```php
$plans = $Paystack->plan->list();
$plan = $Paystack->plan->fetch('PLN_xxxxxx');
$updated = $Paystack->plan->update('PLN_xxxxxx', ['name' => 'Updated Plan Name']);
```

---

## Subscription Resource
#### Create a subscription
```php
$response = $Paystack->subscription->create([
'customer' => 'CUS_xxxxxx',
'plan' => 'PLN_xxxxxx'
]);
```

#### Manage Subscriptions
```php
$subscriptions = $Paystack->subscription->list();
$subscription = $Paystack->subscription->fetch('SUB_xxxxxx');

// Enable or disable
$Paystack->subscription->disable(['code' => 'SUB_xxxxxx', 'token' => 'SUB_tokenxxx']);
$Paystack->subscription->enable(['code' => 'SUB_xxxxxx', 'token' => 'SUB_tokenxxx']);
```

---

### Contact
[Personal Home](https://inndex.page/matscode) | [Email](mailto:matscode@gmail.com)
## Author
Michael Akanji - [matsco.de](https://matsco.de)
1 change: 0 additions & 1 deletion _config.yml

This file was deleted.

10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"authors": [
{
"name": "Michael Akanji",
"email": "matscode@gmail.com",
"homepage": "https://inndex.page/matscode"
"email": "matscode@users.noreply.github.com",
"homepage": "https://matsco.de"
}
],
"keywords": [
Expand Down Expand Up @@ -35,12 +35,12 @@
"sort-packages": true
},
"require": {
"guzzlehttp/guzzle": "^7.0",
"guzzlehttp/guzzle": "^7.0 || ^8.0",
"ext-json": "*"
},
"require-dev": {
"mockery/mockery": "1.4.x-dev",
"mockery/mockery": "^1.4",
"phpunit/phpunit": "^9",
"squizlabs/php_codesniffer": "3.*"
}
}
}
Loading