PHP code example of sextanet / laravel-webpay

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

    

sextanet / laravel-webpay example snippets


// app/Models/YourModel.php

use SextaNet\LaravelWebpay\Traits\PayWithWebpay; // 👈 Import it

class YourModel
{
    // ...

    use HasFactory;
    
    use PayWithWebpay; // 👈 Use it!
}

// app/Models/YourModel.php

public function getBuyOrderAttribute(): string
{
    return $this->id; // Give it your custom logic
}

public function getAmountAttribute(): string
{
    return $this->price; // Give it your custom logic: Don't need to use decimals
}

public function getSessionIdAttribute(): string
{
    return md5($this->id); // Give it your custom logic
}

// In your controller or equivalent

$order = YourOrder::where('id', 1)->first();

return $order->payWithWebpay(); // 👈 Done!

LaravelWebpay::setCancelledUrl('/cancelled-page');

LaravelWebpay::setRejectedUrl('/rejected-page');


// In your controller or equivalent
$order = YourOrder::where('id', 1)->first();

// ❗️ Your order model needs to have: buy_order, session_id and amount fields
return LaravelWebpay::create($order);
bash
php artisan vendor:publish --tag="webpay-migrations"
php artisan migrate