PHP code example of itsmg / rester

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

    

itsmg / rester example snippets


$response = PayNowCreateOrder::fetch();

namespace App\Rester\PaynowPaymentGateway;

use Itsmg\Rester\Rester;
use Itsmg\Rester\Contracts\WithBaseUrl;

class PaynowPaymentGatewayBase extends Rester implements WithBaseUrl
{
    public function setBaseUrl(): string
    {
        return 'https://example-paynow.com/api/v1';
    }
}

namespace App\Rester\PaynowPaymentGateway;

use Itsmg\Rester\Rester;
use Itsmg\Rester\Contracts\WithApiRoute;

class PayNowCreateOrder extends PaynowPaymentGatewayBase implements WithApiRoute
{
    public function setApiRoute(): string
    {
        return '/create/order';
    }
}

class PayNowCreateOrder extends PaynowPaymentGatewayBase implements WithApiRoute, WithDefaultPayload
{
    public function setApiRoute(): string
    {
        return '/create/order';
    }

    public function defaultPayload(): array
    {
       return [ 
         'user_id' => 'itsbalamg-1606',
         'amount' => '1994.00,
         'currency' => 'USD',
       ];
    }
}

class PayNowCreateOrder extends PaynowPaymentGatewayBase implements WithApiRoute, WithRequestHeaders
{
    public function setApiRoute(): string
    {
        return '/create/order';
    }

    public function defaultRequestHeaders(): array
    {
       return [ 
         'Content-Type' => 'application/json',
         'Authorization' => 'Bearer ' . PayNowAuthToken::fetch()
       ];
    }
}

$response = PayNowCreateOrder::withPayload(['secret-key' => 'xxxxxxx'])
           ->send()
           ->get();

$response = PayNowCreateOrder::withHeaders(['Content-Type' => 'application/json'])
           ->send()
           ->get();

class PayNowCreateOrder extends PaynowPaymentGatewayBase implements WithApiRoute, PayloadInterceptor
{
    public function setApiRoute(): string
    {
        return '/create/order';
    }

    public function interceptPayload($payload): array
    {
       $this->exampleValidator($payload);

       return [ 
         'encrypted-data' => $this->exampleEncryptionLogic($payload)
       ];
    }
}

class PayNowCreateOrder extends PaynowPaymentGatewayBase implements WithApiRoute
{
    protected bool $log = true;

    public function setApiRoute(): string
    {
        return '/create/order';
    }
}
bash
php artisan rester:create --group=PaynowPaymentGateway --api-name=PayNowCreateOrder