PHP code example of kipolaboratory / kipo-kpg

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

    

kipolaboratory / kipo-kpg example snippets


use kipolaboratory\KipoPay\KipoKPG;

/**
 * Initial Kipo Library and craete object from that class
 * Merchant key is merchant phone number
 */
$kipo = new KipoKPG(['merchant_key' => '09*********']);

/**
 * Replace "YOUR CALLBACK URL" and "AMOUNT" with what you want
 * KPGInitiate return ARRAY for result
 * Successful - ['status' => true, 'shopping_key' => SHOPING_KEY]
 * Failed - ['status' => false, 'message' => ERROR_MESAGE, 'code' => ERROR_CODE]
 */
$kpg_initiate = $kipo->KPGInitiate(AMOUNT, 'YOUR CALLBACK URL');

if ($kpg_initiate['status']) {
    /**
     * Store $kpg_initiate['shopping_key'] to session to verfiy
     * payment after user came back from gateway
     *
     * Call renderForm function to render a html form and send
     * user to Kipo KPG Gateway (you can create this form manually
     * where you want - form example is at the end of Quick Start
     */
     $kipo->renderForm($kpg_initiate['shopping_key']);
} else {
    /**
     * Show error to user
     *
     * You can call getErrorMessage and send error code to that
     * and get error message
     * $kipo->getErrorMessage(ERROR_CODE)
     */
}

/**
 * Replace "SHOPPING_KEY" with your SHOPPING_KEY that you taken from
 * Initiate function
 *
 * KPGInquery return ARRAY for result
 * Successful - ['status' => true, 'referent_code' => REFERENT_CODE, 'amount' => PAYMENT_AMOUNT]
 * Failed - ['status' => false, 'message' => ERROR_MESAGE, 'code' => ERROR_CODE]
 */
$kpg_inquery = $kipo->KPGInquery(SHOPPING_KEY);

// Get shopping key after KPGInitiate called
$curl->getShoppingKey();

// Get referent code after KPGInquery called
$curl->getReferentCode();

// URL of Kipo KPG - https://webgate.kipopay.com/
// Shopping key must post to this url with SK name
$kipo->kipo_webgate_url;