PHP code example of lloricode / laravel-paymaya-sdk

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

    

lloricode / laravel-paymaya-sdk example snippets




use Lloricode\Paymaya\PaymayaClient;
use Lloricode\Paymaya\Request\Webhook\Webhook;

return [
    'mode' => env('PAYMAYA_MODE', PaymayaClient::ENVIRONMENT_SANDBOX),
    'keys' => [
        'public' => env('PAYMAYA_PUBLIC_KEY'),
        'secret' => env('PAYMAYA_SECRET_KEY'),
    ],

    /**
     *
     * Webhooks
     *
     */
    'webhooks' => [
        Webhook::CHECKOUT_SUCCESS => 'api/payment-callback/paymaya/success',
        Webhook::CHECKOUT_FAILURE => 'api/payment-callback/paymaya/failure',
        Webhook::CHECKOUT_DROPOUT => 'api/payment-callback/paymaya/dropout',

//        Webhook::PAYMENT_SUCCESS => 'api/test/success',
//        Webhook::PAYMENT_EXPIRED => 'api/test/expired',
//        Webhook::PAYMENT_FAILED => 'api/test/failed',
    ],

    'checkout' => [
        'customization' => [
            'logoUrl' => 'https://image1.png',
            'iconUrl' => 'https://image2.png',
            'appleTouchIconUrl' => 'https://image3.png',
            'customTitle' => 'test paymaya sandbox title',
            'colorScheme' => '#e01c44',
            'redirectTimer'=> 3,
        ],
    ],
];

use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use PaymayaSDK;
    
    protected function fakePaymaya(array $mockResponse, &$history = [])
    {
        $mock = [];

        foreach ($mockResponse as $value) {
            $mock[] = new Response(
                $value['status'] ?? 200,
                $value['headers'] ?? [],
                json_encode($value['body'] ?? []),
            );
        }

        PaymayaSDK::client()->setHandlerStack(
            HandlerStack::create(new MockHandler($mock)),
            $history
        );
    }


    /**
     * @test
     */
    public function success_checkout() 
    {
            $paymayaID = 'test-paymaya-generated-id';
            $paymayaRedirectUrl = 'http://test-paymaya/redirect-url';

            $this->fakePaymaya(
                [
                    [
                        'body' => [
                            'checkoutId' => $paymayaID,
                            'redirectUrl' => $paymayaRedirectUrl,
                        ],
                    ],
                ]
            );
            
           // you test
           

bash
php artisan vendor:publish --provider="Lloricode\LaravelPaymaya\LaravelPaymayaServiceProvider" --tag="laravel-paymaya-sdk-config"