PHP code example of shabayek / laravel-payment

1. Go to this page and download the library: Download shabayek/laravel-payment 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/ */

    

shabayek / laravel-payment example snippets


$method_id = 1; // payment method id from the config file
$payment = Payment::via($method_id);

use Shabayek\Payment\Concerns\Billable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Billable, Notifiable;

}

    /**
     * Get the first name.
     *
     * @return string|null
     */
    public function firstNameColumn()
    {
        return $this->name; // OR $this->first_name;
    }

    /**
     * Get the billable billing relations.
     *
     * @return Model
     */
    public function billingRelation()
    {
        return $this->address_relation; // OR $this->address;
    }

$payment->customer($user);

    $items = [
        [
            "name" => "item1",
            "price" => 100,
            "quantity" => 2,
            "description" => "item1 description",
        ],
        [
            "name" => "item2",
            "price" => 200,
            "quantity" => 1,
            "description" => "item2 description",
        ],
    ];
    $payment->items($items);
    // OR By One
    $name = "item1";
    $price = 100;
    $quantity = 2; // Default 1
    $description = "item1 description"; // Default null

    $payment->addItem($name, $price, $quantity, $description);

$payment->transaction($transaction_id);

if ($payment->isOnline()) {
    $url = $payment->purchase();
}

$payment->checkoutForm(Transaction $transaction);

$payment->getErrors();
$payment->isSuccess();

$payment = $payment->pay($request);

// function array with payment status and message
// return [
//     'success' => $isSuccess,
//     'message' => $message,
//     'data' => []
// ];

$method_id = 1; // payment method id from the config file
$payment_order_id = 111; // payment order id
$payment_status = Payment::via($method_id)->verify($payment_order_id);
bash
php artisan vendor:publish --provider="Shabayek\Payment\PaymentServiceProvider" --tag=config