PHP code example of maxiewright / laravel-wipay

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

    

maxiewright / laravel-wipay example snippets


use Maxiewright\LaravelWipay\Data\WipayCheckout;
use Maxiewright\LaravelWipay\Facades\LaravelWipay as Wipay;

$response = Wipay::platformCheckout(new WipayCheckout(
    orderId: 'TS-001',
    total: '99.00',
    responseUrl: route('wipay.return'),
    customerName: 'Anita Mohammed',
    customerPhone: '+18687771111',
    customerEmail: '[email protected]',
    data: ['registration_uuid' => $registration->uuid],
))->create();

return redirect()->away($response->url());

use Maxiewright\LaravelWipay\Facades\LaravelWipay as Wipay;

Wipay::merchantCredentials()->for($shop)->upsert([
    'environment' => 'sandbox',
    'country_code' => 'TT',
    'currency' => 'TTD',
    'account_number' => $request->string('account_number'),
    'api_key' => $request->string('api_key'),
    'payment_link_url' => $request->string('payment_link_url'),
    'scan_to_pay_url' => $request->string('scan_to_pay_url'),
    'enabled' => true,
]);

use Maxiewright\LaravelWipay\Data\WipayCheckout;
use Maxiewright\LaravelWipay\Facades\LaravelWipay as Wipay;

$response = Wipay::merchantCheckout($shop, new WipayCheckout(
    orderId: 'SHOP-1001',
    total: '49.00',
    responseUrl: route('shops.wipay.return', $shop),
))->create();

return redirect()->away($response->url());

$platformLink = Wipay::platformLinks()->paymentLink();
$merchantScanToPay = Wipay::merchantLinks($shop)->scanToPay();

use Illuminate\Http\Request;
use Maxiewright\LaravelWipay\Facades\LaravelWipay as Wipay;

public function __invoke(Request $request)
{
    $result = Wipay::verifyReturn($request, [
        'order_id' => $request->input('order_id'),
        'total' => '99.00',
        'currency' => 'TTD',
    ]);

    if ($result->ok()) {
        // Mark the local order paid using $result->transactionId.
    }

    return view('payments.return', ['result' => $result]);
}

$result = Wipay::verifyReturn($request, $expected, mode: 'merchant', owner: $shop);

use Illuminate\Support\Facades\Event;
use Maxiewright\LaravelWipay\Events\WipayWebhookVerified;

Event::listen(WipayWebhookVerified::class, function (WipayWebhookVerified $event): void {
    $result = $event->result;

    // Reconcile the local payment by $result->orderId and $result->transactionId.
});

use Maxiewright\LaravelWipay\Data\WipayCheckout;
use Maxiewright\LaravelWipay\Facades\LaravelWipay as Wipay;

Wipay::fake()->checkoutUrl('https://tt.wipayfinancial.com/hosted-page/test');

$response = Wipay::platformCheckout(new WipayCheckout(
    orderId: 'TS-001',
    total: '99.00',
    responseUrl: 'https://app.test/wipay/return',
))->create();

expect($response->url())->toBe('https://tt.wipayfinancial.com/hosted-page/test');

Wipay::assertCheckoutCreated(
    fn (array $fields): bool => $fields['order_id'] === 'TS-001'
);
bash
php artisan vendor:publish --tag="wipay-config"
php artisan vendor:publish --tag="wipay-migrations"
php artisan migrate