PHP code example of ipaymu / ipaymu-php-api

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

    

ipaymu / ipaymu-php-api example snippets



use iPaymu\iPaymu;

$apiKey = 'your-apikey';
$va = 'your-va';
$production = true;

$iPaymu = new iPaymu($apiKey, $va, $production);

$balance = $iPaymu->checkBalance();

$status = $iPaymu->checkTransaction($id);

$iPaymu->setURL([
    'ureturn' => 'https://your-website/thankyou_page',
    'unotify' => 'https://your-website/notify_page',
    'ucancel' => 'https://your-website/cancel_page',
]);


$buyer = $iPaymu->setBuyer([
    'name' => 'your-name',
    'phone' => 'your-phone',
    'email' => 'your-email',
]);

$carts = [];
$carts = $iPaymu->add(
    'PROD0001', // product id (string)
    'Jacket', // product name (string)
    12000, // price (float)
    2, // quantity (int)
    'Size M', // description
    1, // product weight (int) (optional)
    1, // product length (int) (optional)
    1, // product weight (int) (optional)
    1 // product height (int) (optional)
);
$carts = $iPaymu->add(
    'PROD0002', // product id (string)
    'Shoe', // product name (string)
    150000, // price (float)
    2, // quantity (int)
    'Size 8', // description
    1, // product weight (int) (optional)
    1, // product length (int) (optional)
    1, // product weight (int) (optional)
    1 // product height (int) (optional)
);

$iPaymu->addCart($carts);

$delivery = $iPaymu->setCOD([
        'deliveryArea' => "76111",
        'deliveryAddress' => "Denpasar",
]);

// set your expiredPayment
$iPaymu->setExpired(24, 'hours'); // 24 hours

$iPaymu->setReferenceId('123123');

$iPaymu->setComments('Payment TRX01');

// set payment method
// check https://ipaymu.com/api-collection for list payment method
$iPaymu->setPaymentMethod('va');

// check https://ipaymu.com/api-collection for list payment channel
$iPaymu->setPaymentChannel('bca');

$payment = $iPaymu->directPayment();

$payment = $iPaymu->redirectPayment();

$apiKey = 'QbGcoO0Qds9sQFDmY0MWg1Tq.xtuh1'; // your api key
$va = '1179000899'; // your va
$production = true; // set false to sandbox mode

$iPaymu = new iPaymu($apiKey, $va, $production);

// set callback url
$iPaymu->setURL([
    'ureturn' => 'https://your-website/thankyou_page',
    'unotify' => 'https://your-website/notify_page',
    'ucancel' => 'https://your-website/cancel_page',
]);

// set buyer name
$iPaymu->setBuyer([
    'name' => 'Bagus',
    'phone' => '08123123139',
    'email' => '[email protected]',
]);

// set your reference id (optional)
$iPaymu->setReferenceId('123123');

// set your expiredPayment
$iPaymu->setExpired(24, 'hours'); // 24 hours

// set payment method
// check https://ipaymu.com/api-collection for list payment method
$iPaymu->setPaymentMethod('va');

// check https://ipaymu.com/api-collection for list payment channel
$iPaymu->setPaymentChannel('bca');

// payment notes (optional)
$iPaymu->setComments('Payment TRX01');

$carts = [];
$carts = $iPaymu->add(
    'PROD0001', // product id (string)
    'Jacket', // product name (string)
    12000, // price (float)
    3, // quantity (int)
    'Size M', // description
    1, // product weight (int) (optional)
    1, // product length (int) (optional)
    1, // product weight (int) (optional)
    1 // product height (int) (optional)
);
$carts = $iPaymu->add(
    'PROD0002', // product id (string)
    'Shoe', // product name (string)
    150000, // price (float)
    2, // quantity (int)
    'Size 8', // description
    1, // product weight (int) (optional)
    1, // product length (int) (optional)
    1, // product weight (int) (optional)
    1 // product height (int) (optional)
);

$iPaymu->addCart($carts);

return $iPaymu->directPayment();

$apiKey = 'QbGcoO0Qds9sQFDmY0MWg1Tq.xtuh1'; // your api key
$va = '1179000899'; // your va
$production = true; // set false to sandbox mode

$iPaymu = new iPaymu($apiKey, $va, $production);

// set callback url
$iPaymu->setURL([
    'ureturn' => 'https://your-website/thankyou_page',
    'unotify' => 'https://your-website/notify_page',
    'ucancel' => 'https://your-website/cancel_page',
]);

// set buyer name
$iPaymu->setBuyer([
    'name' => 'Bagus',
    'phone' => '08123123139',
    'email' => '[email protected]',
]);

// set your reference id (optional)
$iPaymu->setReferenceId('123123');

// set your expiredPayment
$iPaymu->setExpired(24, 'hours'); // 24 hours

// set cod param (optional)
$iPaymu->setCOD([
    'deliveryArea' => "76111",
    'deliveryAddress' => "Denpasar",
]);

$carts = [];
$carts = $iPaymu->add(
    'PROD0001', // product id (string)
    'Jacket', // product name (string)
    12000, // price (float)
    2, // quantity (int)
    'Size M', // description
    1, // product weight (int) (optional)
    1, // product length (int) (optional)
    1, // product weight (int) (optional)
    1 // product height (int) (optional)
);
$carts = $iPaymu->add(
    'PROD0002', // product id (string)
    'Shoe', // product name (string)
    150000, // price (float)
    2, // quantity (int)
    'Size 8', // description
    1, // product weight (int) (optional)
    1, // product length (int) (optional)
    1, // product weight (int) (optional)
    1 // product height (int) (optional)
);

$iPaymu->addCart($carts);

return $iPaymu->redirectPayment();

composer