PHP code example of johnrivera7 / filament-transbank-webpay

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

    

johnrivera7 / filament-transbank-webpay example snippets


use JohnRivera7\FilamentTransbankWebpay\FilamentTransbankWebpayPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugin(
            FilamentTransbankWebpayPlugin::make()
                ->navigationGroup('Pagos')
                ->navigationSort(40)
        );
}

use JohnRivera7\FilamentTransbankWebpay\Support\TransbankCredentials;

->plugin(
    FilamentTransbankWebpayPlugin::make()
        ->credentialsUsing(function (): TransbankCredentials {
            $cfg = /* read from your DB */;

            return TransbankCredentials::fromArray($cfg);
        })
        ->persistCredentialsUsing(function (TransbankCredentials $credentials): void {
            /* persist $credentials->toArray() */
        })
)

use JohnRivera7\FilamentTransbankWebpay\FilamentTransbankWebpayPlugin;
use JohnRivera7\FilamentTransbankWebpay\Services\WebpayPlusGateway;

$gateway = FilamentTransbankWebpayPlugin::get()->gateway();

$payment = $gateway->create(
    buyOrder: 'ORD123',
    sessionId: 'sess-1',
    amountClp: 15990,
    returnUrl: route('payments.transbank.return'),
);

return response()->view('filament-transbank-webpay::payment-redirect', [
    'url' => $payment['redirect_url'],
    'fields' => $payment['redirect_fields'], // ['token_ws' => ...]
]);

if (WebpayPlusGateway::isAbortReturn($request->all())) {
    $reason = WebpayPlusGateway::abortReason($request->all()); // aborted|timeout
}

// If token_ws is present (even alongside TBK_*), call commit:
$result = $gateway->commit($request->all());

use JohnRivera7\FilamentTransbankWebpay\Forms\Components\TransbankCredentialsSchema;

$schema->components([
    ...TransbankCredentialsSchema::make('payments.transbank'),
]);
bash
php artisan vendor:publish --tag=filament-transbank-webpay-config
php artisan vendor:publish --tag=filament-transbank-webpay-assets