PHP code example of rebel / rebel-rebelpay

1. Go to this page and download the library: Download rebel/rebel-rebelpay library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rebel / rebel-rebelpay example snippets


php artisan rebel-rebelpay:install

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

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

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

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

$rebelPay = new Rebel\RebelPay();
echo $rebelPay->echoPhrase('Hello, Rebel!');



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' => '.
         * 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" => "[email protected]",
            "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);
    }


}


bash
php artisan vendor:publish --tag="rebel-rebelpay-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="rebel-rebelpay-config"
bash
php artisan vendor:publish --tag="rebel-rebelpay-views"