定制 rebel/rebel-rebelpay 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

rebel/rebel-rebelpay

Composer 安装命令:

composer require rebel/rebel-rebelpay

包简介

Paystack Laravel package

README 文档

README

Latest Version on Packagist

Total Downloads

This is a Laravel composer package that simplifies accepting payments on Paystack.

Installation

You can install the package via composer:

composer require rebel/rebel-rebelpay

Run this command to publish the config file and all necessary files:

php artisan rebel-rebelpay:install

You can publish the config file with:

php artisan vendor:publish --tag="rebel-rebelpay-config"

This is the contents of the published config file:

return [
    'publickey' => env('PAYSTACK_PUBLIC_KEY'),

    'secretkey' => env('PAYSTACK_SECRET_KEY'),

    'paystackurl' => env('PAYSTACK_PAYMENT_URL'),

    'merchantmail' => env('MERCHANT_EMAIL'),
];

Features

  • Payments
  • Get all transactions records from Paystack
  • Get single transaction record from Paystack
  • Fetch all successful transaction Paystack
  • Fetch all failed transaction Paystack
  • Fetch all abandoned transaction Paystack
  • Export transactions in csv format
  • Fetch transactions history

Workflow of this package

  1. The customer is redirected to the payment provider's site.
  • After customer completes the checkout form on your website, feed the package with the necessary data and the customer will be redirect to paystack to complete payment.
  1. The customer arrives on paystack platform
  • After the customer is redirected to paystack, they can choose from the available payment options based on your account settings with paystack and complete the transaction.
  1. Customer is redirect to website
  • After the customer has completed the transaction on Paystack's website, they will be redirected back to a route that we have set up in our Laravel application instead of relying on Paystack's callback webhook.

Environment Variables

  • PAYSTACK_PUBLIC_KEY= insert your Paystack public key
  • PAYSTACK_SECRET_KEY= insert your Paystack secret key
  • PAYSTACK_PAYMENT_URL=https://api.paystack.co
  • MERCHANT_EMAIL= kwadejeffrey@gmail.com

Usage/Examples

$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);
    }


}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

rebel/rebel-rebelpay 适用场景与选型建议

rebel/rebel-rebelpay 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 04 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 rebel/rebel-rebelpay 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 25
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-23