rebel / rebel-rebelpay
Paystack Laravel 扩展包
v1.3.0
2023-07-27 13:59 UTC
Requires
- php: ^8.1
- illuminate/contracts: ^10.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.9
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
This package is auto-updated.
Last update: 2024-09-09 07:12:47 UTC
README
这是一个Laravel Composer扩展包,简化了在Paystack上进行支付接受的过程。
安装
您可以通过Composer安装此包
composer require rebel/rebel-rebelpay
运行此命令以发布配置文件和所有必要的文件
php artisan rebel-rebelpay:install
您可以使用以下命令发布配置文件
php artisan vendor:publish --tag="rebel-rebelpay-config"
这是发布配置文件的内容
return [ 'publickey' => env('PAYSTACK_PUBLIC_KEY'), 'secretkey' => env('PAYSTACK_SECRET_KEY'), 'paystackurl' => env('PAYSTACK_PAYMENT_URL'), 'merchantmail' => env('MERCHANT_EMAIL'), ];
特性
- 支付
- 从Paystack获取所有交易记录
- 从Paystack获取单个交易记录
- 获取所有成功的Paystack交易
- 获取所有失败的Paystack交易
- 获取所有未完成的Paystack交易
- 以CSV格式导出交易
- 获取交易历史记录
此包的工作流程
- 客户将被重定向到支付提供商的网站。
- 客户在您的网站上完成结账表单后,将数据传递给包,然后客户将被重定向到paystack以完成支付。
- 客户到达Paystack平台
- 客户重定向到网站
环境变量
PAYSTACK_PUBLIC_KEY= 插入您的Paystack公钥PAYSTACK_SECRET_KEY= 插入您的Paystack私钥PAYSTACK_PAYMENT_URL=https://api.paystack.coMERCHANT_EMAIL= kwadejeffrey@gmail.com
使用/示例
$rebelPay = new Rebel\RebelPay(); echo $rebelPay->echoPhrase('Hello, Rebel!');
<?php namespace App\Http\Controllers; use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Routing\Controller as BaseController; use Rebel\RebelPay\Facades\RebelPay; class Controller extends BaseController { public function paystackCheckout(Request $request) { //Let's validate form data $validated_data = $request->validate([ 'first_name' => 'required', 'last_name' => 'required', 'email' => 'required', 'amount' => 'required', ]); /** * Let's build our Paystack data * Always multiply amount by 100 * First, Last and phone name are optional for direct payments * callback_url is optional since we can set a default callback on Paystacks' dashboard but if we set a value for it, it'll overwrite the dashboard default value. * I personally prefer setting a value in my code * You use any of your applications web routes' name as the callback_url */ $data = [ 'email' => $validated_data->email, 'amount' => $validated_data->amount * 100, 'first_name' => $validated_data->first_name, 'last_name' => $validated_data->last_name, 'phone' => $validated_data->tel, 'callback_url' => route('callback') ]; /** * Let's call Rebelpay with the makePayment method * And let's inject the data array into the method * We'll be redirect to the paystack website to complete transaction * A json_decoded with these attributes (Status, Message and Data) is returned * Status has a value of "True" * Message has a value of "Verification successful" * The important keys to note in the data attribute is (status, reference, amount, authorization, customer, channel ) * You can deploy your code is diverse ways using these attributes * You can clear the cart from DB or simply invalidate it depending on your DB structure */ $res = RebelPay::makePayment($data); // You could do something like this if($res->data->status){ Cart::where('user_id', $user_id)->delete(); } //You could pass the status as a session return redirect('/')->with('message', $res->data->status); return view('rebelPay.pageOne'); } /** * Create a customer on Paystack * * @param array $data * * @return string JSON-encoded string representing the customer information. */ public function letsCreateACustomer() { $data = [ "email" => "customer@email.com", "first_name" => "Zero", "last_name" => "Sumthing", "phone" => "+233500005737" ]; $res = RebelPay::createCustomer($data); dd($res); } public function letsUpdateCustomer() { /** * Update customer profile * * @param array $data * @param string $id * @return string JSON-encoded string representing the customer information. */ $res = RebelPay::updateCustomer(array $data, string $id) } /** * Get a specific customer's profile from Paystack * * @param string $identifier Can be either email or customer ID * @return string JSON-encoded string representing the customer information. */ public function letsGetACustomer($identifier) { return $res = RebelPay::getClient($identifier); } /** * We'll use this function to return all our transactions from Paystack */ public function getAllTransactionsFromPaystack() { /** * By default this we'll return a status, message, data and meta attributes * The data is what we need so pass it to the blade view or vue component * This method return the 100 transactions, you can alter the number * This method holds two arguments ($perPage = 100, $page = 1) * You can adjust them as you see fit */ $res = RebelPay::getAllTransactions(); dd($res); return view('rebelPay.pageOne', [ 'transactions' => $res->data ]); } /** * We'll use this function to return all our Failed transactions from Paystack */ public function getFailedTransactionsFromPaystack() { /** * By default this we'll return a status, message, data and meta attributes * The data is what we need so pass it to the blade view or vue component * This method return the 100 transactions, you can alter the number * This method holds two arguments ($perPage = 100, $page = 1) * You can adjust them as you see fit */ $res = RebelPay::getFailedTransactions(); dd($res); return view('rebelPay.pageOne', [ 'transactions' => $res->data ]); } /** * We'll use this function to return all our successful transactions from Paystack */ public function getSuccessfulTransactionsFromPaystack() { /** * By default this we'll return a status, message, data and meta attributes * The data is what we need so pass it to the blade view or vue component * This method return the 100 transactions, you can alter the number * This method holds two arguments ($perPage = 100, $page = 1) * You can adjust them as you see fit */ $res = RebelPay::getSuccessfulTransactions(); dd($res); return view('rebelPay.pageOne', [ 'transactions' => $res->data ]); } /** * We'll use this function to return all our abandoned transactions from Paystack */ public function getAbandonedTransactionsFromPaystack() { /** * By default this we'll return a status, message, data and meta attributes * The data is what we need so pass it to the blade view or vue component * This method return the 100 transactions, you can alter the number * This method holds two arguments ($perPage = 100, $page = 1) * You can adjust them as you see fit */ $res = RebelPay::getAbandonedTransactions(); dd($res); return view('rebelPay.pageOne', [ 'transactions' => $res->data ]); } /** * Method to get a targeted transaction from Paystack */ public function getTransactionFromPaystack(int $id) { /** * Pass the transaction id as an argument * e.g 2749916096 */ $res = RebelPay::getTransaction($id); } }
测试
composer test
变更日志
有关最近更改的更多信息,请参阅变更日志。
贡献
有关详细信息,请参阅贡献。
安全漏洞
有关如何报告安全漏洞的信息,请参阅我们的安全策略。
致谢
许可
MIT许可(MIT)。有关更多信息,请参阅许可文件。