PHP code example of koderpedia / labayar

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

    

koderpedia / labayar example snippets



namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Koderpedia\Labayar\Payment;
class PaymentController extends Controller
{
    public function loadSnapLabayar(Request $request)
    {
        $payment = new Payment("tripay");
        $payload = [
            "orderId" => "inv-" . time(),
            "customer" => [
                "name" => "Raga mulia kusuma",
                "email" => "[email protected]",
                "phone" => "0891234567890"
            ],
            "expiry" => [
                "unit" => "minutes",
                "duration" => 60
            ],
            "items" => [
                [
                    "productId" => "prod12345",
                    "name" => "Mangga harum manis pekanbaru",
                    "quantity" => 10,
                    "price" => 10000
                ],
                [
                    "productId" => "prod12345",
                    "name" => "Jeruk harum manis pekanbaru",
                    "quantity" => 10,
                    "price" => 10000
                ],
                [
                    "productId" => "prod12345",
                    "name" => "Strawberry harum manis pekanbaru",
                    "quantity" => 10,
                    "price" => 10000
                ],
            ]
        ];
        return $payment->UISnapLabayar($payload);
    }
}


Route::get("/snap", [PaymentController::class, "loadSnapLabayar"]);

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Koderpedia\Labayar\Payment;
class PaymentController extends Controller
{
    public function createTransaction(Request $request){
        $labayar = new Payment();
        $payload = [
            "orderId" => "inv-0007",
            "customer" => [
                "name" => "raga",
                "email" => "[email protected]",
                "phone" => "081234567890",
            ],
            "items" => [
                [
                    "productId" => "prd0001",
                    "name" => "Jambu air",
                    "quantity" => 2,
                    "price" => "20000",
                ],
                [
                    "productId" => "prd0002",
                    "name" => "Rambutan",
                    "quantity" => 2,
                    "price" => 20000,
                ],
            ],
            "expiry" => ["unit" => "minutes", "duration" => 10],
            "payAmount" => 90000,
        ];
        $transaction = $labayar->createInvoice($payload);
        return redirect("/api/labayar/orders");
    }
}

public function payInvoice(Request $request){
    $payload = [
        "paymentId" => "inv-0007-1745133149",
        "amount" => 400000,
    ];
    $payment = Payment::pay($payload);
    return $payment
}
sh
php artisan vendor:publish --provider=Koderpedia\Labayar\LabayarServiceProvider
sh
php artisan migrate
sh
php artisan db:seed --class=LabayarSeeder
sh
php artisan serve