KNET PHP SDK
by Abdullah S. Al-Salloum
|
FULL DOC |
QUICK EXAMPLE |
GET THE SDK |
$k = new KNET($c); $k->init(); $p = $k->create(array("AMOUNT" => "10.000")); // assign $p["TRACKING_ID"] to a local record $k->start();
$k = new KNET($c); $k->init(); $p = $k->listen(); /* update the local record payment status using $p["PAYMENT_STATUS"] and other variables in $p by identifying this record using $p["TRACKING_ID"]. */ $k->respond();
// Returns of listen() with invalid tokens array( "STATUS" => "success", "TRACKING_ID" => "[TRACKING_ID]", "PAYMENT_STATUS" => "failed", "DESCRIPTION" => "Unauthorized access or the gateway had technical issues processing this payment." )
require("path/to/KNET.php"); $c = array( "TRANSPORTAL_ID" => "000000", "TRANSPORTAL_PASSWORD" => "000000", "TERMINAL_RESOURCE_KEY" => "000000", "TERMINAL_URI" => "https://kpay.com.kw", "CURRENCY" => "414", "DECIMALS" => "3", "LISTEN_URI" => "https://LISTEN_URI.php", "COMPLETE_URI" => "https://COMPLETE_URI.php", "ACTION" => "1", "DEBUG" => FALSE );
include("CONFIG.php"); $k = new KNET($c); $k->init(); if($k->valid()) { $p = $k->create(array("AMOUNT" => "10.000")); if($p["STATUS"] == "success") { // assign $p["TRACKING_ID"] to a local record if(!$k->start()) { echo "Payment URI is invalid."; } } else { echo $p["DESCRIPTION"]; } } else { echo "Invalid configurations."; }
include("CONFIG.php"); $k = new KNET($c); $k->init(); if($k->valid()) { $p = $k->listen(); if($p["STATUS"] == "success") { if($p["PAYMENT_STATUS"] == "successful") { // Customer has paid } else { // Customer has not paid } /* update the local record payment status using $p["PAYMENT_STATUS"] and other variables in $p by identifying this record using $p["TRACKING_ID"]. */ $k->respond(); } else { echo $p["DESCRIPTION"]; } } else { echo "Invalid configurations."; }
require("path/to/KNET.php");
$c = array( // KNET's terminal transportal ID. "TRANSPORTAL_ID" => "000000", // KNET's terminal transportal password. "TRANSPORTAL_PASSWORD" => "000000", // KNET's terminal resource key. "TERMINAL_RESOURCE_KEY" => "000000", // KNET's terminal URI. "TERMINAL_URI" => "https://kpay.com.kw", // The currency of the transaction. "CURRENCY" => "414", // means KWD // The currency unit decimals, "3" for KWD. "DECIMALS" => "3", /* This is where you must use listen() followed by validation followed by respond(). This must be accessible over HTTPS with a valid SSL certificate. */ "LISTEN_URI" => "https://LISTEN_URI.php", /* This is the final destination where the payee will be redirected to. This should display the status of the payment based on the TRACKING_ID given in GET. HTTPS is not mandatory for this file. */ "COMPLETE_URI" => "https://COMPLETE_URI.php", // This must always be "1" "ACTION" => "1", /* Either TRUE or FALSE. If set to TRUE then you will be using a virtual gateway to test your code. Set this to false if you prefer testing with KNET directly. */ "DEBUG" => FALSE ); $k = new KNET($c);
$k->init(); /* [PARAMETERS]: VOID [RETURNS]: - On success: array( "STATUS" => "success", "DESCRIPTION" => "DESCRIPTIVE_MESSAGE" ) - On error: array( "STATUS" => "error", "DESCRIPTION" => "DESCRIPTIVE_MESSAGE" ) */
if($k->valid()) { echo "setup is valid."; } else { echo "setup is invalid."; }
$p = array( // the amount to be charged "AMOUNT" => "10.000", /* Language code of the interface you will be redirecting the payee to. */ "LANGUAGE" => "ENG", /* Any defined variable that will be retrieved after the gateway contact you in LISTEN_URI. */ "USER_DEFINED_VAR_1" => "", /* Any defined variable that will be retrieved after the gateway contact you in LISTEN_URI. */ "USER_DEFINED_VAR_2" => "", /* Any defined variable that will be retrieved after the gateway contact you in LISTEN_URI. */ "USER_DEFINED_VAR_3" => "", /* Any defined variable that will be retrieved after the gateway contact you in LISTEN_URI. */ "USER_DEFINED_VAR_4" => "" ); $k->create($p); /* [RETURNS]: - On success: array( "STATUS" => "success", "TRACKING_ID" => "UNIQUE_TRACKING_ID", "PAYMENT_URI" => "GATEWAY_PAYMENT_URI" ) - On error: array( "STATUS" => "error", "DESCRIPTION" => "ERROR_DESCRIPTION" ) */
$k->start(); /* [RETURNS]: - On success: bool(true) - On error: bool(false) */
$k->listen(); /* [RETURNS]: - On success: array( "STATUS" => "success", "PAYMENT_STATUS" => "either 'successful' or 'failed'", "DESCRIPTION" => "Descriptive status", "AMOUNT" => "The payment amount", "PAYMENT_ID" => "The payment identification number", "TRACKING_ID" => "The payment identification number", "TRANSACTION_ID" => "Gateway transaction identification number", "REFERENCE_ID" => "Gateway reference identification number", "AUTHORIZATION_ID" => "Gateway authorization identification number", "USER_DEFINED_VAR_1" => "Variable passed to create()", "USER_DEFINED_VAR_2" => "Variable passed to create()", "USER_DEFINED_VAR_3" => "Variable passed to create()", "USER_DEFINED_VAR_4" => "Variable passed to create()", "PAYMENT_TIME" => "Payment date" ) - On error: array( "STATUS" => "error", "DESCRIPTION" => "ERROR_DESCRIPTION" ) */
$k->respond(); /* [RETURNS]: - On success: REDIRECT TO "[COMPLETE_URI]?TRACKING_ID=[TRACKING_ID]" - On error: REDIRECT TO "[COMPLETE_URI]?TRACKING_ID=[TRACKING_ID]" */