PHP code example of sawirricardo / midtrans-api

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

    

sawirricardo / midtrans-api example snippets


$midtransClient = \Sawirricardo\Midtrans\Midtrans::make(
    $serverKey,
    $clientKey,
    $isProduction,
    $is3ds,
    $isSanitized
);
$snapToken = $midtransClient->snap()->create(new \Sawirricardo\Midtrans\Dto\TransactionDto([
        'transaction_details' => [
            'order_id' => 'your-order-id',
            'gross_amount' => 10000,
        ]
    ]));

echo $snapToken->token;
echo $snapToken->redirect_url;

$transactionStatus = $midtransClient->payment()->getStatus('your-order-id-or-transaction-id');