https://github.com/jtad009/cakephp-paystack
A Cakephp 3.x Plugin for making paystack payments
https://github.com/jtad009/cakephp-paystack
cakephp cakephp-paystack-component cakephp-paystack-plugin cakephp-plugin paystack paystack-cakephp paystack-library paystack-php
Last synced: 9 days ago
JSON representation
A Cakephp 3.x Plugin for making paystack payments
- Host: GitHub
- URL: https://github.com/jtad009/cakephp-paystack
- Owner: jtad009
- License: mit
- Created: 2019-02-07T08:59:43.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-04-24T12:54:29.000Z (about 3 years ago)
- Last Synced: 2025-10-02T02:57:27.686Z (9 months ago)
- Topics: cakephp, cakephp-paystack-component, cakephp-paystack-plugin, cakephp-plugin, paystack, paystack-cakephp, paystack-library, paystack-php
- Language: PHP
- Size: 30.3 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cakephp-Paystack
A Cakephp 3.x Plugin for making paystack payments
Installation
PHP 5.4+ , and Composer are required.
To get the latest version of Cakephp Paystack, simply require it
Or add the following line to the require block of your composer.json file.
You'll then need to run composer install or composer update to download it and have the autoloader updated.
##General payment flow
Though there are multiple ways to pay an order, most payment gateways expect you to follow the following flow in your checkout process:
###1. The customer is redirected to the payment provider After the customer has gone through the checkout process and is ready to pay, the customer must be redirected to site of the payment provider.
The redirection is accomplished by submitting a form with some hidden fields. The form must post to the site of the payment provider. The hidden fields minimally specify the amount that must be paid, the order id and a hash.
##Usage
Open your config/path.php file and add your public key, secret key, merchant email and payment url like so:
##Simple Example on how to pay with this plugin
--Let's say a cutomer wants to pay for sms
Step 1: Include the following code into your AppController.php to load the paystack component
loadComponent('PayStack.PayStack');
$this->loadComponent('PayStack.CurlConnection');
?>
Step 2:create view using the following code
Form->create(null,['url'=>['controller'=>'as-per-requirement','action'=>'purchase-sms']]);
echo $this->Form->input('amount',['templates'=>['inputContainer'=>'
{{content}} 0 UNIT(S) Worth: Send to 0
'],'class'=>'form-control','style'=>'resize:none','maxlength'=>"290",'options'=>['500'=>'500','1000'=>'1000','1500'=>'1500','2000'=>'2000','3000'=>'3000','5000'=>'5000','7000'=>'7000','10000'=>'10000'],'empty'=>'Select amount you want to pay','id'=>'sms-amount']);
echo $this->Form->submit('PURCHASE UNITS',['class'=>'btn btn-sm btn-danger btn-block mt-2 ']);
echo $this->Form->end();
?>
Step 3: in your controller create an action, mine will be PurchaseSMS()
'SMS UNIT PURCHASE',
'first_name'=>'EXPECTED_FIRST_NAME',//name of the person paying
'email' => 'EXPECTED EMAIL', //email of the person paying
'amount' => $data['amount'].'00',
'callback_url'=>'https://skole.com.ng/phone-manager/success', //this points back to my website i choose to not use the callback on the dev dashboard of paystack you can choose otherwise
'metadata.cancel_action'=>'https://skole.com.ng/phone-manager/error',
"reference" => md5(uniqid()));
$paystackResponse = $this->PayStack->payWithPaystack($postArray); //send payment details to the paystack API
if($paystackResponse->status):
//if status is true then get refereence code for confirmation "$paystackResponse->data->reference"
//take us to the payment page to
$this->redirect($paystackResponse->data->authorization_url);
endif;
}
//Authorization url will redirect you to this function
//$routes->connect('/success/', ['controller' => 'StudentsProfiles', 'action' => 'complete']);
//I had set up a route to redirect to complete action when the callback_url above is lookedup by paystack
public function complete(){
$reference = isset($_GET['reference']) ? $_GET['reference'] : '';
if(!$reference){
die('No reference supplied');
}else{
$transactionResponse = $this->PayStack->callback($reference);
if(!$transactionResponse->status){
// there was an error from the API
$this->flash->error('API returned error: ' . $tranx->message);
}
if('success' == $transactionResponse->data->status){
// transaction was successful...
// print out reponse and use as required
debug(transactionResponse);
}
}
}
?>
##Todo
Charge Returning Customers
Add Comprehensive Tests
Implement Transaction Dashboard to see all of the transactions in your Cakephp app
List/add Customers
Create/fetch/update Payment plans
Get all transaction history
Manage Subsctiptions
Export Transactions as csv
##How can I thank you?
Why not star the github repo? I'd love the attention! Why not share the link for this repository on Twitter or HackerNews? Spread the word!
Don't forget to follow me on LinkedIn
Thanks! Israel Edet.