PHP code example of zerosdev / paylabs-sdk-php

1. Go to this page and download the library: Download zerosdev/paylabs-sdk-php 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/ */

    

zerosdev / paylabs-sdk-php example snippets




erosDev\Paylabs\Client as PaylabsClient;
use ZerosDev\Paylabs\Support\Constant;
use ZerosDev\Paylabs\VirtualAccount;

$merchantId = '12345';
$apiKey = 'd1cfd***********888ed3';
$mode = Constant::MODE_DEVELOPMENT;
$guzzleOptions = []; // Your additional Guzzle options (https://docs.guzzlephp.org/en/stable/request-options.html)

$client = new PaylabsClient($merchantId, $apiKey, $mode, $guzzleOptions);
$va = new VirtualAccount($client);

$result = $va->create([
    'paymentType' => 'SinarmasVA',
    'amount' => 10000,
    'merchantTradeNo' => uniqid(),
    'notifyUrl' => 'https://yourwebsite.com/payment/notify',
    'payer' => 'Customer Name',
    'goodsInfo' => 'Product Name'
]);

echo $result->getBody()->getContents();

/**
* For debugging purpose
*/
$debugs = $client->debugs();
echo json_encode($debugs, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);

composer