matscode/paystack 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

matscode/paystack

Composer 安装命令:

composer require matscode/paystack

包简介

This package is for communicating with PAYSTACK API

README 文档

README

This currently repository development has been discontinued. Development of v2.0.0 and above has now moved to matscode/paystack-php-sdk with new improved structure, documentation, demo and overall dev experience.

TODO - RoadMap

  • Use GuzzleHttp
  • Customers
  • Plans
  • Subscription
  • Transfers
  • Charges
  • others...
This package is for communicating with PAYSTACK RESTful API. Paystack

Having other resource point available on PAYSTACK API, Resources like;

  • Transaction
  • Customers
  • Plans
  • Subscription
  • Transfers
  • Charges
  • and many more

Just to name a few, it is only the Transaction Resource that is made available currently in this package. Development is ongoing while releases are Stable. Incase you find a BUG/Security Issue, Please, do be kind to open an issue or email matscode at Gmail dot Com.
PS: This library also works for you if you use paystack inline. You just have to use the verify() method, passing in your transaction $reference|$token|$id is compulsory.

Requirements

  • Curl

Install

Via Composer

$ composer require matscode/paystack

If you use a Framework, check your documentation for how vendor packages are autoloaded else Add this to the top of your source file;

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

Making Transactions/Recieving Payment

Starting Up Paystack Transaction

use Matscode\Paystack\Transaction;
use Matscode\Paystack\Utility\Debug; // for Debugging purpose
use Matscode\Paystack\Utility\Http;

$secretKey = 'sk_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';

// creating the transaction object
$Transaction = new Transaction( $secretKey );

Initializing Transaction

Set data/payload/requestBody to post with initialize request. Minimum required data are email and amount.

// Set data to post using array
$data = 
[
    'email'  => 'customer@email.com',
    'amount' => 500000 // amount is treated in kobo using this method
];
$response = $Transaction->initialize($data);

OR

// Set data to post using this method
$response =
        $Transaction
            ->setCallbackUrl('http://michaelakanji.com') // to override/set callback_url, it can also be set on your dashboard 
            ->setEmail( 'matscode@gmail.com' )
            ->setAmount( 75000 ) // amount is treated in Naira while using this method
            ->setMetadata(['custom_field1' => 'value1', 'custom_field2' => 'value2'])
            ->initialize();

If you want to get the 200OK raw Object as it is sent by Paystack, Set the 2nd argument of the initialize() to true, example below

// Set data to post using this method
$response =
        $Transaction 
            ->setEmail( 'matscode@gmail.com' )
            ->setAmount( 75000 ) // amount is treated in Naira while using this method
            ->initialize([], true);

Now do a redirect to payment page (using authorization_url)
NOTE: Recommended to Debug $response or check if authorizationUrl is set, and save your Transaction reference code. useful to verify Transaction status

// recommend to save Transaction reference in database and do a redirect
$reference = $response->reference;
// redirect
Http::redirect($response->authorizationUrl); 

Using a Framework? It is recommended you use the reverse routing/redirection functions provided by your Framework

Verifying Transaction

This part would live in your callback file i.e callback.php or whatsoever_you_name.php
It is also imperative that you create Transaction Obj once more.
This method would return the Transaction Obj but false if saved $reference is not passed in as argument and also cant be guessed. Using verify() would require you do a manual check on the response Obj

$response = $Transaction->verify();
// Debuging the $response
Debug::print_r( $response);

OR

// This method does the check for you and return `(bool) true|false` 
$response = $Transaction->isSuccessful();

The two methods above try to guess your Transaction $reference but it is highly recommended you pass the Transaction $reference as an argument on the method as follows

// This method does the check for you and return `(bool) true|false`
$response = $Transaction->isSuccessful($reference);

Moreso, you can also compare if amount paid by customer is the amount expected. This method only works after calling verify() or isSuccessful() in the same script. It is recommended to do this if you use paystack inline to initialize the transaction.

$amountExpected = 5000; // amount must be in kobo
// returns `(bool) true|false`
$Transaction->amountEquals($amountExpected);

Now you can process Customer Valuable.

You might wanna save Transaction $authorizationCode for the current customer subsequent Transaction but not a nessecity. It would only counts to future updates of this package or if you choose to extend the package.

// returns Auth_xxxxxxx 
$response = $Transaction->authorizationCode($reference); // can also guess Transaction $reference

Hire Me

I am available on contract if you need help integrating paystack into your Business Website or something.
Contact me via my email above - michaelakanji.com

Contributions

If you seem to understand the architecture, you are welcome to fork and pull else you can wait a bit more till when i provide convention documentation.

Licence

GNU GPLV3

matscode/paystack 适用场景与选型建议

matscode/paystack 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20.83k 次下载、GitHub Stars 达 17, 最近一次更新时间为 2017 年 06 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「payment」 「paystack」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 matscode/paystack 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 matscode/paystack 我们能提供哪些服务?
定制开发 / 二次开发

基于 matscode/paystack 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 20.83k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 17
  • 点击次数: 17
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 17
  • Watchers: 1
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-only
  • 更新时间: 2017-06-25