diff --git a/README.md b/README.md new file mode 100644 index 0000000..787b579 --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# WHMCS DOKU HOSTED PAYMENT MODULE # + +DOKU ❤️ WHMCS ! Let your WHMCS store integrated with DOKU payment gateway. + +## Description ## + +DOKU payment gateway is an online payment gateway. We strive to make payments simple for both the merchant and customers. +With this plugin you can accept online payment on your WHMCS using DOKU payment gateway. + +### Minimum Requirements ### + +- WHMCS v7.2.3 or WHMCS v7.x +- PHP version 5.5.x or greater +- MySQL version 5.0 or greater + +### Installation ### + +1. Download the modules from this repository. +2. Extract Whmcs-master.zip file you have previously downloaded. +3. Upload & merged module folder that you have extracted into your WHMCS directory. + +## Installation & Configuration ## + +1. Access your WHMCS admin page. +2. Go to menu Setup -> Payments -> Payment Gateways. +3. Click DOKU Hosted as payment method. +4. Then choose Setup -> Payments -> Payment Gateways -> Manage Existing Gateways +5. Fill the input as instructed on the screen. +6. Click Save Changes + +#### NOTES #### + +* Please note that our this our payment modules not using `composer.json` +* Add the url on the admin panel to cron on your WHMCS hosted for check status payment process. +* In order to use this module please register at [DOKU Website](https://www.doku.com) to get an API. + +Further infornation about DOKU, please check our website on [DOKU Website](https://www.doku.com) \ No newline at end of file diff --git a/modules/gateways/.gitignore b/modules/gateways/.gitignore new file mode 100644 index 0000000..c9e8e8d --- /dev/null +++ b/modules/gateways/.gitignore @@ -0,0 +1,28 @@ +# Composer files +composer.phar +vendor/ + +# Local configs +config/autoload/*.local.php + +# Binary gettext files +*.mo + +# Data +data/logs/ +data/cache/ +data/sessions/ +data/tmp/ +temp/ + +#Doctrine 2 +data/DoctrineORMModule/Proxy/ +data/DoctrineORMModule/cache/ + + +# Legacy ZF1 +demos/ +extras/documentation + +# IGNORE .vscode +.vscode/ diff --git a/modules/gateways/callback/dokuhosted.php b/modules/gateways/callback/dokuhosted.php new file mode 100644 index 0000000..b877533 --- /dev/null +++ b/modules/gateways/callback/dokuhosted.php @@ -0,0 +1,1108 @@ +setTimezone(new DateTimeZone("Asia/Bangkok")); +if (((int)$Datezone->format('His') >= 85959) && ((int)$Datezone->format('His') <= 225959)) { + $Void_Enabled = (isset($gatewayParams['Void-Enabled']) ? $gatewayParams['Void-Enabled'] : ''); + $Void_Enabled = (!is_array($Void_Enabled) ? trim($Void_Enabled) : ''); + $Void_Enabled = ((strtolower($Void_Enabled) === strtolower('on')) ? TRUE : FALSE); +} else { + $Void_Enabled = FALSE; +} +// Constant disabled VOID +$Void_Enabled = FALSE; +//------------------------------------------------------------------------------------------------ +$LocalApiAdminUsername = (isset($gatewayParams['Local-Api-Admin-Username']) ? $gatewayParams['Local-Api-Admin-Username'] : ''); +$Log_Enabled = FALSE; +if (isset($gatewayParams['Log-Enabled'])) { + $Log_Enabled = ((strtolower($gatewayParams['Log-Enabled']) == 'on') ? TRUE : FALSE); +} +$PaymentCheck_Enabled = (isset($gatewayParams['PaymentCheck-Enabled']) ? $gatewayParams['PaymentCheck-Enabled'] : ''); +$PaymentCheck_Enabled = ((strtolower($PaymentCheck_Enabled) === strtolower('on')) ? TRUE : FALSE); +// Die if module is not active. +if (!$gatewayParams['type']) { + die("Module Not Activated"); +} +$Environment = (isset($gatewayParams['Environment']) ? $gatewayParams['Environment'] : 'sandbox'); // Let sandbox as default +$DokuConfigs = array( + 'isofile' => 'dokuhosted/assets/iso3166.json', + 'merchant' => array( + 'mallid' => (isset($gatewayParams['MallId']) ? $gatewayParams['MallId'] : ''), + 'shopname' => (isset($gatewayParams['ShopName']) ? $gatewayParams['ShopName'] : ''), + 'chainmerchant' => (isset($gatewayParams['ChainMerchant']) ? $gatewayParams['ChainMerchant'] : ''), + 'sharedkey' => (isset($gatewayParams['SharedKey']) ? $gatewayParams['SharedKey'] : ''), + ), + 'endpoint' => (is_string($Environment) ? strtolower($Environment) : 'sandbox'), // sandbox as default +); +if (class_exists('dokuhosted_DokuPayment')) { + $DokuPayment = new dokuhosted_DokuPayment($DokuConfigs); +} else { + require_once($dokulib); + $DokuPayment = new dokuhosted_DokuPayment($DokuConfigs); +} +// Getting URL Querystring +$doku_get = dokuhosted_DokuPayment::_GET(); +// Make Global @CallbackPage +$CallbackPage = (isset($doku_get['page']) ? $doku_get['page'] : 'notify'); // notify as default-callback-page +$CallbackPage = (is_string($CallbackPage) ? strtolower($CallbackPage) : 'notify'); +/* +*************************************************************************** +* +* IF IPN : $doku_ipn_params +* IF Redirect : $doku_redirect_params +* +*************************************************************************** +*/ +$REQUEST_METHOD = (isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'HEAD'); +$REQUEST_METHOD_MSG = ""; +# Get Doku IPN Params: +$doku_ipn_params = $DokuPayment->doku_incoming_callback(); +if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $doku_ipn_params, "({$REQUEST_METHOD}) Incoming Callback Params"); } +# Get Doku Redirect Params from Request-Uri +$doku_redirect_params = dokuhosted_DokuPayment::get_query_string(); +################################ +//------------------------------ +// Global Validation +$doku_error = FALSE; +$doku_error_msg = array(); +// Make GLOBAL @success +$success = FALSE; +//------------------------------ +// Make GLOBAL @checkCbTransID +$checkCbTransID = FALSE; +// Previously get 500 Internal Error for this transaction: checkCbTransID($transactionId); +// Make GLOBAL @XMLPaymentStatus +$XMLPaymentStatus = array(); +if ($EDU_Enabled > 0) { + $XMLPaymentStatus['edu-enabled'] = $EDU_Enabled; +} else { + $XMLPaymentStatus['edu-enabled'] = 0; +} +// Make GLOBAL @StringVoidStatus +$StringVoidStatus = ""; +/* +// Use localAPI to handle and redirect user +*/ +$localApi = array( + 'command' => 'GetInvoice', //'GetOrders', + 'data' => array( + //'id' => '', // Later updated on review case + 'invoiceid' => '', # Later updated on review case + ), + 'username' => $LocalApiAdminUsername, // Optional for WHMCS 7.2 and later +); +//------------------------------ +################################ +switch (strtolower($CallbackPage)) { + //------------------ + // Debug Invoice + //------------------ + case 'debug': + $invoiceId = (isset($doku_redirect_params['id']) ? $doku_redirect_params['id'] : ''); + $invoiceId = (int)$invoiceId; + $cbInvoiceId = checkCbInvoiceID($invoiceId, $gatewayParams['paymentmethod']); + if ($invoiceId) { + echo "
"; + echo "{$invoiceId}"; + echo "'; + // Create padding + $returnHtml .= '
"; + echo $cbInvoiceId; + echo "
"; + if (isset($localApi['data']['id'])) { + unset($localApi['data']['id']); + } + $data = array( + //'id' => $invoiceId, + 'invoiceid' => $invoiceId, + ); + $InvoiceData = localAPI('GetInvoice', $data, $localApi['username']); + print_r($InvoiceData); + } + exit; + break; + case 'identify': + if ($_SERVER['REQUEST_METHOD'] == 'POST') { + if (count($doku_ipn_params['body']) > 0) { + # DOKU Identify + $dokuparams = array( + 'TRANSIDMERCHANT' => (isset($doku_ipn_params['body']['TRANSIDMERCHANT']) ? $doku_ipn_params['body']['TRANSIDMERCHANT'] : ''), + 'PURCHASECURRENCY' => (isset($doku_ipn_params['body']['PURCHASECURRENCY']) ? $doku_ipn_params['body']['PURCHASECURRENCY'] : ''), + 'CURRENCY' => (isset($doku_ipn_params['body']['CURRENCY']) ? $doku_ipn_params['body']['CURRENCY'] : ''), + 'PAYMENTCHANNEL' => (isset($doku_ipn_params['body']['PAYMENTCHANNEL']) ? $doku_ipn_params['body']['PAYMENTCHANNEL'] : ''), + 'PAYMENTCODE' => (isset($doku_ipn_params['body']['PAYMENTCODE']) ? $doku_ipn_params['body']['PAYMENTCODE'] : ''), + 'AMOUNT' => (isset($doku_ipn_params['body']['AMOUNT']) ? $doku_ipn_params['body']['AMOUNT'] : ''), + 'SESSIONID' => (isset($doku_ipn_params['body']['SESSIONID']) ? $doku_ipn_params['body']['SESSIONID'] : ''), + ); + if ($Identify_Enabled) { + if ($Log_Enabled) { + logTransaction($gatewayParams['paymentmethod'], $dokuparams, "Payment Identify"); + } + } + $REQUEST_METHOD_MSG = "IDENTIFY:Continue"; + } else { + $REQUEST_METHOD_MSG = "STOP : BODY Have no content - Identify"; + } + } else { + $REQUEST_METHOD_MSG = "STOP : POST Method Required - Identify"; + } + break; + case 'review': + $dokuparams = array(); + $REQUEST_METHOD_MSG = "Review Page - Redirect to main-page"; + // Get from Querystring + $dokuparams['TRANSIDMERCHANT'] = (isset($doku_redirect_params['TRANSIDMERCHANT']) ? $doku_redirect_params['TRANSIDMERCHANT'] : ''); + // Get from Postbody + if (count($doku_ipn_params['body']) > 0) { + $dokuparams['TRANSIDMERCHANT'] = (isset($doku_ipn_params['body']['TRANSIDMERCHANT']) ? $doku_ipn_params['body']['TRANSIDMERCHANT'] : $dokuparams['TRANSIDMERCHANT']); + } + $transaction_id_part = substr($dokuparams['TRANSIDMERCHANT'], 0, 14); + /* + if (!$doku_error) { + try { + $transaction_id_part = date_create_from_format('YmdHis', $transaction_id_part); + } catch (Exception $ex) { + $doku_error = true; + $doku_error_msg[] = "STOP : Exception error of date-created from form: {$ex->getMessage()}."; + } + } + if (!$doku_error) { + if (!strtotime(date_format($transaction_id_part, 'Y-m-d H:i:s'))) { + $doku_error = true; + $doku_error_msg[] = "STOP : Transaction id part not in Dateformat structured."; + } + } + if (!$doku_error) { + $transaction_id_part = date_format($transaction_id_part, 'YmdHis'); + $merchant_transaction = explode("{$transaction_id_part}", $dokuparams['TRANSIDMERCHANT']); + if (!isset($merchant_transaction[1])) { + $doku_error = true; + $doku_error_msg[] = "STOP : There is no Transaction-id from IPN Callback as expected: #DATETIME#TRANSID."; + } + } + */ + if (!$doku_error) { + $merchant_transaction = array( + 0 => FALSE, + 1 => $dokuparams['TRANSIDMERCHANT'], + ); + $invoiceId = trim($merchant_transaction[1]); + /** + * Validate Callback Invoice ID. + * + * Checks invoice ID is a valid invoice number. Note it will count an + * invoice in any status as valid. + * + * Performs a die upon encountering an invalid Invoice ID. + * + * Returns a normalised invoice ID. + * + * @param int $invoiceId Invoice ID + * @param string $gatewayName Gateway Name + **/ + $invoiceId = checkCbInvoiceID($invoiceId, $gatewayParams['paymentmethod']); + if (!$invoiceId) { + $doku_error = true; + $doku_error_msg[] = "STOP : Invoice Id is not found."; + if ($Log_Enabled) { + logTransaction($gatewayParams['paymentmethod'], $doku_error_msg, "InvoiceId Not Found"); + } + } + } + if (!$doku_error) { + $localApi['command'] = 'GetInvoice'; + if (isset($localApi['data']['id'])) { + unset($localApi['data']['id']); + } + $localApi['data']['invoiceid'] = $invoiceId; + $InvoiceData = localAPI($localApi['command'], $localApi['data'], $localApi['username']); + $Redirect_Url = ""; + if (isset($InvoiceData['invoiceid'])) { + if (intval($InvoiceData['invoiceid']) > 0) { + $GetConfigurationValue = localAPI('GetConfigurationValue', array('setting' => 'SystemURL'), $localApi['username']); + $Redirect_Url .= (isset($GetConfigurationValue['value']) ? $GetConfigurationValue['value'] : ''); + $Redirect_Url .= ((substr($systemUrl, -1) == '/') ? '' : '/'); + $Redirect_Url .= "viewinvoice.php?id={$invoiceId}"; + header("HTTP/1.1 301 Moved Permanently"); + header("Location: {$Redirect_Url}"); + exit; + } + } else { + $doku_error = true; + $doku_error_msg[] = "STOP : Local API Result not get invoiceid while review of InvoiceData from GetInvoice()."; + } + } + break; + case 'notify': + default: + if ($_SERVER['REQUEST_METHOD'] == 'POST') { + if (count($doku_ipn_params['body']) > 0) { + # DOKU Notify + $dokuparams = array( + 'PAYMENTDATETIME' => (isset($doku_ipn_params['body']['PAYMENTDATETIME']) ? $doku_ipn_params['body']['PAYMENTDATETIME'] : ''), + 'PURCHASECURRENCY' => (isset($doku_ipn_params['body']['PURCHASECURRENCY']) ? $doku_ipn_params['body']['PURCHASECURRENCY'] : ''), + 'LIABILITY' => (isset($doku_ipn_params['body']['LIABILITY']) ? $doku_ipn_params['body']['LIABILITY'] : ''), + 'PAYMENTCHANNEL' => (isset($doku_ipn_params['body']['PAYMENTCHANNEL']) ? $doku_ipn_params['body']['PAYMENTCHANNEL'] : ''), + 'AMOUNT' => (isset($doku_ipn_params['body']['AMOUNT']) ? $doku_ipn_params['body']['AMOUNT'] : ''), + 'PAYMENTCODE' => (isset($doku_ipn_params['body']['PAYMENTCODE']) ? $doku_ipn_params['body']['PAYMENTCODE'] : ''), + 'MCN' => (isset($doku_ipn_params['body']['MCN']) ? $doku_ipn_params['body']['MCN'] : ''), + 'WORDS' => (isset($doku_ipn_params['body']['WORDS']) ? $doku_ipn_params['body']['WORDS'] : ''), + 'RESULTMSG' => (isset($doku_ipn_params['body']['RESULTMSG']) ? $doku_ipn_params['body']['RESULTMSG'] : ''), + 'VERIFYID' => (isset($doku_ipn_params['body']['VERIFYID']) ? $doku_ipn_params['body']['VERIFYID'] : ''), + 'TRANSIDMERCHANT' => (isset($doku_ipn_params['body']['TRANSIDMERCHANT']) ? $doku_ipn_params['body']['TRANSIDMERCHANT'] : ''), + 'BANK' => (isset($doku_ipn_params['body']['BANK']) ? $doku_ipn_params['body']['BANK'] : ''), + 'STATUSTYPE' => (isset($doku_ipn_params['body']['STATUSTYPE']) ? $doku_ipn_params['body']['STATUSTYPE'] : ''), + 'APPROVALCODE' => (isset($doku_ipn_params['body']['APPROVALCODE']) ? $doku_ipn_params['body']['APPROVALCODE'] : ''), + 'EDUSTATUS' => (isset($doku_ipn_params['body']['EDUSTATUS']) ? $doku_ipn_params['body']['EDUSTATUS'] : ''), + 'THREEDSECURESTATUS' => (isset($doku_ipn_params['body']['THREEDSECURESTATUS']) ? $doku_ipn_params['body']['THREEDSECURESTATUS'] : ''), + 'VERIFYSCORE' => (isset($doku_ipn_params['body']['VERIFYSCORE']) ? $doku_ipn_params['body']['VERIFYSCORE'] : ''), + 'CURRENCY' => (isset($doku_ipn_params['body']['CURRENCY']) ? $doku_ipn_params['body']['CURRENCY'] : ''), + 'RESPONSECODE' => (isset($doku_ipn_params['body']['RESPONSECODE']) ? $doku_ipn_params['body']['RESPONSECODE'] : ''), + 'CHNAME' => (isset($doku_ipn_params['body']['CHNAME']) ? $doku_ipn_params['body']['CHNAME'] : ''), + 'BRAND' => (isset($doku_ipn_params['body']['BRAND']) ? $doku_ipn_params['body']['BRAND'] : ''), + 'VERIFYSTATUS' => (isset($doku_ipn_params['body']['VERIFYSTATUS']) ? $doku_ipn_params['body']['VERIFYSTATUS'] : ''), + 'SESSIONID' => (isset($doku_ipn_params['body']['SESSIONID']) ? $doku_ipn_params['body']['SESSIONID'] : ''), + ); + $REQUEST_METHOD_MSG = "NOTIFY:Continue"; + } else { + $REQUEST_METHOD_MSG = "STOP : BODY Have no content"; + } + } else { + $REQUEST_METHOD_MSG = "STOP : POST Method Required"; + } + break; + case 'redirect': + # DOKU Params (GET) + $dokuparams = array( + 'PAYMENTDATETIME' => (isset($doku_redirect_params['PAYMENTDATETIME']) ? $doku_redirect_params['PAYMENTDATETIME'] : ''), + 'PURCHASECURRENCY' => (isset($doku_redirect_params['PURCHASECURRENCY']) ? $doku_redirect_params['PURCHASECURRENCY'] : ''), + 'LIABILITY' => (isset($doku_redirect_params['LIABILITY']) ? $doku_redirect_params['LIABILITY'] : ''), + 'PAYMENTCHANNEL' => (isset($doku_redirect_params['PAYMENTCHANNEL']) ? $doku_redirect_params['PAYMENTCHANNEL'] : ''), + 'AMOUNT' => (isset($doku_redirect_params['AMOUNT']) ? $doku_redirect_params['AMOUNT'] : ''), + 'PAYMENTCODE' => (isset($doku_redirect_params['PAYMENTCODE']) ? $doku_redirect_params['PAYMENTCODE'] : ''), + 'MCN' => (isset($doku_redirect_params['MCN']) ? $doku_redirect_params['MCN'] : ''), + 'WORDS' => (isset($doku_redirect_params['WORDS']) ? $doku_redirect_params['WORDS'] : ''), + 'RESULTMSG' => (isset($doku_redirect_params['RESULTMSG']) ? $doku_redirect_params['RESULTMSG'] : ''), + 'VERIFYID' => (isset($doku_redirect_params['VERIFYID']) ? $doku_redirect_params['VERIFYID'] : ''), + 'TRANSIDMERCHANT' => (isset($doku_redirect_params['TRANSIDMERCHANT']) ? $doku_redirect_params['TRANSIDMERCHANT'] : ''), + 'BANK' => (isset($doku_redirect_params['BANK']) ? $doku_redirect_params['BANK'] : ''), + 'STATUSTYPE' => (isset($doku_redirect_params['STATUSTYPE']) ? $doku_redirect_params['STATUSTYPE'] : ''), + 'APPROVALCODE' => (isset($doku_redirect_params['APPROVALCODE']) ? $doku_redirect_params['APPROVALCODE'] : ''), + 'EDUSTATUS' => (isset($doku_redirect_params['EDUSTATUS']) ? $doku_redirect_params['EDUSTATUS'] : ''), + 'THREEDSECURESTATUS' => (isset($doku_redirect_params['THREEDSECURESTATUS']) ? $doku_redirect_params['THREEDSECURESTATUS'] : ''), + 'VERIFYSCORE' => (isset($doku_redirect_params['VERIFYSCORE']) ? $doku_redirect_params['VERIFYSCORE'] : ''), + 'CURRENCY' => (isset($doku_redirect_params['CURRENCY']) ? $doku_redirect_params['CURRENCY'] : ''), + 'RESPONSECODE' => (isset($doku_redirect_params['RESPONSECODE']) ? $doku_redirect_params['RESPONSECODE'] : ''), + 'CHNAME' => (isset($doku_redirect_params['CHNAME']) ? $doku_redirect_params['CHNAME'] : ''), + 'BRAND' => (isset($doku_redirect_params['BRAND']) ? $doku_redirect_params['BRAND'] : ''), + 'VERIFYSTATUS' => (isset($doku_redirect_params['VERIFYSTATUS']) ? $doku_redirect_params['VERIFYSTATUS'] : ''), + 'SESSIONID' => (isset($doku_redirect_params['SESSIONID']) ? $doku_redirect_params['SESSIONID'] : ''), + 'STATUSCODE' => (isset($doku_redirect_params['STATUSCODE']) ? $doku_redirect_params['STATUSCODE'] : ''), + ); + # DOKU Params (POST) + if (count($doku_ipn_params['body']) > 0) { + foreach ($doku_ipn_params['body'] as $key => $val) { + if (!isset($dokuparams[$key])) { + $dokuparams[$key] = $val; + } else { + if ($dokuparams[$key] != $val) { + $dokuparams[$key] = $val; + } + } + } + } + if (count($doku_redirect_params) > 0) { + $REQUEST_METHOD_MSG = "REDIRECT:Continue"; + } else { + $REQUEST_METHOD_MSG = "STOP : QUERYSTRING Have no content"; + } + break; +} +/* +** +* CONTINUE +** +*/ +switch (strtolower($CallbackPage)) { + case 'notify': + default: + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $dokuparams, 'Payment Notify From Doku'); } + break; + case 'redirect': + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $dokuparams, 'Payment Redirect From Doku'); } + break; + case 'review': + case 'identify': + echo "{$REQUEST_METHOD_MSG}"; + exit; + break; +} +/* +** +* CONTINUE +** +*/ +switch (strtolower($CallbackPage)) { + case 'review': + case 'identify': + die(); + break; + case 'notify': + case 'redirect': + default: + //-------------------------------------------------------------------- + if (!$doku_error) { + if (is_array($dokuparams['TRANSIDMERCHANT']) || is_object($dokuparams['TRANSIDMERCHANT'])) { + $doku_error = true; + $doku_error_msg[] = "STOP : Array or Object return for TRANSIDMERCHANT."; + } + } + /* + if (!$doku_error) { + $transaction_id = $dokuparams['TRANSIDMERCHANT']; + $transaction_id_part = substr($dokuparams['TRANSIDMERCHANT'], 0, 14); + try { + $transaction_id_part = date_create_from_format('YmdHis', $transaction_id_part); + } catch (Exception $ex) { + $doku_error = true; + $doku_error_msg[] = "STOP : Exception error of date-created from form: {$ex->getMessage()}."; + } + } + if (!$doku_error) { + if (!strtotime(date_format($transaction_id_part, 'Y-m-d H:i:s'))) { + $doku_error = true; + $doku_error_msg[] = "STOP : Transaction id part not in Dateformat structured."; + } + } + if (!$doku_error) { + $transaction_id_part = date_format($transaction_id_part, 'YmdHis'); + $merchant_transaction = explode("{$transaction_id_part}", $dokuparams['TRANSIDMERCHANT']); + if (!isset($merchant_transaction[1])) { + $doku_error = true; + $doku_error_msg[] = "STOP : There is no Transaction-id from IPN Callback as expected: #DATETIME#TRANSID."; + } + } + */ + ######################################### + if (!$doku_error) { + $merchant_transaction = array( + 0 => FALSE, + 1 => $dokuparams['TRANSIDMERCHANT'], + ); + $invoiceId = trim($merchant_transaction[1]); + /** + * Validate Callback Invoice ID. + * + * Checks invoice ID is a valid invoice number. Note it will count an + * invoice in any status as valid. + * + * Performs a die upon encountering an invalid Invoice ID. + * + * Returns a normalised invoice ID. + * + * @param int $invoiceId Invoice ID + * @param string $gatewayName Gateway Name + **/ + $invoiceId = checkCbInvoiceID($invoiceId, $gatewayParams['paymentmethod']); + if (!$invoiceId) { + $doku_error = true; + $doku_error_msg[] = "STOP : Invoice Id is not found."; + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $doku_error_msg, "InvoiceId Not Found"); } + } + } + ######################################## + //-------------------------------------------------------------------- + if (!$doku_error) { + $params_input = array(); + $params_input['amount'] = (isset($dokuparams['AMOUNT']) ? $dokuparams['AMOUNT'] : '0.00'); + $params_input['transaction_id'] = (isset($dokuparams['TRANSIDMERCHANT']) ? $dokuparams['TRANSIDMERCHANT'] : 0); + $params_input['transaction_session'] = (isset($dokuparams['SESSIONID']) ? $dokuparams['SESSIONID'] : ''); + $params_input['transaction_currency'] = (isset($dokuparams['CURRENCY']) ? $dokuparams['CURRENCY'] : '360'); + $params_input['result_msg'] = (isset($dokuparams['RESULTMSG']) ? $dokuparams['RESULTMSG'] : ''); // SUCCESS | FAILED + $params_input['verify_status'] = (isset($dokuparams['VERIFYSTATUS']) ? $dokuparams['VERIFYSTATUS'] : ''); // NA + $params_input['words'] = (isset($dokuparams['WORDS']) ? $dokuparams['WORDS'] : ''); + // Make notify structured + $CheckNotifyPaymentStructure = $DokuPayment->create_payment_structure('notify', 0, $params_input, $dokuparams); + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $CheckNotifyPaymentStructure, 'Payment Notify Structured: ' . (__LINE__)); } + if (!isset($CheckNotifyPaymentStructure['WORDS'])) { + $doku_error = true; + $doku_error_msg[] = "STOP : Not get WORDS string from created notify structured."; + } + } + if (!$doku_error) { + if (!is_string($params_input['words'])) { + $doku_error = true; + $doku_error_msg[] = "STOP : Words should be a string."; + } + } + //--------------------------------------------------------------------------------- + break; +} +/* +** +* CONTINUE +** +*/ +switch (strtolower($CallbackPage)) { + case 'review': + case 'identify': + die(); + break; + case 'notify': + case 'redirect': + default: + // Make more @XMLPaymentStatus params + if (count($dokuparams) > 0) { + foreach ($dokuparams as $key => $val) { + $key = preg_replace("/[^a-zA-Z0-9]+/", "", $key); + if (!empty($key) || ($key != '')) { + $XMLPaymentStatus[$key] = $val; + } + } + } + //------------------------------------ + $Redirect_Url = "/"; + if (!$doku_error) { + If (isset($localApi['data']['id'])) { + unset($localApi['data']['id']); + } + $localApi['data']['invoiceid'] = $invoiceId; + //unset($localApi['data']['invoiceid']); + //$localApi['data']['id'] = $invoiceId; + //$InvoiceData = localAPI($localApi['command'], $localApi['data'], $localApi['username']); + // query localApi from invoiceid + $InvoiceData = localAPI('GetInvoice', $localApi['data'], $localApi['username']); + if (isset($InvoiceData['invoiceid'])) { + if (intval($InvoiceData['invoiceid']) > 0) { + $GetConfigurationValue = localAPI('GetConfigurationValue', array('setting' => 'SystemURL'), $localApi['username']); + $Redirect_Url = (isset($GetConfigurationValue['value']) ? $GetConfigurationValue['value'] : ''); + $Redirect_Url .= ((substr($systemUrl, -1) == '/') ? '' : '/'); + $Redirect_Url .= "viewinvoice.php?id={$invoiceId}"; + } + } else { + $doku_error = true; + $doku_error_msg[] = "STOP : Local API Result not get invoiceid of InvoiceData from GetInvoice()."; + } + } + $orders_debug = array( + 'order_id' => 0, + 'order_num' => 0, + 'order_status' => '', + ); + $order_id = 0; + $order_num = 0; + $order_status = ''; + if (!$doku_error) { + if (isset($InvoiceData['invoiceid']) && isset($InvoiceData['invoicenum']) && isset($InvoiceData['status'])) { + if (intval($InvoiceData['invoiceid']) > 0) { + $order_id = $InvoiceData['invoiceid']; + $orders_debug['order_id'] = $order_id; + } + if (intval($InvoiceData['invoicenum']) > 0) { + $order_num = $InvoiceData['invoicenum']; + $orders_debug['order_num'] = $order_num; + } + $order_status = (is_string($InvoiceData['status']) ? strtolower($InvoiceData['status']) : ''); + $orders_debug['order_status'] = $order_status; + } else { + $doku_error = true; + $doku_error_msg[] = "STOP : Local API Result for GetInvoice() not get proper data as expected."; + } + } + break; +} +/* +** +* CONTINUE +** +*/ +switch (strtolower($CallbackPage)) { + case 'review': + case 'identify': + die(); + break; + case 'notify': + default: + // Only for Notify + if (strtolower($CallbackPage) === strtolower('notify')) { + if (!$doku_error) { + //----------------------------------------- + // check if WORDS is match or not + //----------------------------------------- + if (strtolower($CheckNotifyPaymentStructure['WORDS']) !== strtolower($params_input['words'])) { + $doku_error = true; + $doku_error_msg[] = "STOP : Words from Notify-Structured not same with Dokuparams"; + } + } + } + //------------------------------------------------------------------------------------------ + if (!$doku_error) { + //--------------------------------- + // IMPORTANT GLOBAL VARS + //--------------------------------- + $invoiceId = (isset($invoiceId) ? $invoiceId : ''); + //$transactionId = (isset($dokuparams['APPROVALCODE']) ? $dokuparams['APPROVALCODE'] : ''); + $transactionId = $invoiceId; + /** + * Adding Unique generated Invoice-Id to Transaction-Id + * Got bugs: DOKU always send: + * Constant APPROVALCODE for first time Notify (DOKU Always send same Approval-code for each invoice-id) + * Using @$transaction_id_part + */ + $transactionId .= "_"; + if (isset($dokuparams['TRANSIDMERCHANT'])) { + $explode_transid = explode("{$invoiceId}_", $dokuparams['TRANSIDMERCHANT']); + if (isset($explode_transid[1])) { + $transactionId .= sprintf("%s", $explode_transid[1]); + } + } + //$transactionId .= (isset($transaction_id_part) ? $transaction_id_part : ''); + //$transactionId .= (isset($dokuparams['APPROVALCODE']) ? $dokuparams['APPROVALCODE'] : ''); + $paymentAmount = (isset($dokuparams['AMOUNT']) ? $dokuparams['AMOUNT'] : 0); + $paymentFee = (isset($dokuparams['FEE']) ? $dokuparams['FEE'] : 0); + $paymentEDU = (isset($dokuparams['EDUSTATUS']) ? $dokuparams['EDUSTATUS'] : 'NA'); // NA (Default) + # + $paymentResponseStatus = (isset($dokuparams['RESULTMSG']) ? $dokuparams['RESULTMSG'] : ''); // SUCCESS, VOIDED, FAILED + $paymentResponseCode = (isset($dokuparams['RESPONSECODE']) ? $dokuparams['RESPONSECODE'] : ''); // 0000 (Success), Other is failed + switch (strtoupper($paymentResponseStatus)) { + case 'SUCCESS': + $success = TRUE; + if ($paymentResponseCode == '0000') { + $success = TRUE; + } else { + $success = FALSE; + $doku_error = true; + $doku_error_msg[] = "Payment Response Code is Not : 0000 from Payment-Notify."; + } + break; + case 'VOIDED': + if ($paymentResponseCode == '0000') { + $success = TRUE; + } else { + $success = FALSE; + $doku_error = true; + $doku_error_msg[] = "STOP : Payment Response Code is Not : 0000."; + } + break; + case 'FAILED': + $success = FALSE; + $doku_error = true; + $doku_error_msg[] = "STOP : Payment Response Status is not Success: {$paymentResponseStatus}."; + break; + default: + $success = FALSE; + $doku_error = true; + $doku_error_msg[] = "STOP : Un-Expected Payment-Response-Status: (" . (__LINE__) . ") {$paymentResponseStatus}"; + break; + } + } + break; + case 'redirect': + //------------------------------------------------------------------------------------------------------------- + /** + * Check Status Payment: Call DOKU + * Applied only for Redirect-Page not for First Time Notify + * ******************************************************** + */ + //------------------------------------------------------------------------------------------------------------- + if ($PaymentCheck_Enabled) { + if (strtolower($order_status) !== strtolower('paid')) { + // Should call to redirect-page + //*********************************************************************** + if (!$doku_error) { + // Make checking payment structured + # add puchase-currency + $params_input['transaction_currency_purchase'] = (isset($dokuparams['PURCHASECURRENCY']) ? $dokuparams['PURCHASECURRENCY'] : '360'); + $CheckStatusPaymentStructure = $DokuPayment->create_payment_structure('check', 0, $params_input, $dokuparams); + $headers = $DokuPayment->create_curl_headers($DokuPayment->dokupayment_headers); + if (isset($CheckStatusPaymentStructure['WORDS_STRING'])) { + unset($CheckStatusPaymentStructure['WORDS_STRING']); + } + try { + $payment_status = $DokuPayment->create_curl_request('POST', $DokuPayment->endpoint['checkstatus'], 'API.Context (http://whmcs.alumniparhata.org)', $headers, $CheckStatusPaymentStructure, 30); + } catch (Exception $ex) { + $doku_error = true; + $doku_error_msg[] = "STOP : Exception Error: {$ex->getMessage()}."; + throw $ex; + } + } + if (!$doku_error) { + if (!isset($payment_status['response']['body'])) { + $doku_error = true; + $doku_error_msg[] = "STOP : There is no body from Doku check -payment-status."; + } + } + // Format XML to Array + if (!$doku_error) { + # Log payment-status Body + //logTransaction($gatewayParams['paymentmethod'], $payment_status['response']['body'], 'Payment Status XML:' . (__LINE__)); + try { + $payment_status = $DokuPayment->xmltoarray($payment_status['response']['body']); + } catch (Exception $ex) { + $doku_error = true; + $doku_error_msg[] = "STOP : Exception Error while render xml format to array: {$ex->getMessage()}."; + throw $ex; + } + } + if (!$doku_error) { + if (!isset($payment_status['PAYMENT_STATUS'])) { + $doku_error = true; + $doku_error_msg[] = "STOP : XML Format is not-expected."; + } + } + if (!$doku_error) { + if (count($payment_status['PAYMENT_STATUS']) > 0) { + foreach ($payment_status['PAYMENT_STATUS'] as $key => $val) { + $XMLPaymentStatus[$key] = (isset($val['value']) ? $val['value'] : ''); + } + } else { + $doku_error = true; + $doku_error_msg[] = "STOP : Count payment-status not have an array."; + } + } + if (!$doku_error) { + // Make checking redirect-payment structured + # add transaction-words, transaction-status, transaction-code + $params_input['transaction_words'] = (isset($dokuparams['WORDS']) ? $dokuparams['WORDS'] : ''); + $params_input['transaction_status'] = (isset($dokuparams['STATUSCODE']) ? strval($dokuparams['STATUSCODE']) : ''); // 0000 = Success, Other = Failed + $params_input['transaction_channel'] = (isset($dokuparams['PAYMENTCHANNEL']) ? $dokuparams['PAYMENTCHANNEL'] : ''); + $CheckRedirectPaymentStructure = $DokuPayment->create_payment_structure('redirect', 0, $params_input, $dokuparams); + if (strtolower($CallbackPage) === strtolower('redirect')) { + //----------------------------------------- + // check if WORDS is match or not (On 'redirect' stage) + //----------------------------------------- + if (strtolower($params_input['transaction_words']) !== strtolower($CheckRedirectPaymentStructure['WORDS'])) { + $doku_error = true; + $doku_error_msg[] = "STOP : Words from Redirect-Structured not same with Dokuparams.
\n"; + $doku_error_msg[] .= "Input words: {$params_input['transaction_words']}
\n"; + $doku_error_msg[] .= "Structured words: {$CheckRedirectPaymentStructure['WORDS']}
\n"; + /* + $doku_error_msg['structured'] = $CheckRedirectPaymentStructure; + $doku_error_msg['input'] = $params_input; + $doku_error_msg['dokuparams'] = $dokuparams; + */ + } + } + } + if (!$doku_error) { + //--------------------------------- + // IMPORTANT GLOBAL VARS + //--------------------------------- + $invoiceId = (isset($invoiceId) ? $invoiceId : ''); + #$transactionId = (isset($XMLPaymentStatus['APPROVALCODE']) ? $XMLPaymentStatus['APPROVALCODE'] : ''); + $transactionId = $invoiceId; + // + // Adding Unique generated Invoice-Id to Transaction-Id + // Got bugs: DOKU always send: + // Constant APPROVALCODE for first time Notify (DOKU Always send same Approval-code foe each invoice-id) + // Using @$merchant_transaction[0] + // + $transactionId .= "_"; + if (isset($dokuparams['TRANSIDMERCHANT'])) { + $explode_transid = explode("{$invoiceId}_", $dokuparams['TRANSIDMERCHANT']); + if (isset($explode_transid[1])) { + $transactionId .= sprintf("%s", $explode_transid[1]); + } + } + //$transactionId .= (isset($transaction_id_part) ? $transaction_id_part : ''); + //$transactionId .= (isset($XMLPaymentStatus['APPROVALCODE']) ? $XMLPaymentStatus['APPROVALCODE'] : ''); + $paymentAmount = (isset($XMLPaymentStatus['AMOUNT']) ? $XMLPaymentStatus['AMOUNT'] : 0); + $paymentFee = (isset($XMLPaymentStatus['FEE']) ? $XMLPaymentStatus['FEE'] : 0); + $paymentEDU = (isset($XMLPaymentStatus['EDUSTATUS']) ? $XMLPaymentStatus['EDUSTATUS'] : 'NA'); // NA (Default) + # + $paymentResponseStatus = (isset($XMLPaymentStatus['RESULTMSG']) ? $XMLPaymentStatus['RESULTMSG'] : ''); // SUCCESS, VOIDED, FAILED + $paymentResponseCode = (isset($XMLPaymentStatus['RESPONSECODE']) ? $XMLPaymentStatus['RESPONSECODE'] : ''); // 0000 (Success), Other is failed + } + if (!$doku_error) { + // Log payment-status + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $XMLPaymentStatus, "(#{$invoiceId}) " . 'Payment Status Array:' . (__LINE__)); } + /* + if ($checkCbTransID) { + $doku_error = true; + $doku_error_msg[] = "checkCbTransID() Return True: Maybe duplicated transaction."; + } + */ + } + //*********************************************************************** + } else { + header("HTTP/1.1 301 Moved Permanently"); + header("Location: {$Redirect_Url}"); + exit; + } + } else { + if (!$doku_error) { + // Make checking redirect-payment structured + # add transaction-words, transaction-status, transaction-code + $params_input['transaction_words'] = (isset($dokuparams['WORDS']) ? $dokuparams['WORDS'] : ''); + $params_input['transaction_status'] = (isset($dokuparams['STATUSCODE']) ? strval($dokuparams['STATUSCODE']) : ''); // 0000 = Success, Other = Failed + $params_input['transaction_channel'] = (isset($dokuparams['PAYMENTCHANNEL']) ? $dokuparams['PAYMENTCHANNEL'] : ''); + $CheckRedirectPaymentStructure = $DokuPayment->create_payment_structure('redirect', 0, $params_input, $dokuparams); + if (strtolower($CallbackPage) === strtolower('redirect')) { + //----------------------------------------- + // check if WORDS is match or not (On 'redirect' stage) + //----------------------------------------- + if (strtolower($params_input['transaction_words']) !== strtolower($CheckRedirectPaymentStructure['WORDS'])) { + $doku_error = true; + $doku_error_msg[] = "STOP : Words from Redirect-Structured not same with Dokuparams. (" . (__LINE__) . ")"; + } + } + } + if (!$doku_error) { + if (strtolower($order_status) !== strtolower('paid')) { + //--------------------------------- + // IMPORTANT GLOBAL VARS + //--------------------------------- + $invoiceId = (isset($invoiceId) ? $invoiceId : ''); + $transactionId = $invoiceId; + // + // Adding Unique generated Invoice-Id to Transaction-Id + // Got bugs: DOKU always send: + // Constant APPROVALCODE for first time Notify (DOKU Always send same Approval-code foe each invoice-id) + // Using @$merchant_transaction[0] + // + $transactionId .= "_"; + if (isset($dokuparams['TRANSIDMERCHANT'])) { + $explode_transid = explode("{$invoiceId}_", $dokuparams['TRANSIDMERCHANT']); + if (isset($explode_transid[1])) { + $transactionId .= sprintf("%s", $explode_transid[1]); + } + } + //$transactionId .= (isset($transaction_id_part) ? $transaction_id_part : ''); + //$transactionId .= (isset($dokuparams['APPROVALCODE']) ? $dokuparams['APPROVALCODE'] : ''); + $paymentAmount = (isset($dokuparams['AMOUNT']) ? $dokuparams['AMOUNT'] : 0); + $paymentFee = (isset($dokuparams['FEE']) ? $dokuparams['FEE'] : 0); + $paymentEDU = (isset($dokuparams['EDUSTATUS']) ? $dokuparams['EDUSTATUS'] : 'NA'); // NA (Default) + # + $paymentResponseStatus = (isset($dokuparams['RESULTMSG']) ? $dokuparams['RESULTMSG'] : ''); // SUCCESS, VOIDED, FAILED + $paymentResponseCode = (isset($dokuparams['RESPONSECODE']) ? $XMLPaymentStatus['RESPONSECODE'] : $params_input['transaction_status']); // 0000 (Success), Other is failed + } else { + header("HTTP/1.1 301 Moved Permanently"); + header("Location: {$Redirect_Url}"); + exit; + } + } + if (!$doku_error) { + // Log payment-status + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $dokuparams, "(#{$invoiceId}) " . 'Payment Status From Redirected:' . (__LINE__)); } + if (strtolower($order_status) !== strtolower('paid')) { + // Make Error if Redirected from Un-Success Payment + $doku_error = true; + $doku_error_msg[] = "STOP : Redirected from failed payment: Maybe WHMCS Payment-Gateway-Module not activate payment-check status."; + } + } + } + //------------------------------------------------------------------------------------------------------------- + break; +} +/* +** +* CONTINUE +** +*/ +switch (strtolower($CallbackPage)) { + case 'review': + case 'identify': + die(); + break; + case 'notify': + case 'redirect': + default: + if (!$doku_error) { + $transactionStatus = ($success ? 'Success' : 'Failure'); + //------------------------------------------------------------------------------------------------------------------- + // EDU Enabled? + //------------------------------------------------------------------------------------------------------------------- + $transactionEdu = "EDU:APPROVE"; // DEFAULT: For not-enabled EDU + if ($success) { + if ($EDU_Enabled > 0) { + switch (strtoupper($paymentEDU)) { + case 'APPROVE': + $success = TRUE; + $transactionEdu = 'EDU:APPROVE'; + // Status: Success + break; + case 'REJECT': + $success = FALSE; + $transactionEdu = 'EDU:REJECT'; + // Status: Failed + break; + case 'NA': + $success = FALSE; + $transactionEdu = "EDU:NA"; + // Status: Pending/Waiting + break; + default: + $success = FALSE; + $transactionEdu = "EDU:{$paymentEDU}"; + // Status: Un-Expected + break; + } + } + if ($transactionEdu == 'EDU:APPROVE') { + $transactionStatus = 'Success'; + } else { + $transactionStatus = 'Pending'; + } + } + } + ############################################################################################################# + break; +} +/* +** +* CONTINUE +** +*/ +switch (strtolower($CallbackPage)) { + case 'review': + case 'identify': + die(); + break; + case 'redirect': + case 'notify': + default: + if (!$doku_error) { + if (strtolower($order_status) !== strtolower('paid')) { + //--------------------------------- + /** + * Check Callback Transaction ID. + * + * Performs a check for any existing transactions with the same given + * transaction number. + * + * Performs a die upon encountering a duplicate. + * + * @param string $transactionId Unique Transaction ID + */ + checkCbTransID($transactionId); + } + } + break; +} +/* +** +* CONTINUE +** +*/ +switch (strtolower($CallbackPage)) { + case 'review': + case 'identify': + die(); + break; + case 'redirect': + ############################################################################################################# + # CALL VOID? + ############################################################################################################# + //------------------------------------------------------------------------------------------------------------------- + if ($Void_Enabled) { + if (!$doku_error) { + $VoidParams = array( + 'transaction_id' => (isset($XMLPaymentStatus['TRANSIDMERCHANT']) ? $XMLPaymentStatus['TRANSIDMERCHANT'] : ''), + 'transaction_session' => (isset($XMLPaymentStatus['SESSIONID']) ? $XMLPaymentStatus['SESSIONID'] : ''), + 'transaction_currency' => (isset($XMLPaymentStatus['CURRENCY']) ? $XMLPaymentStatus['CURRENCY'] : '360'), + 'transaction_channel' => (isset($XMLPaymentStatus['PAYMENTCHANNEL']) ? $XMLPaymentStatus['PAYMENTCHANNEL'] : ''), + ); + $createVoidStructure = $DokuPayment->create_payment_structure('void', 0, $VoidParams, $dokuparams); + if (isset($createVoidStructure['WORDS_STRING'])) { + unset($createVoidStructure['WORDS_STRING']); + } + $headers = $DokuPayment->create_curl_headers($DokuPayment->dokupayment_headers); + try { + $create_void = $DokuPayment->create_curl_request('POST', $DokuPayment->endpoint['void'], 'API.Context (http://whmcs.alumniparhata.org) - Change this as you wish.', $headers, $createVoidStructure, 30); + } catch (Exception $ex) { + $doku_error = true; + $doku_error_msg[] = "STOP : Error exception for create void: {$ex->getMessage()}."; + throw $ex; + } + } + if (!$doku_error) { + if (!isset($create_void['response']['body'])) { + $doku_error = true; + $doku_error_msg[] = "STOP : There is no body response from Void response."; + } + } + if (!$doku_error) { + $StringVoidStatus = trim($create_void['response']['body']); + switch (strtoupper($StringVoidStatus)) { + case 'FAILED': + // Do what to do if Failed VOID + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $create_void, "Payment Void: ". strtoupper($StringVoidStatus)); } + break; + case 'SUCCESS': + // Do what to do if Success VOID + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $create_void, "Payment Void: ". strtoupper($StringVoidStatus)); } + break; + default: + // DO what to do if Un-expected VOID + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $create_void, "Payment Void: UN-EXPECTED ({$StringVoidStatus})"); } + break; + } + } + } + ############################################################################################################# + //------------------------------------------------------------------------------------------------------------------- + if (!$doku_error) { + switch (strtoupper($paymentResponseStatus)) { + case 'SUCCESS': + $success = TRUE; + break; + case 'VOIDED': + if ($paymentResponseCode == '0000') { + $success = TRUE; + } else { + $success = FALSE; + $doku_error = true; + $doku_error_msg[] = "STOP : Payment Response Code is Not : 0000."; + } + break; + case 'FAILED': + $success = FALSE; + $doku_error = true; + $doku_error_msg[] = "STOP : Payment Response Status is not Success: {$paymentResponseStatus}."; + break; + default: + $success = FALSE; + $doku_error = true; + $doku_error_msg[] = "STOP : Un-Expected Payment-Response-Status on Line (" . (__LINE__) . "): {$paymentResponseStatus}"; + $doku_error_msg['XMLPaymentStatus'] = $XMLPaymentStatus; + break; + } + } + if (!$doku_error) { + if (strtolower($order_status) !== strtolower('paid')) { + $REQUEST_METHOD_MSG = "REDIRECT:Continue"; + } else { + header("HTTP/1.1 301 Moved Permanently"); + header("Location: {$Redirect_Url}"); + exit; + } + } + break; + case 'notify': + default: + $REQUEST_METHOD_MSG = "CONTINUE"; + break; +} +/* +** +* CONTINUE +** +*/ +switch (strtolower($CallbackPage)) { + case 'redirect': + case 'notify': + default: + if (!$doku_error) { + /** + * Log Transaction. + * + * Add an entry to the Gateway Log for debugging purposes. + * + * The debug data can be a string or an array. In the case of an + * array it will be + * + * @param string $gatewayName Display label + * @param string|array $debugData Data to log + * @param string $transactionStatus Status + */ + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $XMLPaymentStatus, $transactionStatus); } + if ($success) { + /** + * Add Invoice Payment. + * + * Applies a payment transaction entry to the given invoice ID. + * + * @param int $invoiceId Invoice ID + * @param string $transactionId Transaction ID + * @param float $paymentAmount Amount paid (defaults to full balance) + * @param float $paymentFee Payment fee (optional) + * @param string $gatewayModule Gateway module name + */ + addInvoicePayment( + $invoiceId, + $transactionId, + $paymentAmount, + $paymentFee, + $gatewayModuleName + ); + } + } else { + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], array('STOP' => $doku_error_msg), "(doku_error): Failed"); } + } + break; + case 'review': + case 'identify': + die(); + break; +} +/* +** +* CONTINUE +** +*/ +switch (strtolower($CallbackPage)) { + case 'review': + case 'identify': + if (!$doku_error) { + echo $REQUEST_METHOD_MSG; + } else { + print_r($doku_error_msg); + } + case 'notify': + default: + if (!$doku_error) { + echo $REQUEST_METHOD_MSG; + } else { + echo "STOP\r\n"; + if (count($doku_error_msg) > 0) { + foreach ($doku_error_msg as $keval) { + echo $keval . "\n"; + } + } + } + break; + case 'redirect': + header("HTTP/1.1 301 Moved Permanently"); + header("Location: {$Redirect_Url}"); + exit; + break; +} + diff --git a/modules/gateways/callback/dokusubscription.php b/modules/gateways/callback/dokusubscription.php new file mode 100644 index 0000000..a3f786b --- /dev/null +++ b/modules/gateways/callback/dokusubscription.php @@ -0,0 +1,1507 @@ +setTimezone(new DateTimeZone("Asia/Bangkok")); +if (((int)$Datezone->format('His') >= 85959) && ((int)$Datezone->format('His') <= 225959)) { + $Void_Enabled = (isset($gatewayParams['Void-Enabled']) ? $gatewayParams['Void-Enabled'] : ''); + $Void_Enabled = (!is_array($Void_Enabled) ? trim($Void_Enabled) : ''); + $Void_Enabled = ((strtolower($Void_Enabled) === strtolower('on')) ? TRUE : FALSE); +} else { + $Void_Enabled = FALSE; +} +// Constant disabled VOID +$Void_Enabled = FALSE; +//------------------------------------------------------------------------------------------------ +$LocalApiAdminUsername = (isset($gatewayParams['Local-Api-Admin-Username']) ? $gatewayParams['Local-Api-Admin-Username'] : ''); +$Log_Enabled = FALSE; +if (isset($gatewayParams['Log-Enabled'])) { + $Log_Enabled = ((strtolower($gatewayParams['Log-Enabled']) == 'on') ? TRUE : FALSE); +} +/* +print_r($gatewayParams); +exit; +*/ +$PaymentCheck_Enabled = (isset($gatewayParams['PaymentCheck-Enabled']) ? $gatewayParams['PaymentCheck-Enabled'] : ''); +$PaymentCheck_Enabled = ((strtolower($PaymentCheck_Enabled) === strtolower('on')) ? TRUE : FALSE); +function redirecting_page_to_invoice($Redirect_Url) { + header("HTTP/1.1 301 Moved Permanently"); + header("Location: {$Redirect_Url}"); + exit; +} +// Die if module is not active. +if (!$gatewayParams['type']) { + die("Module Not Activated"); +} +$Environment = (isset($gatewayParams['Environment']) ? $gatewayParams['Environment'] : 'sandbox'); // Let sandbox as default +if (!is_string($Environment) && ((!is_array($Environment)) || (!is_object($Environment)))) { + if (strtolower($Environment) === strtolower('live')) { + // Gateway Configuration Parameters + $MallId = (isset($gatewayParams['MallId_Live']) ? $gatewayParams['MallId_Live'] : ''); + $ShopName = (isset($gatewayParams['ShopName_Live']) ? $gatewayParams['ShopName_Live'] : ''); + $ChainMerchant = (isset($gatewayParams['ChainMerchant_Live']) ? $gatewayParams['ChainMerchant_Live'] : 'NA'); + $SharedKey = (isset($gatewayParams['SharedKey_Live']) ? $gatewayParams['SharedKey_Live'] : ''); + } else { + // Gateway Configuration Parameters + $MallId = (isset($gatewayParams['MallId']) ? $gatewayParams['MallId'] : ''); + $ShopName = (isset($gatewayParams['ShopName']) ? $gatewayParams['ShopName'] : ''); + $ChainMerchant = (isset($gatewayParams['ChainMerchant']) ? $gatewayParams['ChainMerchant'] : 'NA'); + $SharedKey = (isset($gatewayParams['SharedKey']) ? $gatewayParams['SharedKey'] : ''); + } +} else { + // Gateway Configuration Parameters + $MallId = (isset($gatewayParams['MallId']) ? $gatewayParams['MallId'] : ''); + $ShopName = (isset($gatewayParams['ShopName']) ? $gatewayParams['ShopName'] : ''); + $ChainMerchant = (isset($gatewayParams['ChainMerchant']) ? $gatewayParams['ChainMerchant'] : 'NA'); + $SharedKey = (isset($gatewayParams['SharedKey']) ? $gatewayParams['SharedKey'] : ''); +} +$DokuConfigs = array( + 'isofile' => 'dokuhosted/assets/iso3166.json', + 'merchant' => array( + 'mallid' => $MallId, + 'shopname' => $ShopName, + 'chainmerchant' => $ChainMerchant, + 'sharedkey' => $SharedKey, + ), + 'endpoint' => (is_string($Environment) ? strtolower($Environment) : 'sandbox'), // sandbox as default +); +if (class_exists('dokusubscription_DokuPayment')) { + $DokuPayment = new dokusubscription_DokuPayment($DokuConfigs); +} else { + require_once($dokulib); + $DokuPayment = new dokusubscription_DokuPayment($DokuConfigs); +} +// Getting URL Querystring +$doku_get = dokusubscription_DokuPayment::_GET(); +// Make Global @CallbackPage +$CallbackPage = (isset($doku_get['page']) ? $doku_get['page'] : 'notify'); // notify as default-callback-page +$CallbackPage = (is_string($CallbackPage) ? strtolower($CallbackPage) : 'notify'); +/* +*************************************************************************** +* +* IF IPN : $doku_ipn_params +* IF Redirect : $doku_redirect_params +* +*************************************************************************** +*/ +$REQUEST_METHOD = (isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'HEAD'); +$REQUEST_METHOD_MSG = ""; +# Get Doku IPN Params: +$doku_ipn_params = $DokuPayment->doku_incoming_callback(); +if ($Log_Enabled) { + logTransaction($gatewayParams['paymentmethod'], $doku_ipn_params, "({$REQUEST_METHOD}) Incoming Callback Params"); +} +# Get Doku Redirect Params from Request-Uri +$doku_redirect_params = dokusubscription_DokuPayment::get_query_string(); +################################ +//------------------------------ +// Global Validation +$doku_error = FALSE; +$doku_error_msg = array(); +// Make GLOBAL @success +$success = FALSE; +//------------------------------ +// Make GLOBAL @checkCbTransID +$checkCbTransID = FALSE; +// Previously get 500 Internal Error for this transaction: checkCbTransID($transactionId); +// Make GLOBAL @XMLPaymentStatus +$XMLPaymentStatus = array(); +if ($EDU_Enabled > 0) { + $XMLPaymentStatus['edu-enabled'] = $EDU_Enabled; +} else { + $XMLPaymentStatus['edu-enabled'] = 0; +} +// Make GLOBAL @StringVoidStatus +$StringVoidStatus = ""; +/* +// Use localAPI to handle and redirect user +*/ +$localApi = array( + 'command' => 'GetOrders', + 'data' => array( + 'id' => '', // Later updated on review case + //'invoiceid' => '', # Later updated on review case + ), + 'username' => $LocalApiAdminUsername, // Optional for WHMCS 7.2 and later +); +//------------------------------ +################################ +switch (strtolower($CallbackPage)) { + //------------------ + // Debug Invoice + //------------------ + case 'debug': + $invoiceId = (isset($doku_redirect_params['id']) ? $doku_redirect_params['id'] : ''); + $invoiceId = (int)$invoiceId; + $cbInvoiceId = checkCbInvoiceID($invoiceId, $gatewayParams['paymentmethod']); + if ($invoiceId) { + echo ""; + echo "{$invoiceId}"; + echo "
"; + echo $cbInvoiceId; + echo "
"; + $data = array( + //'id' => $invoiceId, + 'invoiceid' => $invoiceId, + ); + $InvoiceData = localAPI('GetInvoice', $data, 'whmcsdoku'); + print_r($InvoiceData); + + + } + exit; + break; + case 'identify': + if ($_SERVER['REQUEST_METHOD'] == 'POST') { + if (count($doku_ipn_params['body']) > 0) { + # DOKU Identify + $dokuparams = array( + 'TRANSIDMERCHANT' => (isset($doku_ipn_params['body']['TRANSIDMERCHANT']) ? $doku_ipn_params['body']['TRANSIDMERCHANT'] : ''), + 'PURCHASECURRENCY' => (isset($doku_ipn_params['body']['PURCHASECURRENCY']) ? $doku_ipn_params['body']['PURCHASECURRENCY'] : ''), + 'CURRENCY' => (isset($doku_ipn_params['body']['CURRENCY']) ? $doku_ipn_params['body']['CURRENCY'] : ''), + 'PAYMENTCHANNEL' => (isset($doku_ipn_params['body']['PAYMENTCHANNEL']) ? $doku_ipn_params['body']['PAYMENTCHANNEL'] : ''), + 'PAYMENTCODE' => (isset($doku_ipn_params['body']['PAYMENTCODE']) ? $doku_ipn_params['body']['PAYMENTCODE'] : ''), + 'AMOUNT' => (isset($doku_ipn_params['body']['AMOUNT']) ? $doku_ipn_params['body']['AMOUNT'] : ''), + 'SESSIONID' => (isset($doku_ipn_params['body']['SESSIONID']) ? $doku_ipn_params['body']['SESSIONID'] : ''), + ); + if ($Identify_Enabled) { + if ($Log_Enabled) { + logTransaction($gatewayParams['paymentmethod'], $dokuparams, "Payment Identify"); + } + } + $REQUEST_METHOD_MSG = "IDENTIFY:Continue"; + } else { + $REQUEST_METHOD_MSG = "STOP: BODY Have no content - Identify"; + } + } else { + $REQUEST_METHOD_MSG = "STOP: POST Method Required - Identify"; + } + break; + case 'review': + $dokuparams = array(); + $REQUEST_METHOD_MSG = "Review Page - Redirect to main-page"; + // Get from Querystring + $dokuparams['TRANSIDMERCHANT'] = (isset($doku_redirect_params['TRANSIDMERCHANT']) ? $doku_redirect_params['TRANSIDMERCHANT'] : ''); + // Get from Postbody + if (count($doku_ipn_params['body']) > 0) { + $dokuparams['TRANSIDMERCHANT'] = (isset($doku_ipn_params['body']['TRANSIDMERCHANT']) ? $doku_ipn_params['body']['TRANSIDMERCHANT'] : $dokuparams['TRANSIDMERCHANT']); + } + $transaction_id_part = substr($dokuparams['TRANSIDMERCHANT'], 0, 14); + if (!$doku_error) { + try { + $transaction_id_part = date_create_from_format('YmdHis', $transaction_id_part); + } catch (Exception $ex) { + $doku_error = true; + $doku_error_msg[] = "Exception error of date-created from formta: {$ex->getMessage()}."; + } + } + if (!$doku_error) { + if (!strtotime(date_format($transaction_id_part, 'Y-m-d H:i:s'))) { + $doku_error = true; + $doku_error_msg[] = "Transaction id part not in Dateformat structured."; + } + } + if (!$doku_error) { + $transaction_id_part = date_format($transaction_id_part, 'YmdHis'); + $merchant_transaction = explode("{$transaction_id_part}", $dokuparams['TRANSIDMERCHANT']); + if (!isset($merchant_transaction[1])) { + $doku_error = true; + $doku_error_msg[] = "There is no Transaction-id from IPN Callback as expected: #DATETIME#TRANSID."; + } + } + if (!$doku_error) { + $invoiceId = trim($merchant_transaction[1]); + /** + * Validate Callback Invoice ID. + * + * Checks invoice ID is a valid invoice number. Note it will count an + * invoice in any status as valid. + * + * Performs a die upon encountering an invalid Invoice ID. + * + * Returns a normalised invoice ID. + * + * @param int $invoiceId Invoice ID + * @param string $gatewayName Gateway Name + **/ + $invoiceId = checkCbInvoiceID($invoiceId, $gatewayParams['paymentmethod']); + if (!$invoiceId) { + $doku_error = true; + $doku_error_msg[] = "invoiceId is not found."; + if ($Log_Enabled) { + logTransaction($gatewayParams['paymentmethod'], $doku_error_msg, "InvoiceId Not Found"); + } + } + } + if (!$doku_error) { + $localApi['data']['id'] = $invoiceId; + $InvoiceData = localAPI($localApi['command'], $localApi['data'], $localApi['username']); + $Redirect_Url = ""; + if (isset($InvoiceData['totalresults'])) { + if (intval($InvoiceData['totalresults']) > 0) { + $GetConfigurationValue = localAPI('GetConfigurationValue', array('setting' => 'SystemURL'), $localApi['username']); + $Redirect_Url .= (isset($GetConfigurationValue['value']) ? $GetConfigurationValue['value'] : ''); + $Redirect_Url .= ((substr($systemUrl, -1) == '/') ? '' : '/'); + $Redirect_Url .= "viewinvoice.php?id={$invoiceId}"; + echo "redirect 01 -
\n"; + //redirecting_page_to_invoice($Redirect_Url) + exit; + } + } else { + $doku_error = true; + $doku_error_msg[] = "Local API Result not get totalresults of InvoiceData from GetOrders()."; + } + } + break; + case 'notify': + case 'updatenotify': + case 'regupdate': + case 'subscription': + default: + if ($_SERVER['REQUEST_METHOD'] == 'POST') { + if (count($doku_ipn_params['body']) > 0) { + # DOKU Notify + $dokuparams = array( + 'PAYMENTDATETIME' => (isset($doku_ipn_params['body']['PAYMENTDATETIME']) ? $doku_ipn_params['body']['PAYMENTDATETIME'] : ''), + 'PURCHASECURRENCY' => (isset($doku_ipn_params['body']['PURCHASECURRENCY']) ? $doku_ipn_params['body']['PURCHASECURRENCY'] : ''), + 'LIABILITY' => (isset($doku_ipn_params['body']['LIABILITY']) ? $doku_ipn_params['body']['LIABILITY'] : ''), + 'PAYMENTCHANNEL' => (isset($doku_ipn_params['body']['PAYMENTCHANNEL']) ? $doku_ipn_params['body']['PAYMENTCHANNEL'] : ''), + 'AMOUNT' => (isset($doku_ipn_params['body']['AMOUNT']) ? $doku_ipn_params['body']['AMOUNT'] : ''), + 'PAYMENTCODE' => (isset($doku_ipn_params['body']['PAYMENTCODE']) ? $doku_ipn_params['body']['PAYMENTCODE'] : ''), + 'MCN' => (isset($doku_ipn_params['body']['MCN']) ? $doku_ipn_params['body']['MCN'] : ''), + 'WORDS' => (isset($doku_ipn_params['body']['WORDS']) ? $doku_ipn_params['body']['WORDS'] : ''), + 'RESULTMSG' => (isset($doku_ipn_params['body']['RESULTMSG']) ? $doku_ipn_params['body']['RESULTMSG'] : ''), + 'VERIFYID' => (isset($doku_ipn_params['body']['VERIFYID']) ? $doku_ipn_params['body']['VERIFYID'] : ''), + 'TRANSIDMERCHANT' => (isset($doku_ipn_params['body']['TRANSIDMERCHANT']) ? $doku_ipn_params['body']['TRANSIDMERCHANT'] : ''), + 'BANK' => (isset($doku_ipn_params['body']['BANK']) ? $doku_ipn_params['body']['BANK'] : ''), + 'APPROVALCODE' => (isset($doku_ipn_params['body']['APPROVALCODE']) ? $doku_ipn_params['body']['APPROVALCODE'] : ''), + 'EDUSTATUS' => (isset($doku_ipn_params['body']['EDUSTATUS']) ? $doku_ipn_params['body']['EDUSTATUS'] : ''), + 'THREEDSECURESTATUS' => (isset($doku_ipn_params['body']['THREEDSECURESTATUS']) ? $doku_ipn_params['body']['THREEDSECURESTATUS'] : ''), + 'VERIFYSCORE' => (isset($doku_ipn_params['body']['VERIFYSCORE']) ? $doku_ipn_params['body']['VERIFYSCORE'] : ''), + 'CURRENCY' => (isset($doku_ipn_params['body']['CURRENCY']) ? $doku_ipn_params['body']['CURRENCY'] : ''), + 'RESPONSECODE' => (isset($doku_ipn_params['body']['RESPONSECODE']) ? $doku_ipn_params['body']['RESPONSECODE'] : ''), + 'CHNAME' => (isset($doku_ipn_params['body']['CHNAME']) ? $doku_ipn_params['body']['CHNAME'] : ''), + 'BRAND' => (isset($doku_ipn_params['body']['BRAND']) ? $doku_ipn_params['body']['BRAND'] : ''), + 'VERIFYSTATUS' => (isset($doku_ipn_params['body']['VERIFYSTATUS']) ? $doku_ipn_params['body']['VERIFYSTATUS'] : ''), + 'SESSIONID' => (isset($doku_ipn_params['body']['SESSIONID']) ? $doku_ipn_params['body']['SESSIONID'] : ''), + // -- Recurring POST + 'CHAINMERCHANT' => (isset($doku_ipn_params['body']['CHAINMERCHANT']) ? $doku_ipn_params['body']['CHAINMERCHANT'] : ''), + 'CUSTOMERID' => (isset($doku_ipn_params['body']['CUSTOMERID']) ? $doku_ipn_params['body']['CUSTOMERID'] : ''), + 'BILLNUMBER' => (isset($doku_ipn_params['body']['BILLNUMBER']) ? $doku_ipn_params['body']['BILLNUMBER'] : ''), + 'CARDNUMBER' => (isset($doku_ipn_params['body']['CARDNUMBER']) ? $doku_ipn_params['body']['CARDNUMBER'] : ''), + 'STATUS' => (isset($doku_ipn_params['body']['STATUS']) ? $doku_ipn_params['body']['STATUS'] : ''), + 'ERRORCODE' => (isset($doku_ipn_params['body']['ERRORCODE']) ? $doku_ipn_params['body']['ERRORCODE'] : ''), + 'MESSAGE' => (isset($doku_ipn_params['body']['MESSAGE']) ? $doku_ipn_params['body']['MESSAGE'] : ''), + 'STATUSTYPE' => (isset($doku_ipn_params['body']['STATUSTYPE']) ? $doku_ipn_params['body']['STATUSTYPE'] : ''), + 'TOKENID' => (isset($doku_ipn_params['body']['TOKENID']) ? $doku_ipn_params['body']['TOKENID'] : ''), + // -- Subscription Get Amount + 'CUSTOMERNAME' => (isset($doku_ipn_params['body']['CUSTOMERNAME']) ? $doku_ipn_params['body']['CUSTOMERNAME'] : ''), + 'CUSTOMEREMAIL' => (isset($doku_ipn_params['body']['CUSTOMEREMAIL']) ? $doku_ipn_params['body']['CUSTOMEREMAIL'] : ''), + 'CUSTOMERHOMEPHONE' => (isset($doku_ipn_params['body']['CUSTOMERHOMEPHONE']) ? $doku_ipn_params['body']['CUSTOMERHOMEPHONE'] : ''), + 'CUSTOMERMOBILEPHONE' => (isset($doku_ipn_params['body']['CUSTOMERMOBILEPHONE']) ? $doku_ipn_params['body']['CUSTOMERMOBILEPHONE'] : ''), + ); + $REQUEST_METHOD_MSG = "NOTIFY-REGISTER:Continue"; + } else { + $doku_error = true; + $REQUEST_METHOD_MSG = "STOP: BODY Have no content"; + $doku_error_msg[] = $REQUEST_METHOD_MSG; + } + } else { + $doku_error = true; + $REQUEST_METHOD_MSG = "STOP: POST Method Required"; + $doku_error_msg[] = $REQUEST_METHOD_MSG; + } + break; + case 'redirect': + # DOKU Params (GET) + $dokuparams = array( + 'PAYMENTDATETIME' => (isset($doku_redirect_params['PAYMENTDATETIME']) ? $doku_redirect_params['PAYMENTDATETIME'] : ''), + 'PURCHASECURRENCY' => (isset($doku_redirect_params['PURCHASECURRENCY']) ? $doku_redirect_params['PURCHASECURRENCY'] : ''), + 'LIABILITY' => (isset($doku_redirect_params['LIABILITY']) ? $doku_redirect_params['LIABILITY'] : ''), + 'PAYMENTCHANNEL' => (isset($doku_redirect_params['PAYMENTCHANNEL']) ? $doku_redirect_params['PAYMENTCHANNEL'] : ''), + 'AMOUNT' => (isset($doku_redirect_params['AMOUNT']) ? $doku_redirect_params['AMOUNT'] : ''), + 'PAYMENTCODE' => (isset($doku_redirect_params['PAYMENTCODE']) ? $doku_redirect_params['PAYMENTCODE'] : ''), + 'MCN' => (isset($doku_redirect_params['MCN']) ? $doku_redirect_params['MCN'] : ''), + 'WORDS' => (isset($doku_redirect_params['WORDS']) ? $doku_redirect_params['WORDS'] : ''), + 'RESULTMSG' => (isset($doku_redirect_params['RESULTMSG']) ? $doku_redirect_params['RESULTMSG'] : ''), + 'VERIFYID' => (isset($doku_redirect_params['VERIFYID']) ? $doku_redirect_params['VERIFYID'] : ''), + 'TRANSIDMERCHANT' => (isset($doku_redirect_params['TRANSIDMERCHANT']) ? $doku_redirect_params['TRANSIDMERCHANT'] : ''), + 'BANK' => (isset($doku_redirect_params['BANK']) ? $doku_redirect_params['BANK'] : ''), + 'STATUSTYPE' => (isset($doku_redirect_params['STATUSTYPE']) ? $doku_redirect_params['STATUSTYPE'] : ''), + 'APPROVALCODE' => (isset($doku_redirect_params['APPROVALCODE']) ? $doku_redirect_params['APPROVALCODE'] : ''), + 'EDUSTATUS' => (isset($doku_redirect_params['EDUSTATUS']) ? $doku_redirect_params['EDUSTATUS'] : ''), + 'THREEDSECURESTATUS' => (isset($doku_redirect_params['THREEDSECURESTATUS']) ? $doku_redirect_params['THREEDSECURESTATUS'] : ''), + 'VERIFYSCORE' => (isset($doku_redirect_params['VERIFYSCORE']) ? $doku_redirect_params['VERIFYSCORE'] : ''), + 'CURRENCY' => (isset($doku_redirect_params['CURRENCY']) ? $doku_redirect_params['CURRENCY'] : ''), + 'RESPONSECODE' => (isset($doku_redirect_params['RESPONSECODE']) ? $doku_redirect_params['RESPONSECODE'] : ''), + 'CHNAME' => (isset($doku_redirect_params['CHNAME']) ? $doku_redirect_params['CHNAME'] : ''), + 'BRAND' => (isset($doku_redirect_params['BRAND']) ? $doku_redirect_params['BRAND'] : ''), + 'VERIFYSTATUS' => (isset($doku_redirect_params['VERIFYSTATUS']) ? $doku_redirect_params['VERIFYSTATUS'] : ''), + 'SESSIONID' => (isset($doku_redirect_params['SESSIONID']) ? $doku_redirect_params['SESSIONID'] : ''), + 'STATUSCODE' => (isset($doku_redirect_params['STATUSCODE']) ? $doku_redirect_params['STATUSCODE'] : ''), + // -- Recurring Params + 'CHAINMERCHANT' => (isset($doku_redirect_params['CHAINMERCHANT']) ? $doku_redirect_params['CHAINMERCHANT'] : ''), + 'CUSTOMERID' => (isset($doku_redirect_params['CUSTOMERID']) ? $doku_redirect_params['CUSTOMERID'] : ''), + 'BILLNUMBER' => (isset($doku_redirect_params['BILLNUMBER']) ? $doku_redirect_params['BILLNUMBER'] : ''), + 'CARDNUMBER' => (isset($doku_redirect_params['CARDNUMBER']) ? $doku_redirect_params['CARDNUMBER'] : ''), + 'STATUS' => (isset($doku_redirect_params['STATUS']) ? $doku_redirect_params['STATUS'] : ''), + 'ERRORCODE' => (isset($doku_redirect_params['ERRORCODE']) ? $doku_redirect_params['ERRORCODE'] : ''), + 'MESSAGE' => (isset($doku_redirect_params['MESSAGE']) ? $doku_redirect_params['MESSAGE'] : ''), + 'STATUSTYPE' => (isset($doku_redirect_params['STATUSTYPE']) ? $doku_redirect_params['STATUSTYPE'] : ''), + 'TOKENID' => (isset($doku_redirect_params['TOKENID']) ? $doku_redirect_params['TOKENID'] : ''), + ); + # DOKU Params (POST) + if (count($doku_ipn_params['body']) > 0) { + foreach ($doku_ipn_params['body'] as $key => $val) { + if (!isset($dokuparams[$key])) { + $dokuparams[$key] = $val; + } else { + if ($dokuparams[$key] != $val) { + $dokuparams[$key] = $val; + } + } + } + } + if (count($doku_redirect_params) > 0) { + $REQUEST_METHOD_MSG = "REDIRECT:Continue"; + } else { + $REQUEST_METHOD_MSG = "STOP: QUERYSTRING Have no content"; + } + break; +} +/* +** +* CONTINUE +** +*/ +$Notify_Type = 0; +switch (strtolower($CallbackPage)) { + case 'notify': + case 'subscripton': + if (!$doku_error) { + if (!empty($dokuparams['STATUSTYPE'])) { + if (!is_string($dokuparams['STATUSTYPE'])) { + $doku_error = true; + $doku_error_msg[] = "STATUS TYPE should be in string format."; + } + } + } + if (!$doku_error) { + switch (strtoupper($dokuparams['STATUSTYPE'])) { + case 'G': + $Notify_Type = 1; // Notify Registration + break; + case 'T': + $Notify_Type = 2; // Notify Update + break; + } + } + break; + default: + // Nothing to do.... + break; +} +/* +** +* CONTINUE +** +*/ +switch (strtolower($CallbackPage)) { + case 'notify': + case 'updatenotify': + case 'regupdate': + default: + if (!$doku_error) { + if ($Log_Enabled) { + switch ($Notify_Type) { + case 0: logTransaction($gatewayParams['paymentmethod'], $dokuparams, 'Payment Notify Process'); break; + case 1: logTransaction($gatewayParams['paymentmethod'], $dokuparams, 'Payment Notify Register'); break; + case 2: logTransaction($gatewayParams['paymentmethod'], $dokuparams, 'Payment Notify Update'); break; + } + } + } + break; + case 'redirect': + if (!$doku_error) { + if ($Log_Enabled) { + switch ($Notify_Type) { + case 0: logTransaction($gatewayParams['paymentmethod'], $dokuparams, 'Payment Redirect Process'); break; + case 1: logTransaction($gatewayParams['paymentmethod'], $dokuparams, 'Payment Redirect Register'); break; + case 2: logTransaction($gatewayParams['paymentmethod'], $dokuparams, 'Payment Redirect Update'); break; + } + } + } + break; + case 'subscription': + if (!$doku_error) { + if ($Log_Enabled) { + logTransaction($gatewayParams['paymentmethod'], $dokuparams, 'Payment Subscription GetAmount'); + } + } + break; + case 'review': + case 'identify': + echo "{$REQUEST_METHOD_MSG}"; + exit; + break; +} +/* +** +* CONTINUE +** +*/ +switch (strtolower($CallbackPage)) { + case 'notify': + case 'updatenotify': + case 'regupdate': + case 'redirect': + case 'subscription': + default: + if (!$doku_error) { + if (is_array($dokuparams['BILLNUMBER']) || is_object($dokuparams['BILLNUMBER'])) { + $doku_error = true; + $doku_error_msg[] = "Array or Object return for BILLNUMBER."; + } + } + if (!$doku_error) { + $transaction_id = $dokuparams['BILLNUMBER']; + $transaction_id_part = substr($dokuparams['BILLNUMBER'], 0, 12); + try { + //$transaction_id_part = DateTime::createFromFormat('YmdHi', $transaction_id_part); + $transaction_id_part = date_create_from_format('YmdHi', $transaction_id_part); + } catch (Exception $ex) { + $doku_error = true; + $doku_error_msg[] = "Exception error of date-created from format: {$ex->getMessage()}."; + } + } + if (!$doku_error) { + if (!strtotime(date_format($transaction_id_part, 'Y-m-d H:i:s'))) { + $doku_error = true; + $doku_error_msg[] = "Transaction id part from billnumber not in Dateformat structured."; + } + } + if (!$doku_error) { + $transaction_id_part = date_format($transaction_id_part, 'YmdHi'); + $merchant_transaction = explode("{$transaction_id_part}", $dokuparams['BILLNUMBER']); + if (!isset($merchant_transaction[1])) { + $doku_error = true; + $doku_error_msg[] = "There is no Transaction-id from IPN Callback as expected: #DATETIME#TRANSID."; + } + } + if (!$doku_error) { + $invoiceId = trim($merchant_transaction[1]); + } + break; +} +/* +** +* CONTINUE +** +*/ +switch (strtolower($CallbackPage)) { + case 'notify': + case 'regupdate': + case 'redirect': + default: + ######################################### + if (!$doku_error) { + /** + * Validate Callback Invoice ID. + * + * Checks invoice ID is a valid invoice number. Note it will count an + * invoice in any status as valid. + * + * Performs a die upon encountering an invalid Invoice ID. + * + * Returns a normalised invoice ID. + * + * @param int $invoiceId Invoice ID + * @param string $gatewayName Gateway Name + **/ + $invoiceId = checkCbInvoiceID($invoiceId, $gatewayParams['paymentmethod']); + if (!$invoiceId) { + $doku_error = true; + $doku_error_msg[] = "invoiceId is not found."; + if ($Log_Enabled) { + logTransaction($gatewayParams['paymentmethod'], $doku_error_msg, "InvoiceId Not Found"); + } + } + } + ######################################## + break; + case 'subscription': + // do nothing.. + break; +} +/* +** +* CONTINUE +** +*/ +switch (strtolower($CallbackPage)) { + case 'notify': + case 'regupdate': + case 'redirect': + case 'subscription': + default: + //-------------------------------------------------------------------- + if (!$doku_error) { + $params_input = array(); + $params_input['mallid'] = (isset($dokuparams['MALLID']) ? $dokuparams['MALLID'] : ''); + $params_input['chainmerchant'] = (isset($dokuparams['CHAINMERCHANT']) ? $dokuparams['CHAINMERCHANT'] : ''); + $params_input['transaction_id'] = (isset($dokuparams['TRANSIDMERCHANT']) ? $dokuparams['TRANSIDMERCHANT'] : ''); + $params_input['transaction_customer'] = (isset($dokuparams['CUSTOMERID']) ? $dokuparams['CUSTOMERID'] : ''); + $params_input['transaction_card'] = (isset($dokuparams['CARDNUMBER']) ? $dokuparams['CARDNUMBER'] : ''); + $params_input['transaction_status'] = (isset($dokuparams['STATUS']) ? $dokuparams['STATUS'] : ''); + $params_input['transaction_error'] = (isset($dokuparams['ERRORCODE']) ? $dokuparams['ERRORCODE'] : ''); + $params_input['transaction_message'] = (isset($dokuparams['MESSAGE']) ? $dokuparams['MESSAGE'] : ''); + $params_input['transaction_type'] = (isset($dokuparams['STATUSTYPE']) ? $dokuparams['STATUSTYPE'] : ''); // G: Notify Registration T: Notify Update + $params_input['transaction_code'] = (isset($dokuparams['RESPONSECODE']) ? $dokuparams['RESPONSECODE'] : ''); + $params_input['transaction_currency'] = (isset($dokuparams['CURRENCY']) ? $dokuparams['CURRENCY'] : ''); + $params_input['transaction_approval'] = (isset($dokuparams['APPROVALCODE']) ? $dokuparams['APPROVALCODE'] : ''); + $params_input['transaction_bank'] = (isset($dokuparams['BANK']) ? $dokuparams['BANK'] : ''); + $params_input['transaction_datetime'] = (isset($dokuparams['PAYMENTDATETIME']) ? $dokuparams['PAYMENTDATETIME'] : ''); + $params_input['words'] = (isset($dokuparams['WORDS']) ? $dokuparams['WORDS'] : ''); + //--- + $params_input['subscription_amount'] = (isset($dokuparams['AMOUNT']) ? $dokuparams['AMOUNT'] : '0.00'); + $params_input['subscription_chainmerchant'] = (isset($dokuparams['CHAINMERCHANT']) ? $dokuparams['CHAINMERCHANT'] : 'NA'); + $params_input['subscription_transaction_id'] = (isset($dokuparams['TRANSIDMERCHANT']) ? $dokuparams['TRANSIDMERCHANT'] : 0); + $params_input['subscription_transaction_bill'] = (isset($dokuparams['BILLNUMBER']) ? $dokuparams['BILLNUMBER'] : 0); + $params_input['subscription_transaction_session'] = (isset($dokuparams['SESSIONID']) ? $dokuparams['SESSIONID'] : ''); + $params_input['subscription_transaction_currency'] = (isset($dokuparams['CURRENCY']) ? $dokuparams['CURRENCY'] : 'IDR'); + $params_input['subscription_transaction_currency'] = substr($params_input['subscription_transaction_currency'], 0, 2); + $params_input['subscription_transaction_status'] = (isset($dokuparams['STATUS']) ? $dokuparams['STATUS'] : ''); + $params_input['subscription_transaction_error'] = (isset($dokuparams['ERRORCODE']) ? $dokuparams['ERRORCODE'] : ''); + $params_input['subscription_transaction_message'] = (isset($dokuparams['MESSAGE']) ? $dokuparams['MESSAGE'] : ''); + $params_input['subscription_transaction_card'] = (isset($dokuparams['CARDNUMBER']) ? $dokuparams['CARDNUMBER'] : ''); + $params_input['subscription_transaction_type'] = (isset($dokuparams['STATUSTYPE']) ? $dokuparams['STATUSTYPE'] : ''); + $params_input['subscription_result_msg'] = (isset($dokuparams['RESULTMSG']) ? $dokuparams['RESULTMSG'] : ''); // SUCCESS | FAILED + $params_input['subscription_transaction_customer'] = (isset($dokuparams['CUSTOMERID']) ? $dokuparams['CUSTOMERID'] : ''); + $params_input['subscription_transaction_token'] = (isset($dokuparams['TOKENID']) ? $dokuparams['TOKENID'] : ''); + $params_input['subscription_transaction_channel'] = (isset($dokuparams['PAYMENTCHANNEL']) ? $dokuparams['PAYMENTCHANNEL'] : ''); + $params_input['subscription_verify_id'] = (isset($dokuparams['VERIFYID']) ? $dokuparams['VERIFYID'] : ''); + $params_input['subscription_verify_score'] = (isset($dokuparams['VERIFYSCORE']) ? $dokuparams['VERIFYSCORE'] : ''); + $params_input['subscription_verify_status'] = (isset($dokuparams['VERIFYSTATUS']) ? $dokuparams['VERIFYSTATUS'] : ''); // NA + $params_input['subscription_words'] = (isset($dokuparams['WORDS']) ? $dokuparams['WORDS'] : ''); + //-- + $params_input['subscription_transaction_customer_name'] = (isset($dokuparams['CUSTOMERNAME']) ? $dokuparams['CUSTOMERNAME'] : ''); + $params_input['subscription_transaction_customer_email'] = (isset($dokuparams['CUSTOMEREMAIL']) ? $dokuparams['CUSTOMEREMAIL'] : ''); + $params_input['subscription_transaction_customer_phone'] = (isset($dokuparams['CUSTOMERHOMEPHONE']) ? $dokuparams['CUSTOMERHOMEPHONE'] : ''); + $params_input['subscription_transaction_customer_mobile'] = (isset($dokuparams['CUSTOMERMOBILEPHONE']) ? $dokuparams['CUSTOMERMOBILEPHONE'] : ''); + } + break; +} +/* +** +* CONTINUE +** +*/ +switch (strtolower($CallbackPage)) { + case 'notify': + case 'regupdate': + if (!$doku_error) { + // Make subscription-notify structured + switch ($Notify_Type) { + case 0: + $CheckNotifyPaymentStructure = $DokuPayment->create_payment_structure('subscription-process', 0, $params_input, $dokuparams); + if ($Log_Enabled) { + logTransaction($gatewayParams['paymentmethod'], $CheckNotifyPaymentStructure, 'Subscription Process Structured'); + } + break; + case 1: + $CheckNotifyPaymentStructure = $DokuPayment->create_payment_structure('subscription-notify', 0, $params_input, $dokuparams); + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $CheckNotifyPaymentStructure, 'Subscription Register Structured'); } + break; + case 2: + $CheckNotifyPaymentStructure = $DokuPayment->create_payment_structure('subscription-update', 0, $params_input, $dokuparams); + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $CheckNotifyPaymentStructure, 'Subscription Update Structured'); } + break; + } + if (!isset($CheckNotifyPaymentStructure['WORDS'])) { + $doku_error = true; + $doku_error_msg[] = "Not get WORDS string from created notify structured."; + } + + } + break; + case 'redirect': + if (!$doku_error) { + // Make subscription-redirect structured + $CheckNotifyPaymentStructure = $DokuPayment->create_payment_structure('redirect', 0, $params_input, $dokuparams); + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $CheckNotifyPaymentStructure, 'Subscription Redirect Structured'); } + if (!isset($CheckNotifyPaymentStructure['WORDS'])) { + $doku_error = true; + $doku_error_msg[] = "Not get WORDS string from created notify structured."; + } + } + if (!$doku_error) { + if (!is_string($params_input['words'])) { + $doku_error = true; + $doku_error_msg[] = "Words should be a string."; + } + } + break; + case 'subscription': + if (!$doku_error) { + try { + $SubscriptionDataStructure = $DokuPayment->create_payment_structure('regsubscription', 0, $params_input, $dokuparams); + } catch (Exception $ex) { + $doku_error = true; + $doku_error_msg[] = "Exception error while get system structure for get subscription amount: {$ex->getMessage()}."; + } + } + if (!$doku_error) { + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $SubscriptionDataStructure, 'Get Subscription Amount'); } + if (!isset($SubscriptionDataStructure['WORDS'])) { + $doku_error = true; + $doku_error_msg[] = "Not get WORDS string from created get subscription amount."; + } + } + if (!$doku_error) { + if (!is_string($params_input['words'])) { + $doku_error = true; + $doku_error_msg[] = "Words should be a string."; + } + } + if (!$doku_error) { + if (strtolower($params_input['words']) !== strtolower($SubscriptionDataStructure['WORDS'])) { + $doku_error = true; + $doku_error_msg[] = "Words should be match to get subscription data."; + } + } + break; +} + + +/* +** +* CONTINUE +** +*/ +$order_id = 0; +$order_num = 0; +$order_status = ''; +switch (strtolower($CallbackPage)) { + case 'notify': + case 'regupdate': + case 'redirect': + // Make more @XMLPaymentStatus params + if (count($dokuparams) > 0) { + foreach ($dokuparams as $key => $val) { + $key = preg_replace("/[^a-zA-Z0-9]+/", "", $key); + if (!empty($key) || ($key != '')) { + $XMLPaymentStatus[$key] = $val; + } + } + } + //------------------------------------ + $Redirect_Url = "/"; + if (!$doku_error) { + If (isset($localApi['data']['id'])) { + unset($localApi['data']['id']); + } + $localApi['data']['invoiceid'] = $invoiceId; + // query localApi from invoiceid + $InvoiceData = localAPI('GetInvoice', $localApi['data'], $localApi['username']); + if (isset($InvoiceData['invoiceid'])) { + if (intval($InvoiceData['invoiceid']) > 0) { + $GetConfigurationValue = localAPI('GetConfigurationValue', array('setting' => 'SystemURL'), $localApi['username']); + $Redirect_Url = (isset($GetConfigurationValue['value']) ? $GetConfigurationValue['value'] : ''); + $Redirect_Url .= ((substr($systemUrl, -1) == '/') ? '' : '/'); + $Redirect_Url .= "viewinvoice.php?id={$invoiceId}"; + } + } else { + $doku_error = true; + $doku_error_msg[] = "Local API Result not get totalresults of InvoiceData from GetInvoice()."; + } + } + $orders_debug = array( + 'order_id' => 0, + 'order_num' => 0, + 'order_status' => '', + ); + if (!$doku_error) { + if (isset($InvoiceData['invoiceid']) && isset($InvoiceData['invoicenum']) && isset($InvoiceData['status'])) { + if (intval($InvoiceData['invoiceid']) > 0) { + $order_id = $InvoiceData['invoiceid']; + $orders_debug['order_id'] = $order_id; + } + if (intval($InvoiceData['invoicenum']) > 0) { + $order_num = $InvoiceData['invoicenum']; + $orders_debug['order_num'] = $order_num; + } + $order_status = (is_string($InvoiceData['status']) ? strtolower($InvoiceData['status']) : ''); + $orders_debug['order_status'] = $order_status; + } else { + $doku_error = true; + $doku_error_msg[] = "Local API Result for GetInvoice() not get proper data as expected."; + } + } + break; + case 'subscription': + if (!$doku_error) { + If (isset($localApi['data']['id'])) { + unset($localApi['data']['id']); + } + $localApi['data']['invoiceid'] = $invoiceId; + $InvoiceData = localAPI('GetInvoice', $localApi['data'], $localApi['username']); + if (isset($InvoiceData['invoiceid'])) { + if (intval($InvoiceData['invoiceid']) > 0) { + $GetConfigurationValue = localAPI('GetConfigurationValue', array('setting' => 'SystemURL'), $localApi['username']); + $Redirect_Url = (isset($GetConfigurationValue['value']) ? $GetConfigurationValue['value'] : ''); + $Redirect_Url .= ((substr($systemUrl, -1) == '/') ? '' : '/'); + $Redirect_Url .= "viewinvoice.php?id={$invoiceId}"; + } + } else { + $doku_error = true; + $doku_error_msg[] = "Local API Result not get totalresults of InvoiceData from GetOrders()."; + } + } + $invoceSubscriptionTotal = ""; + if (!$doku_error) { + if (isset($InvoiceData['total'])) { + $invoceSubscriptionTotal = sprintf("%.2f", floatval($InvoiceData['total'])); + } + } + if (!$doku_error) { + echo $invoceSubscriptionTotal; + } else { + print_r($doku_error_msg); + } + exit; + break; +} +/* +** +* CONTINUE +** +*/ +switch (strtolower($CallbackPage)) { + case 'notify': + case 'regupdate': + + break; +} + + + + + + +//-------------------------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------------------------- +/* +$OrderData = FALSE; +if (isset($localApi['data']['id'])) { + unset($localApi['data']['id']); +} +$localApi['command'] = 'GetOrders'; +$localApi['data']['invoiceid'] = (isset($params['invoiceid']) ? $params['invoiceid'] : ''); +$OrdersData = localAPI($localApi['command'], $localApi['data'], $localApi['username']); +if (isset($OrdersData['orders']['order'])) { + if (count($OrdersData['orders']['order']) > 0) { + foreach ($OrdersData['orders']['order'] as $keval) { + if (isset($keval['invoiceid'])) { + if ((int)$keval['invoiceid'] === (int)$localApi['data']['invoiceid']) { + $OrderData = $keval; + } + } + } + } +} +if (!$error) { + if (!$OrderData) { + $error = true; + $error_msg[] = "No Invoice data from localApi: " . (__METHOD__); + } +} +if ($InvoiceData) { + if (!$doku_error) { + echo ""; + echo "{$invoiceId}"; + echo "\r\n"; + print_r($InvoiceData); + exit; + + + + echo ""; + print_r($localApi); + print_r($orders_debug); + print_r($InvoiceData); + $GetConfigurationValue = localAPI('GetConfigurationValue', array('setting' => 'SystemURL'), $localApi['username']); + print_r($GetConfigurationValue); + exit; + } else { + echo ""; + print_r($doku_error); + exit; + } +} else { + exit("NO INVOICE DATA"); +} +*/ +//-------------------------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------------------------------------- +/* +** +* CONTINUE +** +*/ +switch (strtolower($CallbackPage)) { + case 'notify': + default: + // Only for Notify + //************************************************************************** + //************************************************************************** + if (strtolower($CallbackPage) === strtolower('notify')) { + if (!$doku_error) { + //----------------------------------------- + // check if WORDS is match or not + //----------------------------------------- + if (strtolower($CheckNotifyPaymentStructure['WORDS']) !== strtolower($params_input['words'])) { + $doku_error = true; + $doku_error_msg[] = "Words from Notify-Structured not same with Dokuparams"; + } + } + } + //************************************************************************** + //************************************************************************** + //------------------------------------------------------------------------------------------ + if (!$doku_error) { + //--------------------------------- + // IMPORTANT GLOBAL VARS + //--------------------------------- + $invoiceId = (isset($invoiceId) ? $invoiceId : ''); + $transactionId = False; + /** + * Adding Unique generated Invoice-Id to Transaction-Id + * Got bugs: DOKU always send: + * Constant $transactionId + * Using @$transaction_id_part + */ + switch ($Notify_Type) { + case 0: // Notify process + $transactionId = (isset($CheckNotifyPaymentStructure['APPROVALCODE']) ? $CheckNotifyPaymentStructure['APPROVALCODE'] : ''); + break; + case 1: // Notify register + $transactionId = (isset($CheckNotifyPaymentStructure['BILLNUMBER']) ? $CheckNotifyPaymentStructure['BILLNUMBER'] : ''); + break; + case 2: // Notify update + $transactionId = (isset($CheckNotifyPaymentStructure['BILLNUMBER']) ? $CheckNotifyPaymentStructure['BILLNUMBER'] : ''); + break; + } + $transactionId .= "_"; + switch ($Notify_Type) { + case 0: // Notify process + $transactionId .= (isset($CheckNotifyPaymentStructure['TRANSIDMERCHANT']) ? $CheckNotifyPaymentStructure['TRANSIDMERCHANT'] : ''); + $paymentAmount = (isset($CheckNotifyPaymentStructure['AMOUNT']) ? $CheckNotifyPaymentStructure['AMOUNT'] : 0); + $paymentFee = (isset($CheckNotifyPaymentStructure['FEE']) ? $CheckNotifyPaymentStructure['FEE'] : 0); + $paymentEDU = (isset($CheckNotifyPaymentStructure['EDUSTATUS']) ? $CheckNotifyPaymentStructure['EDUSTATUS'] : 'NA'); // NA (Default) + break; + case 1: // Notify register + $transactionId .= (isset($CheckNotifyPaymentStructure['STATUSTYPE']) ? $CheckNotifyPaymentStructure['STATUSTYPE'] : ''); + $paymentAmount = (isset($InvoiceData['total']) ? $InvoiceData['total'] : 0); + $paymentFee = (isset($CheckNotifyPaymentStructure['FEE']) ? $CheckNotifyPaymentStructure['FEE'] : 0); + $paymentEDU = (isset($CheckNotifyPaymentStructure['EDUSTATUS']) ? $CheckNotifyPaymentStructure['EDUSTATUS'] : 'NA'); // NA (Default) + break; + case 2: // Notify update + $transactionId .= (isset($CheckNotifyPaymentStructure['STATUSTYPE']) ? $CheckNotifyPaymentStructure['STATUSTYPE'] : ''); + $paymentAmount = (isset($InvoiceData['total']) ? $InvoiceData['total'] : 0); + $paymentFee = (isset($CheckNotifyPaymentStructure['FEE']) ? $CheckNotifyPaymentStructure['FEE'] : 0); + $paymentEDU = (isset($CheckNotifyPaymentStructure['EDUSTATUS']) ? $CheckNotifyPaymentStructure['EDUSTATUS'] : 'NA'); // NA (Default) + break; + } + # + switch ($Notify_Type) { + case 0: + $paymentResponseStatus = (isset($dokuparams['RESULTMSG']) ? $dokuparams['RESULTMSG'] : ''); // SUCCESS, FAILED + $paymentResponseCode = (isset($dokuparams['RESPONSECODE']) ? $dokuparams['RESPONSECODE'] : ''); // 00 (Success), Other is failed + $paymentResponseType = (isset($dokuparams['VERIFYSTATUS']) ? $dokuparams['VERIFYSTATUS'] : ''); //APPROVE / REJECT / REVIEW / HIGHRISK + break; + case 1: + $paymentResponseStatus = (isset($dokuparams['STATUS']) ? $dokuparams['STATUS'] : ''); // SUCCESS, FAILED + $paymentResponseCode = (isset($dokuparams['ERRORCODE']) ? $dokuparams['ERRORCODE'] : ''); // 00 (Success), Other is failed + $paymentResponseType = (isset($dokuparams['STATUSTYPE']) ? $dokuparams['STATUSTYPE'] : ''); // G or T + break; + case 2: + $paymentResponseStatus = (isset($dokuparams['STATUS']) ? $dokuparams['STATUS'] : ''); // SUCCESS, FAILED + $paymentResponseCode = (isset($dokuparams['ERRORCODE']) ? $dokuparams['ERRORCODE'] : ''); // 00 (Success), Other is failed + $paymentResponseType = (isset($dokuparams['STATUSTYPE']) ? $dokuparams['STATUSTYPE'] : ''); // G or T + break; + } + switch (strtoupper($paymentResponseStatus)) { + case 'SUCCESS': + case 'VOIDED': + $success = TRUE; + switch ($Notify_Type) { + case 0: + if ((int)$paymentResponseCode > 0) { + $success = FALSE; + $doku_error = true; + $doku_error_msg[] = "RESPONSECODE should be 0"; + } + break; + case 1: + if (strtoupper($paymentResponseType) !== strtoupper('G')) { + $success = FALSE; + $doku_error = true; + $doku_error_msg[] = "Status Type should be G for Notify Registration"; + } + break; + case 2: + if (strtoupper($paymentResponseType) !== strtoupper('T')) { + $success = FALSE; + $doku_error = true; + $doku_error_msg[] = "Status Type should be T for Notify Registration"; + } + break; + } + break; + case 'FAILED': + $success = FALSE; + $doku_error = true; + $doku_error_msg[] = "Payment Response Status is not Success: {$paymentResponseStatus}."; + break; + default: + $success = FALSE; + $doku_error = true; + $doku_error_msg[] = "Un-Expected Payment-Response-Status: (" . (__LINE__) . ") {$paymentResponseStatus}"; + break; + } + } + break; + case 'redirect': + case 'regupdate': + //------------------------------------------------------------------------------------------------------------- + /** + * Check Status Payment: Call DOKU + * Applied only for Redirect-Page not for First Time Notify + * ******************************************************** + */ + //------------------------------------------------------------------------------------------------------------- + if (!$doku_error) { + // Make checking redirect-payment structured + # add transaction-words, transaction-status, transaction-code + $params_input['transaction_words'] = (isset($dokuparams['WORDS']) ? $dokuparams['WORDS'] : ''); + $params_input['transaction_status'] = (isset($dokuparams['STATUSCODE']) ? strval($dokuparams['STATUSCODE']) : ''); // 00 = Success, Other = Failed + $params_input['transaction_channel'] = (isset($dokuparams['PAYMENTCHANNEL']) ? $dokuparams['PAYMENTCHANNEL'] : ''); + $CheckRedirectPaymentStructure = $DokuPayment->create_payment_structure('redirect', 0, $params_input, $dokuparams); + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $CheckRedirectPaymentStructure, 'Subsciption Chek Redirect Structured'); } + if (strtolower($CallbackPage) === strtolower('redirect')) { + //----------------------------------------- + // check if WORDS is match or not (On 'redirect' stage) + //----------------------------------------- + if (strtolower($params_input['transaction_words']) !== strtolower($CheckRedirectPaymentStructure['WORDS'])) { + $doku_error = true; + $doku_error_msg[] = "Words from Redirect-Structured not same with Dokuparams. (" . (__LINE__) . ")"; + redirecting_page_to_invoice($Redirect_Url); + exit; + } + } + } + if (!$doku_error) { + /* + TRANSIDMERCHANT => 2017091216074812 + PAYMENTCHANNEL => 17 + BILLNUMBER => 20170912160712 + AMOUNT => 2469305.00 + WORDS => 6064d5cdc802395df1ffc7bc93c41bb22874322e + SESSIONID => 00dd18b360d7ed1f8c509a19b19be8d4 + CUSTOMERID => 1 + */ + if (!in_array(strtolower($order_status), array('paid', 'pending'))) { + //--------------------------------- + // IMPORTANT GLOBAL VARS + //--------------------------------- + $invoiceId = (isset($invoiceId) ? $invoiceId : ''); + $transactionId = False; + // + // Adding Unique generated Invoice-Id to Transaction-Id + // Got bugs: DOKU always send: + // Constant APPROVALCODE for first time Notify (DOKU Always send same Approval-code foe each invoice-id) + // Using @$merchant_transaction[0] + // + switch ($Notify_Type) { + case 0: + $transactionId = (isset($CheckNotifyPaymentStructure['BILLNUMBER']) ? $CheckNotifyPaymentStructure['BILLNUMBER'] : ''); + $paymentResponseStatus = (isset($dokuparams['RESULTMSG']) ? $dokuparams['RESULTMSG'] : ''); // SUCCESS, FAILED + $paymentResponseCode = (isset($dokuparams['RESPONSECODE']) ? $dokuparams['RESPONSECODE'] : ''); // 00 (Success), Other is failed + $paymentResponseType = (isset($dokuparams['VERIFYSTATUS']) ? $dokuparams['VERIFYSTATUS'] : ''); //APPROVE / REJECT / REVIEW / HIGHRISK + break; + case 1: + $transactionId = (isset($dokuparams['BILLNUMBER']) ? $dokuparams['BILLNUMBER'] : ''); + $paymentResponseStatus = (isset($dokuparams['STATUS']) ? $dokuparams['STATUS'] : ''); // SUCCESS, FAILED + $paymentResponseCode = (isset($dokuparams['ERRORCODE']) ? $dokuparams['ERRORCODE'] : ''); // 00 (Success), Other is failed + $paymentResponseType = (isset($dokuparams['STATUSTYPE']) ? $dokuparams['STATUSTYPE'] : ''); // G or T + break; + case 2: + $transactionId = (isset($dokuparams['BILLNUMBER']) ? $dokuparams['BILLNUMBER'] : ''); + $paymentResponseStatus = (isset($dokuparams['STATUS']) ? $dokuparams['STATUS'] : ''); // SUCCESS, FAILED + $paymentResponseCode = (isset($dokuparams['ERRORCODE']) ? $dokuparams['ERRORCODE'] : ''); // 00 (Success), Other is failed + $paymentResponseType = (isset($dokuparams['STATUSTYPE']) ? $dokuparams['STATUSTYPE'] : ''); // G or T + break; + } + $transactionId .= "_"; + switch ($Notify_Type) { + case 0: + $transactionId .= (isset($CheckNotifyPaymentStructure['TRANSIDMERCHANT']) ? $CheckNotifyPaymentStructure['TRANSIDMERCHANT'] : ''); + $paymentAmount = (isset($dokuparams['AMOUNT']) ? $dokuparams['AMOUNT'] : 0); + $paymentFee = (isset($dokuparams['FEE']) ? $dokuparams['FEE'] : 0); + $paymentEDU = (isset($dokuparams['EDUSTATUS']) ? $dokuparams['EDUSTATUS'] : 'NA'); // NA (Default) + break; + case 1: + $transactionId .= (isset($dokuparams['STATUSTYPE']) ? $dokuparams['STATUSTYPE'] : ''); + $paymentAmount = (isset($InvoiceData['total']) ? $InvoiceData['total'] : 0); + $paymentFee = (isset($CheckRedirectPaymentStructure['FEE']) ? $CheckRedirectPaymentStructure['FEE'] : 0); + $paymentEDU = (isset($CheckRedirectPaymentStructure['EDUSTATUS']) ? $CheckRedirectPaymentStructure['EDUSTATUS'] : 'NA'); // NA (Default) + break; + case 2: + $transactionId .= (isset($dokuparams['STATUSTYPE']) ? $dokuparams['STATUSTYPE'] : ''); + $paymentAmount = (isset($InvoiceData['total']) ? $InvoiceData['total'] : 0); + $paymentFee = (isset($CheckRedirectPaymentStructure['FEE']) ? $CheckRedirectPaymentStructure['FEE'] : 0); + $paymentEDU = (isset($CheckRedirectPaymentStructure['EDUSTATUS']) ? $CheckRedirectPaymentStructure['EDUSTATUS'] : 'NA'); // NA (Default) + break; + } + } else { + redirecting_page_to_invoice($Redirect_Url); + exit; + } + } + if (!$doku_error) { + // Log payment-status + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $dokuparams, "(#{$invoiceId}) " . 'Payment Status From Redirected (Not Paid)'); } + /* + if (strtolower($order_status) !== strtolower('paid')) { + // Make Error if Redirected from Un-Success Payment + $doku_error = true; + $doku_error_msg[] = "Redirected from failed payment: Maybe WHMCS Payment-Gateway-Module not activate payment-check status."; + } + */ + } + //------------------------------------------------------------------------------------------------------------- + break; +} +/* +** +* CONTINUE +** +*/ +switch (strtolower($CallbackPage)) { + case 'notify': + case 'regupdate': + default: + if (!$doku_error) { + //--------------------------------- + /** + * Check Callback Transaction ID. + * + * Performs a check for any existing transactions with the same given + * transaction number. + * + * Performs a die upon encountering a duplicate. + * + * @param string $transactionId Unique Transaction ID + */ + if (strtolower($order_status) !== strtolower('paid')) { + switch ($Notify_Type) { + case 0: + if (!in_array(strtolower($order_status), array('paid', 'draft'))) { + checkCbTransID($transactionId); + } + break; + case 1: + if (!in_array(strtolower($order_status), array('paid', 'draft'))) { + checkCbTransID($transactionId); + } + break; + case 2: + if (!in_array(strtolower($order_status), array('paid', 'draft'))) { + checkCbTransID($transactionId); + } + break; + } + } + } + break; + case 'redirect': + if (!$doku_error) { + //--------------------------------- + /** + * Check Callback Transaction ID. + * + * Performs a check for any existing transactions with the same given + * transaction number. + * + * Performs a die upon encountering a duplicate. + * + * @param string $transactionId Unique Transaction ID + */ + if (strtolower($order_status) !== strtolower('paid')) { + switch ($Notify_Type) { + case 0: + if (!in_array(strtolower($order_status), array('paid'))) { + checkCbTransID($transactionId); + } + break; + case 1: + if (!in_array(strtolower($order_status), array('paid', 'draft'))) { + checkCbTransID($transactionId); + } + break; + case 2: + if (!in_array(strtolower($order_status), array('paid', 'draft'))) { + checkCbTransID($transactionId); + } + break; + } + } + } + break; +} +/* +** +* CONTINUE +** +*/ +switch (strtolower($CallbackPage)) { + // allow only Doku IP Address for payment + case 'notify': + case 'regupdate': + if (!$doku_error) { + $doku_ip_address = '103.10.129.0/24'; + $this_ip_address = (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0'); + if (substr($DokuPayment->get_ip_address($this_ip_address), 0, 10) != substr($doku_ip_address, 0, 10)) { + $doku_error = true; + $doku_error_msg[] = "Invalid IP Address, Not from doku sandbox env: {$DokuPayment->get_ip_address()}"; + $success = FALSE; + } + } + break; + default: + // do nothing + break; +} + +/* +** +* CONTINUE +** +*/ +switch (strtolower($CallbackPage)) { + case 'notify': + case 'regupdate': + default: + if (!$doku_error) { + if ($success) { + /** + * Add Invoice Payment. + * + * Applies a payment transaction entry to the given invoice ID. + * + * @param int $invoiceId Invoice ID + * @param string $transactionId Transaction ID + * @param float $paymentAmount Amount paid (defaults to full balance) + * @param float $paymentFee Payment fee (optional) + * @param string $gatewayModule Gateway module name + */ + $localApi['command'] = 'UpdateInvoice'; + $localApi['data'] = array( + 'invoiceid' => $invoiceId, + 'status' => 'Draft', + ); + if (strtolower($order_status) !== strtolower('paid')) { + switch ($Notify_Type) { + case 0: + $REQUEST_METHOD_MSG = "CONTINUE"; + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $XMLPaymentStatus, 'Success'); } + addInvoicePayment($invoiceId, $transactionId, $paymentAmount, $paymentFee, $gatewayModuleName); + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], "Notify Process", "(#{$invoiceId}) Logger"); } + break; + case 1: + $REQUEST_METHOD_MSG = "CONTINUE"; + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $XMLPaymentStatus, 'Pending: Subscription Register'); } + /* + try { + $InvoiceUpdate = localAPI($localApi['command'], $localApi['data'], $localApi['username']); + logTransaction($gatewayParams['paymentmethod'], $InvoiceUpdate, 'Pending: InvoiceUpdate - Register'); + } catch (Exception $ex) { + $doku_error = true; + $doku_error_msg[] = "Cannot update Invoice Status On Notify: Subscription Register."; + } + */ + addInvoicePayment($invoiceId, $transactionId, $paymentAmount, $paymentFee, $gatewayModuleName); + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], "Notify Register", "(#{$invoiceId}) Logger"); } + break; + case 2: + $REQUEST_METHOD_MSG = "CONTINUE"; + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $XMLPaymentStatus, 'Pending: Subscription Update'); } + /* + try { + $InvoiceUpdate = localAPI($localApi['command'], $localApi['data'], $localApi['username']); + logTransaction($gatewayParams['paymentmethod'], $InvoiceUpdate, 'Pending: InvoiceUpdate - Update'); + } catch (Exception $ex) { + $doku_error = true; + $doku_error_msg[] = "Cannot update Invoice Status On Notify: Subscription Update."; + } + */ + addInvoicePayment($invoiceId, $transactionId, $paymentAmount, $paymentFee, $gatewayModuleName); + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], "Notify Update", "(#{$invoiceId}) Logger"); } + break; + } + } + } + } else { + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], array('STOP' => $doku_error_msg), "(doku_error): Failed on Notify"); } + } + break; + case 'redirect': + if (!$doku_error) { + if ($success) { + /** + * Add Invoice Payment. + * + * Applies a payment transaction entry to the given invoice ID. + * + * @param int $invoiceId Invoice ID + * @param string $transactionId Transaction ID + * @param float $paymentAmount Amount paid (defaults to full balance) + * @param float $paymentFee Payment fee (optional) + * @param string $gatewayModule Gateway module name + */ + $localApi['command'] = 'UpdateInvoice'; + $localApi['data'] = array( + 'invoiceid' => $invoiceId, + 'status' => 'Draft', + ); + if (strtolower($order_status) !== strtolower('paid')) { + switch ($Notify_Type) { + case 0: + $REQUEST_METHOD_MSG = "Subscription Redirect Process"; + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $XMLPaymentStatus, 'Success'); } + addInvoicePayment($invoiceId, $transactionId, $paymentAmount, $paymentFee, $gatewayModuleName); + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], "Redirect Process", "(#{$invoiceId}) Logger"); } + break; + case 1: + $REQUEST_METHOD_MSG = "Subscription Redirect Register"; + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $XMLPaymentStatus, 'Pending: Redirect Register'); } + /* + try { + $InvoiceUpdate = localAPI($localApi['command'], $localApi['data'], $localApi['username']); + } catch (Exception $ex) { + $doku_error = true; + $doku_error_msg[] = "Cannot update Invoice Status On Register: Subscription Register."; + } + */ + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], "Redirect Register", "(#{$invoiceId}) Logger"); } + break; + case 2: + $REQUEST_METHOD_MSG = "Subscription Redirect Update"; + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $XMLPaymentStatus, 'Pending: Redirect Update'); } + /* + try { + $InvoiceUpdate = localAPI($localApi['command'], $localApi['data'], $localApi['username']); + } catch (Exception $ex) { + $doku_error = true; + $doku_error_msg[] = "Cannot update Invoice Status On Register: Subscription Update."; + } + */ + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], "Redirect Update", "(#{$invoiceId}) Logger"); } + break; + } + } + } + } else { + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $doku_error_msg, "(doku_error): Failed on Redirect"); } + } + break; +} +/* +** +* CONTINUE +** +*/ +switch (strtolower($CallbackPage)) { + case 'review': + case 'identify': + if (!$doku_error) { + echo $REQUEST_METHOD_MSG; + } else { + print_r($doku_error_msg); + } + case 'notify': + default: + if (!$doku_error) { + echo $REQUEST_METHOD_MSG; + } else { + echo "STOP\r\n"; + print_r($REQUEST_METHOD_MSG); + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], array('STOP' => $REQUEST_METHOD_MSG), 'DOKU ERROR MSG'); } + } + break; + case 'redirect': + if (!$doku_error) { + if ($Log_Enabled) { logTransaction($gatewayParams['paymentmethod'], $REQUEST_METHOD_MSG, "(#{$invoiceId}) " . 'Echo From Redirect'); } + redirecting_page_to_invoice($Redirect_Url); + } else { + echo ""; + print_r($doku_error_msg); + } + break; +} + + + +/* +** +* CONTINUE +** +*/ +/* +switch (strtolower($CallbackPage)) { + case 'review': + case 'identify': + die(); + break; + case 'redirect': + ############################################################################################################# + # CALL VOID? + ############################################################################################################# + //------------------------------------------------------------------------------------------------------------------- + if ($Void_Enabled) { + if (!$doku_error) { + $VoidParams = array( + 'transaction_id' => (isset($XMLPaymentStatus['TRANSIDMERCHANT']) ? $XMLPaymentStatus['TRANSIDMERCHANT'] : ''), + 'transaction_session' => (isset($XMLPaymentStatus['SESSIONID']) ? $XMLPaymentStatus['SESSIONID'] : ''), + 'transaction_currency' => (isset($XMLPaymentStatus['CURRENCY']) ? $XMLPaymentStatus['CURRENCY'] : '360'), + 'transaction_channel' => (isset($XMLPaymentStatus['PAYMENTCHANNEL']) ? $XMLPaymentStatus['PAYMENTCHANNEL'] : ''), + ); + $createVoidStructure = $DokuPayment->create_payment_structure('void', 0, $VoidParams, $dokuparams); + if (isset($createVoidStructure['WORDS_STRING'])) { + unset($createVoidStructure['WORDS_STRING']); + } + $headers = $DokuPayment->create_curl_headers($DokuPayment->dokupayment_headers); + try { + $create_void = $DokuPayment->create_curl_request('POST', $DokuPayment->endpoint['void'], 'API.Context (http://whmcs.alumniparhata.org) - Change this as you wish.', $headers, $createVoidStructure, 30); + } catch (Exception $ex) { + $doku_error = true; + $doku_error_msg[] = "Error exception for create void: {$ex->getMessage()}."; + throw $ex; + } + } + if (!$doku_error) { + if (!isset($create_void['response']['body'])) { + $doku_error = true; + $doku_error_msg[] = "There is no body response from Void response."; + } + } + if (!$doku_error) { + $StringVoidStatus = trim($create_void['response']['body']); + switch (strtoupper($StringVoidStatus)) { + case 'FAILED': + // Do what to do if Failed VOID + logTransaction($gatewayParams['paymentmethod'], $create_void, "Payment Void: ". strtoupper($StringVoidStatus)); + break; + case 'SUCCESS': + // Do what to do if Success VOID + logTransaction($gatewayParams['paymentmethod'], $create_void, "Payment Void: ". strtoupper($StringVoidStatus)); + break; + default: + // DO what to do if Un-expected VOID + logTransaction($gatewayParams['paymentmethod'], $create_void, "Payment Void: UN-EXPECTED ({$StringVoidStatus})"); + break; + } + } + } + ############################################################################################################# + //------------------------------------------------------------------------------------------------------------------- + if (!$doku_error) { + switch (strtoupper($paymentResponseStatus)) { + case 'SUCCESS': + $success = TRUE; + break; + case 'VOIDED': + if ($paymentResponseCode == '00') { + $success = TRUE; + } else { + $success = FALSE; + $doku_error = true; + $doku_error_msg[] = "Payment Response Code is Not : 00."; + } + break; + case 'FAILED': + $success = FALSE; + $doku_error = true; + $doku_error_msg[] = "Payment Response Status is not Success: {$paymentResponseStatus}."; + break; + default: + $success = FALSE; + $doku_error = true; + $doku_error_msg[] = "Un-Expected Payment-Response-Status on Line (" . (__LINE__) . "): {$paymentResponseStatus}"; + $doku_error_msg['XMLPaymentStatus'] = $XMLPaymentStatus; + break; + } + } + if (!$doku_error) { + if (strtolower($order_status) !== strtolower('paid')) { + $REQUEST_METHOD_MSG = "REDIRECT:Continue"; + } else { + echo "redirect - 3
\n"; + echo $Redirect_Url; + // redirecting_page_to_invoice($Redirect_Url); + exit; + } + } + break; + case 'notify': + default: + $REQUEST_METHOD_MSG = "CONTINUE"; + break; +} +*/ diff --git a/modules/gateways/dokuhosted.php b/modules/gateways/dokuhosted.php new file mode 100644 index 0000000..bb92af0 --- /dev/null +++ b/modules/gateways/dokuhosted.php @@ -0,0 +1,1568 @@ + 'DOKU Payment Gateway - Indonesia', + 'APIVersion' => '1.2', // Use API Version 1.1 + 'DisableLocalCredtCardInput' => true, + 'TokenisedStorage' => false, + ); +} + +//--------------- +// URL show to admin page +Class dokuhosted_DokuAdmin { + public static $notify = false; + public static $redirect = false; + public static $review = false; + public static $identify = false; + public static $DOKUCONFIGS; + public function __construct($configs = array()) { + $this->set_protocol(self::getDokuPaymentProtocol()); + $this->protocol = (isset($this->protocol) ? $this->protocol : $this->get_protocol()); + $this->set_hostname(self::getDokuPaymentHost()); + $this->hostname = (isset($this->hostname) ? $this->hostname : $this->get_hostname()); + $this->set_url('notify', "{$this->protocol}{$this->hostname}modules/gateways/callback/dokuhosted.php?page=notify"); + $this->set_url('redirect', "{$this->protocol}{$this->hostname}modules/gateways/callback/dokuhosted.php?page=redirect"); + $this->set_url('review', "{$this->protocol}{$this->hostname}modules/gateways/callback/dokuhosted.php?page=review"); + $this->set_url('identify', "{$this->protocol}{$this->hostname}modules/gateways/callback/dokuhosted.php?page=identify"); + // Set GLOBAL $DOKUCONFIGS + self::$DOKUCONFIGS = $configs; + } + public static function getDokuPaymentConfigs($Vars) { + $configs = array(); + if (!isset(self::$DOKUCONFIGS)) { + return false; + } + switch (strtolower($Vars)) { + case 'channels': + $configs = (isset(self::$DOKUCONFIGS['paymentchannels']) ? self::$DOKUCONFIGS['paymentchannels'] : NULL); + break; + case 'acquirers': + $configs = (isset(self::$DOKUCONFIGS['paymentacquirers']) ? self::$DOKUCONFIGS['paymentacquirers'] : NULL); + break; + case 'tenors': + $configs = (isset(self::$DOKUCONFIGS['paymenttenors']) ? self::$DOKUCONFIGS['paymenttenors'] : NULL); + break; + } + return $configs; + } + public static function getDokuPaymentProtocol() { + if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) { + if ( $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ) { + $_SERVER['HTTPS'] = 'on'; + $_SERVER['SERVER_PORT'] = 443; + } + } + $protocol = 'http://'; + if (isset($_SERVER['HTTPS'])) { + $protocol = (($_SERVER['HTTPS'] == 'on') ? 'https://' : 'http'); + } else { + $protocol = (isset($_SERVER["SERVER_PROTOCOL"]) ? $_SERVER["SERVER_PROTOCOL"] : 'http'); + $protocol = ((strtolower(substr($protocol, 0, 5)) =='https') ? 'https://': 'http://'); + } + return $protocol; + } + public static function getDokuPaymentHost() { + $currentPath = (isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : ''); + $pathInfo = pathinfo(dirname($currentPath)); + $hostName = (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''); + $return = $hostName; + $return .= ((substr($hostName, -1) == '/') ? '' : '/'); + return $return; + } + public static function _GET(){ + $__GET = array(); + $request_uri = ((isset($_SERVER['REQUEST_URI']) && (!empty($_SERVER['REQUEST_URI']))) ? $_SERVER['REQUEST_URI'] : '/'); + $_get_str = explode('?', $request_uri); + if( !isset($_get_str[1]) ) return $__GET; + $params = explode('&', $_get_str[1]); + foreach ($params as $p) { + $parts = explode('=', $p); + $__GET[$parts[0]] = isset($parts[1]) ? $parts[1] : ''; + } + return $__GET; + } + public function set_hostname($hostname) { + $this->hostname = $hostname; + return $this; + } + public function get_hostname() { + return $this->hostname; + } + public function set_protocol($protocol) { + $this->protocol = $protocol; + return $this; + } + public function get_protocol() { + return $this->protocol; + } + public static function set_url($type, $url) { + switch (strtolower($type)) { + case 'notify': + default: + self::$notify = $url; + break; + case 'redirect': + self::$redirect = $url; + break; + case 'review': + self::$review = $url; + break; + case 'identify': + self::$identify = $url; + break; + } + } +} +// Start new DokuAdmin instance +/* +error_reporting(E_ALL); +ini_set('display_startup_errors', true); +ini_set('display_errors', true); +*/ +// Include @DOKUCONFIGS +$configfile = (dirname(__FILE__). '/dokuhosted/dokuhosted-config.php'); +if (!file_exists($configfile)) { + Exit("Required configs file does not exists."); +} +require($configfile); +if (!isset($DOKUCONFIGS)) { + Exit("There is no DOKUCONFIGS of included config file."); +} +$DokuAdmin = new dokuhosted_DokuAdmin($DOKUCONFIGS); +/** + * Define gateway configuration options. + * + * The fields you define here determine the configuration options that are + * presented to administrator users when activating and configuring your + * payment gateway module for use. + * + * Supported field types include: + * * text + * * password + * * yesno + * * dropdown + * * radio + * * textarea + * + * Examples of each field type and their possible configuration parameters are + * provided in the sample function below. + * + * @return array + */ +// Require doku-payment class instance +require('dokuhosted/dokuhosted-whmcs.php'); +function dokuhosted_config() { + $configs = array( + // the friendly display name for a payment gateway should be + // defined here for backwards compatibility + 'FriendlyName' => array( + 'Type' => 'System', + 'Value' => 'DOKU - Standard Payment', + 'Description' => 'DOKU is an online payment platform that processes payments through many different methods, including Credit Card, ATM Transfer and DOKU Wallet. Check us out on http://www.doku.com', + ), + 'Pembatas-Description-Payment-Gateway' => array( + 'FriendlyName' => '', + 'Type' => 'hidden', + 'Size' => '72', + 'Default' => '', + 'Description' => ' DOKU is an online payment platform that processes payments through many different methods, including Credit Card, ATM Transfer and DOKU Wallet. Check us out on http://www.doku.com', + ), + 'Description-Payment-Gateway' => array( + 'FriendlyName' => 'Description', + 'Type' => 'textarea', + 'Rows' => '8', + 'Cols' => '72', + 'Default' => 'DOKU is an online payment platform that processes payments through many different methods, including Credit Card, ATM Transfer and DOKU Wallet. Check us out on http://www.doku.com', + 'Description' => '', + ), + // a text field type allows for single line text input + # Development + //------------- + 'Pembatas-Sandbox' => array( + "FriendlyName" => "(*)", + "Type" => 'hidden', + "Size" => "64", + "Default" => '', + "Description" => 'Development Params', + ), + //------------- + 'MallId' => array( + 'FriendlyName' => 'Development: Mall ID', + 'Type' => 'text', + 'Size' => '25', + 'Default' => '', + 'Description' => 'Enter your Mall ID here', + ), + /* + 'ShopName' => array( + 'FriendlyName' => 'Sandbox: Shop Name', + 'Type' => 'text', + 'Size' => '25', + 'Default' => '', + 'Description' => 'Enter Shop Name here', + ), + */ + 'ChainMerchant' => array( + 'FriendlyName' => 'Development: Chain Merchant (Default is: NA)', + 'Type' => 'text', + 'Size' => '25', + 'Default' => 'NA', + 'Description' => 'Enter Chain Merchant (Default is: NA)', + ), + 'SharedKey' => array( + 'FriendlyName' => 'Development: Shared Key', + 'Type' => 'text', + 'Size' => '25', + 'Default' => '', + 'Description' => 'Enter Shared Key you got from DOKU Dashboard', + ), + //------------- + 'Pembatas-Live' => array( + "FriendlyName" => "(*)", + "Type" => 'hidden', + "Size" => "64", + "Default" => '', + "Description" => 'Production Params', + ), + //------------- + # Live + 'MallId_Live' => array( + 'FriendlyName' => '(*)Production: Mall ID', + 'Type' => 'text', + 'Size' => '25', + 'Default' => '', + 'Description' => 'Enter your Mall ID here', + ), + 'ChainMerchant_Live' => array( + 'FriendlyName' => '(*)Production: Chain Merchant Name (Default is: NA)', + 'Type' => 'text', + 'Size' => '25', + 'Default' => 'NA', + 'Description' => 'Enter Chain Merchant Name (Default is: NA)', + ), + 'SharedKey_Live' => array( + 'FriendlyName' => '(*)Production: Shared Key', + 'Type' => 'text', + 'Size' => '25', + 'Default' => '', + 'Description' => 'Enter Shared Key you got from DOKU Dashboard', + ), + //------------- + 'Pembatas-Global-Params' => array( + "FriendlyName" => "", + "Type" => 'hidden', + "Size" => "64", + "Default" => '', + "Description" => 'Global Params', + ), + //------------- + # GLOBAL + // the dropdown field type renders a select menu of options (LOGGER) + 'Log-Enabled' => array( + 'FriendlyName' => "Use Logger on Transaction Log? (Billing > Gateway Log)", + 'Type' => "yesno", + 'Description' => "Tick this box to enable Logging", + ), + // the dropdown field type renders a select menu of options + 'Environment' => array( + 'FriendlyName' => 'Environment Mode', + 'Type' => 'dropdown', + 'Options' => array( + 'sandbox' => 'Development', + 'live' => 'Production', + ), + 'Description' => 'Choose environment development or production', + ), + "EDU-Enabled" => array( + 'FriendlyName' => "Use EDU?", + 'Type' => "yesno", + 'Description' => "Tick this box to enable EDU", + ), + "Identify-Enabled" => array( + 'FriendlyName' => "Use Identify?", + 'Type' => "yesno", + 'Description' => "Tick this box to enable DOKU Identify", + ), + //"Void-Enabled" => array( + // 'FriendlyName' => "Use Void?", + // 'Type' => "yesno", + // 'Description' => "Tick this box to enable Payment Void", + // ), + # + "PaymentCheck-Enabled" => array( + 'FriendlyName' => "Enable Payment Check During Notify and Redirect", + 'Type' => "yesno", + 'Description' => "Tick this box to enable Payment Check (We recomended you enabled payment-check to verified payment)", + ), + 'URL-Notify' => array( + "FriendlyName" => "Enter your URL Notify to DOKU Dasboard", + "Type" => 'hidden', + "Size" => "64", + "Default" => dokuhosted_DokuAdmin::$notify, + "Description" => dokuhosted_DokuAdmin::$notify, + ), + 'URL-Redirect' => array( + "FriendlyName" => "Enter your URL Redirect to DOKU Dasboard", + "Type" => 'hidden', + "Size" => "64", + "Default" => dokuhosted_DokuAdmin::$redirect, + "Description" => dokuhosted_DokuAdmin::$redirect, + ), + 'URL-Review' => array( + "FriendlyName" => "Enter your URL Review to DOKU Dasboard", + "Type" => 'hidden', + "Size" => "64", + "Default" => dokuhosted_DokuAdmin::$review, + "Description" => dokuhosted_DokuAdmin::$review, + ), + 'URL-Identify' => array( + "FriendlyName" => "Enter your URL Identify to DOKU Dasboard", + "Type" => 'hidden', + "Size" => "64", + "Default" => dokuhosted_DokuAdmin::$identify, + "Description" => dokuhosted_DokuAdmin::$identify, + ), + // + 'Local-Api-Admin-Username' => array( + 'FriendlyName' => '(*) WHMCS Admin Username for using WHMCS::localAPI().', + 'Type' => 'text', + 'Size' => '22', + 'Default' => '', + 'Description' => 'Enter your WHMCS Admin Username for using WHMCS::localAPI().', + ), + //---------------------------------------------------------------------------- + 'Pembatas-Payment-Channel' => array( + "FriendlyName" => "(*) Select Enabled Payment Channel", + "Type" => 'hidden', + "Size" => "64", + "Default" => '', + "Description" => 'Please tick to enable payment channels', + ), + //----------------------------------------------------------------------------- + + ); + // Add payment-channels + $getDokuPaymentChannels = dokuhosted_DokuAdmin::getDokuPaymentConfigs('channels'); + if (count($getDokuPaymentChannels) > 0) { + foreach ($getDokuPaymentChannels as $val) { + $payment_channel_key = "Payment-Channel-"; + $payment_channel_key .= (isset($val[0]) ? $val[0] : '00'); + $configs[$payment_channel_key] = array( + 'FriendlyName' => '', + 'Type' => 'yesno', + 'Default' => (isset($val[0]) ? $val[0] : '00'), + 'Description' => (isset($val[1]) ? $val[1] : 'All'), + ); + } + } + //------------------------------------------------------------------------------------ + // INSTALLMENT PAYMENT (Credit Card) + //------------------------------------------------------------------------------------ + $configs["Installment-Enabled"] = array( + 'FriendlyName' => 'Use Installment', + 'Type' => 'dropdown', + 'Options' => array( + 'SALE' => 'SALE', + 'ONUS' => 'ONUS INSTALLMENT', + 'OFFUS' => 'OFFUS INSTALLEMENT', + ), + ); + //------------------------------------------------------ + $configs['Pembatas-Payment-Acquirer-Bank'] = array( + "FriendlyName" => "::", + "Type" => 'hidden', + "Size" => "64", + "Default" => '', + "Description" => 'ACQUIRER BANK FOR INSTALLMENT', + ); + //-------------- + // GLOBAL OBJECT FOR PROMO OF EACH BANK TENORS + $GLOBAL_ACQUIRER_BANKS = array( + 'onus' => [], + 'offus' => [], + ); + # Get Banks + $getDokuPaymentAcquirers = dokuhosted_DokuAdmin::getDokuPaymentConfigs('acquirers'); + //----------------------- + // ON US INSTALLMENT + //----------------------- + $configs['Pembatas-Payment-Acquirer-Bank-Onus'] = array( + "FriendlyName" => "(*) Payment Acquirer Banks (ON US)", + "Type" => 'hidden', + "Size" => "64", + "Default" => '', + "Description" => 'Please tick to enable payment acquirers bank', + ); + if (isset($getDokuPaymentAcquirers['onus'])) { + if (count($getDokuPaymentAcquirers['onus']) > 0) { + foreach ($getDokuPaymentAcquirers['onus'] as $keval) { + $bank_acquirer_code = (isset($keval[0]) ? $keval[0] : '100'); // 100 (BNI as Default Bank) + $bank_acquirer_name = (isset($keval[1]) ? $keval[1] : 'Bank BNI'); // 100 (BNI as Default Bank) + $GLOBAL_ACQUIRER_BANKS['onus'][] = array( + 'code' => $bank_acquirer_code, + 'name' => $bank_acquirer_name, + 'tenor' => array(), + ); + } + } + } + if (count($GLOBAL_ACQUIRER_BANKS['onus']) > 0) { + foreach ($GLOBAL_ACQUIRER_BANKS['onus'] as $k => $val) { + # Get Tenors + $getDokuPaymentTenors = dokuhosted_DokuAdmin::getDokuPaymentConfigs('tenors'); + if (count($getDokuPaymentTenors) > 0) { + foreach ($getDokuPaymentTenors as $keval) { + $tenor_acquirer_code = (isset($keval[0]) ? $keval[0] : '03'); // (03 Months as Default Tenor) + $tenor_acquirer_name = (isset($keval[1]) ? $keval[1] : '03 Bulan'); // (03 Months as Default Tenor) + $val_tenor = array( + 'code' => $tenor_acquirer_code, + 'name' => $tenor_acquirer_name, + 'promo' => '', + ); + $GLOBAL_ACQUIRER_BANKS['onus'][$k]['tenor'][] = $val_tenor; + } + } + } + } + # Build into @configs + if (count($GLOBAL_ACQUIRER_BANKS['onus']) > 0) { + foreach ($GLOBAL_ACQUIRER_BANKS['onus'] as $key => $val) { + // Bank installment key + $bank_installment_key = "Bank-Installment-Acquirer-Onus-"; + $bank_installment_key .= (isset($val['code']) ? $val['code'] : '100'); // 100 = BNI + # add to configs + $configs[$bank_installment_key] = array( + 'FriendlyName' => '', + 'Type' => 'yesno', + 'Default' => (isset($val['code']) ? $val['code'] : '100'), // 100 = BNI + 'Description' => "" . (isset($val['name']) ? $val['name'] : 'Bank BNI..?') . "", // BNI as Default + ); + $bank_installment_code = (isset($val['code']) ? (string)$val['code'] : ''); + if (strtolower($bank_installment_code) === strtolower('100')) { + $configs["{$bank_installment_key}-00"] = array( + 'FriendlyName' => 'Installment Promo Code For ' . (isset($val['name']) ? $val['name'] : 'Bank BNI..?'), + 'Type' => 'text', + 'Size' => '22', + 'Default' => '', + 'Description' => 'Insert Promo Code For ' . (isset($val['name']) ? $val['name'] : 'Bank BNI..?'), + ); + } + // Bank promo for each available tenors + if (isset($val['tenor'])) { + if (count($val['tenor']) > 0) { + foreach ($val['tenor'] as $keval) { + $bank_installment_tenor = $bank_installment_key; + $bank_installment_tenor .= "-"; + $bank_installment_tenor .= (isset($keval['code']) ? $keval['code'] : '03'); // 03 Months as default + # add to configs (tenor) + $configs[$bank_installment_tenor] = array( + 'FriendlyName' => '', + 'Type' => 'yesno', + 'Default' => (isset($keval['code']) ? $keval['code'] : '03'), + 'Description' => (isset($keval['name']) ? $keval['name'] : '03 Bulan'), + ); + $bank_installment_tenor_promo = "{$bank_installment_tenor}-PromoId"; + # add to configs (promo) + // except BNI + if (strtolower($bank_installment_code) !== strtolower('100')) { + $configs[$bank_installment_tenor_promo] = array( + 'FriendlyName' => 'Installment Promo Code For ' . (isset($keval['name']) ? $keval['name'] : '03 Bulan'), + 'Type' => 'text', + 'Size' => '22', + 'Default' => '', + 'Description' => 'Insert Promo Code For ' . (isset($keval['name']) ? $keval['name'] : '03 Bulan') . ' On ' . (isset($val['name']) ? $val['name'] : 'Bank BNI..?'), + ); + } else { + $configs[$bank_installment_tenor_promo] = array( + 'FriendlyName' => '', + 'Type' => 'hidden', + 'Size' => '22', + 'Default' => '001', + 'Description' => '', + ); + } + } + } + } + } + } + //----------------------- + // OFF US INSTALLMENT + //----------------------- + $configs['Pembatas-Payment-Acquirer-Bank-Offus'] = array( + "FriendlyName" => "(*) Payment Acquirer Banks (OFF US)", + "Type" => 'hidden', + "Size" => "64", + "Value" => '', + "Description" => 'Please tick to enable payment acquirers bank', + ); + if (isset($getDokuPaymentAcquirers['offus'])) { + if (count($getDokuPaymentAcquirers['offus']) > 0) { + foreach ($getDokuPaymentAcquirers['offus'] as $keval) { + $bank_acquirer_code = (isset($keval[0]) ? $keval[0] : '100'); // 100 (BNI as Default Bank) + $bank_acquirer_name = (isset($keval[1]) ? $keval[1] : 'Bank BNI'); // 100 (BNI as Default Bank) + $GLOBAL_ACQUIRER_BANKS['offus'][] = array( + 'code' => $bank_acquirer_code, + 'name' => $bank_acquirer_name, + 'tenor' => array(), + ); + } + } + } + if (count($GLOBAL_ACQUIRER_BANKS['offus']) > 0) { + foreach ($GLOBAL_ACQUIRER_BANKS['offus'] as $k => $val) { + # Get Tenors + $getDokuPaymentTenors = dokuhosted_DokuAdmin::getDokuPaymentConfigs('tenors'); + if (count($getDokuPaymentTenors) > 0) { + foreach ($getDokuPaymentTenors as $keval) { + $tenor_acquirer_code = (isset($keval[0]) ? $keval[0] : '03'); // (03 Months as Default Tenor) + $tenor_acquirer_name = (isset($keval[1]) ? $keval[1] : '03 Bulan'); // (03 Months as Default Tenor) + $val_tenor = array( + 'code' => $tenor_acquirer_code, + 'name' => $tenor_acquirer_name, + 'promo' => '', + ); + $GLOBAL_ACQUIRER_BANKS['offus'][$k]['tenor'][] = $val_tenor; + } + } + } + } + # Build into @configs + if (count($GLOBAL_ACQUIRER_BANKS['offus']) > 0) { + foreach ($GLOBAL_ACQUIRER_BANKS['offus'] as $key => $val) { + // Bank installment key + $bank_installment_key = "Bank-Installment-Acquirer-Offus-"; + $bank_installment_key .= (isset($val['code']) ? $val['code'] : '100'); // 100 = BNI + // For OFFUS because same $val['code'] create unique identify by index loop + $bank_installment_key .= "-{$key}"; + # add to configs + $configs[$bank_installment_key] = array( + 'FriendlyName' => '', + 'Type' => 'yesno', + 'Default' => (isset($val['code']) ? $val['code'] : '100'), // 100 = BNI + 'Description' => "" . (isset($val['name']) ? $val['name'] : 'Bank BNI..?') . "", // BNI as Default + ); + $bank_installment_code = (isset($val['code']) ? (string)$val['code'] : ''); + if (strtolower($bank_installment_code) === strtolower('000')) { + $configs["{$bank_installment_key}-00"] = array( + 'FriendlyName' => 'Installment Promo Code For ' . (isset($val['name']) ? $val['name'] : 'Bank BNI..?'), + 'Type' => 'text', + 'Size' => '22', + 'Default' => '', + 'Description' => 'Insert Promo Code For ' . (isset($val['name']) ? $val['name'] : 'Bank BNI..?'), + ); + } + // Bank promo for each available tenors + if (isset($val['tenor'])) { + if (count($val['tenor']) > 0) { + foreach ($val['tenor'] as $keval) { + $bank_installment_tenor = $bank_installment_key; + $bank_installment_tenor .= "-"; + $bank_installment_tenor .= (isset($keval['code']) ? $keval['code'] : '03'); // 03 Months as default + # add to configs (tenor) + $configs[$bank_installment_tenor] = array( + 'FriendlyName' => '', + 'Type' => 'yesno', + 'Default' => (isset($keval['code']) ? $keval['code'] : '03'), + 'Description' => (isset($keval['name']) ? $keval['name'] : '03 Bulan'), + ); + $bank_installment_tenor_promo = "{$bank_installment_tenor}-PromoId"; + # add to configs (promo) + // except BNI + if (strtolower($bank_installment_code) !== strtolower('000')) { + $configs[$bank_installment_tenor_promo] = array( + 'FriendlyName' => 'Installment Promo Code For ' . (isset($keval['name']) ? $keval['name'] : '03 Bulan'), + 'Type' => 'text', + 'Size' => '22', + 'Default' => '', + 'Description' => 'Insert Promo Code For ' . (isset($keval['name']) ? $keval['name'] : '03 Bulan') . ' On ' . (isset($val['name']) ? $val['name'] : 'Bank BNI..?'), + ); + } else { + $configs[$bank_installment_tenor_promo] = array( + 'FriendlyName' => '', + 'Type' => 'hidden', + 'Size' => '22', + 'Default' => '001', + 'Description' => '', + ); + } + } + } + } + } + } + //---------------------------------------------------------------------------------------------- + /* + $configs['Custom-Data-To-Showing'] = array( + 'FriendlyName' => 'Textarea Field', + 'Type' => 'textarea', + 'Rows' => '3', + 'Cols' => '60', + 'Default' => print_r(array('g' => $GLOBAL_ACQUIRER_BANKS, 'b' => $getDokuPaymentAcquirers), true), + 'Description' => 'Freeform multi-line text input field', + ); + */ + //------------------------------------------------------------------------------------ + return $configs; +} + +/** + * Payment link. + * + * Required by third party payment gateway modules only. + * + * Defines the HTML output displayed on an invoice. Typically consists of an + * HTML form that will take the user to the payment gateway endpoint. + * + * @param array $params Payment Gateway Module Parameters + * + * @see https://developers.whmcs.com/payment-gateways/third-party-gateway/ + * + * @return string + */ +function dokuhosted_link($params) { + $Log_Enabled = FALSE; + if (isset($params['Log-Enabled'])) { + $Log_Enabled = ((strtolower($params['Log-Enabled']) == 'on') ? TRUE : FALSE); + } + /* + echo ""; + print_r($params); + exit; + */ + $Environment = (isset($params['Environment']) ? $params['Environment'] : 'sandbox'); // Sandbox as Default-Environment + if (!is_string($Environment) && ((!is_array($Environment)) || (!is_object($Environment)))) { + if (strtolower($Environment) === strtolower('live')) { + // Gateway Configuration Parameters + $MallId = (isset($params['MallId_Live']) ? $params['MallId_Live'] : ''); + $ShopName = (isset($params['ShopName_Live']) ? $params['ShopName_Live'] : ''); + $ChainMerchant = (isset($params['ChainMerchant_Live']) ? $params['ChainMerchant_Live'] : 'NA'); + $SharedKey = (isset($params['SharedKey_Live']) ? $params['SharedKey_Live'] : ''); + } else { + // Gateway Configuration Parameters + $MallId = (isset($params['MallId']) ? $params['MallId'] : ''); + $ShopName = (isset($params['ShopName']) ? $params['ShopName'] : ''); + $ChainMerchant = (isset($params['ChainMerchant']) ? $params['ChainMerchant'] : 'NA'); + $SharedKey = (isset($params['SharedKey']) ? $params['SharedKey'] : ''); + } + } else { + // Gateway Configuration Parameters + $MallId = (isset($params['MallId']) ? $params['MallId'] : ''); + $ShopName = (isset($params['ShopName']) ? $params['ShopName'] : ''); + $ChainMerchant = (isset($params['ChainMerchant']) ? $params['ChainMerchant'] : 'NA'); + $SharedKey = (isset($params['SharedKey']) ? $params['SharedKey'] : ''); + } + $LocalApiAdminUsername = (isset($params['Local-Api-Admin-Username']) ? $params['Local-Api-Admin-Username'] : ''); + //$ExchangeCurrency = (isset($params['ExchangeCurrency']) ? $params['ExchangeCurrency'] : ''); + //--------- + // Create DokuPayment Instance + //--------- + $DokuConfigs = array( + 'isofile' => 'dokuhosted/assets/iso3166.json', + 'merchant' => array( + 'mallid' => $MallId, + 'shopname' => $ShopName, + 'chainmerchant' => $ChainMerchant, + 'sharedkey' => $SharedKey, + ), + 'endpoint' => (is_string($Environment) ? strtolower($Environment) : 'sandbox'), // sandbox as default + ); + ## + # DokuPayment Instance + ## + $DokuPayment = new dokuhosted_DokuPayment($DokuConfigs); + //----------------------------------------------------- + // Invoice Parameters + $invoiceId = $params['invoiceid']; + $description = $params["description"]; + $amount = $params['amount']; + $currencyCode = $params['currency']; + // Client Parameters + $firstname = $params['clientdetails']['firstname']; + $lastname = $params['clientdetails']['lastname']; + $fullname = $params['clientdetails']['fullname']; + $email = $params['clientdetails']['email']; + $address1 = $params['clientdetails']['address1']; + $address2 = $params['clientdetails']['address2']; + $city = $params['clientdetails']['city']; + $state = $params['clientdetails']['state']; + $postcode = $params['clientdetails']['postcode']; + $country = $params['clientdetails']['country']; + $phone = $params['clientdetails']['phonenumber']; + // System Parameters + $companyName = $params['companyname']; + $systemUrl = $params['systemurl']; + $returnUrl = $params['returnurl']; + $langPayNow = $params['langpaynow']; + $moduleDisplayName = $params['name']; + $moduleName = $params['paymentmethod']; + $whmcsVersion = $params['whmcsVersion']; + // POSTFIELDS + $postfields = array(); + $postfields['username'] = $email; + $postfields['invoice_id'] = $invoiceId; + $postfields['description'] = $description; + $postfields['amount'] = $amount; + $postfields['currency'] = $currencyCode; + $postfields['first_name'] = $firstname; + $postfields['last_name'] = $lastname; + $postfields['fullname'] = $fullname; + $postfields['email'] = $email; + $postfields['address1'] = $address1; + $postfields['address2'] = $address2; + $postfields['city'] = $city; + $postfields['state'] = $state; + $postfields['postcode'] = $postcode; + $postfields['country'] = $country; + $postfields['phone'] = $phone; + $postfields['callback_url'] = $systemUrl . ((substr($systemUrl, -1) == '/') ? '' : '/') . 'modules/gateways/callback/' . $moduleName . '.php'; + $postfields['return_url'] = $returnUrl; + // Create Unique invoice_id + $postfields['invoice_id'] = $postfields['invoice_id'] . '_' . (date('YmdHis', time())); + ####postfields['invoice_id'] = $postfields['invoice_id']; + // AVAILABLE PAYMENT CHANNELS + $PaymentChannels = array(); + $getDokuPaymentChannels = dokuhosted_DokuAdmin::getDokuPaymentConfigs('channels'); + if (count($getDokuPaymentChannels) > 0) { + foreach ($getDokuPaymentChannels as $keval) { + if (isset($keval[0])) { + if (isset($params["Payment-Channel-{$keval[0]}"])) { + if ($params["Payment-Channel-{$keval[0]}"] == 'on') { + $channel_code = $keval[0]; + $channel_name = (isset($keval[1]) ? $keval[1] : '--Un-Named Payment Channel--'); + $PaymentChannels[] = array( + 'code' => $channel_code, + 'name' => $channel_name, + ); + } + } + } + } + } + // AVAILABLE INSTALLMENT BANKS + //-------------- + // MAKE GLOBAL_ACQUIRER_BANKS + // GLOBAL OBJECT FOR PROMO OF EACH BANK TENORS + $GLOBAL_ACQUIRER_BANKS = array( + 'onus' => [], + 'offus' => [], + ); + //$GLOBAL_ACQUIRER_BANKS = array(); + # Get Banks + $getDokuPaymentAcquirers = dokuhosted_DokuAdmin::getDokuPaymentConfigs('acquirers'); + //----------------------- + // ON US INSTALLMENT + //----------------------- + if (isset($getDokuPaymentAcquirers['onus'])) { + if (count($getDokuPaymentAcquirers['onus']) > 0) { + foreach ($getDokuPaymentAcquirers['onus'] as $key => $keval) { + if (isset($keval[0])) { + if (isset($params["Bank-Installment-Acquirer-Onus-{$keval[0]}"])) { + if ($params["Bank-Installment-Acquirer-Onus-{$keval[0]}"] == 'on') { + $bank_code = (isset($keval[0]) ? $keval[0] : '100'); // 100 (BNI as Default Bank) + $bank_name = (isset($keval[1]) ? $keval[1] : 'Bank BNI'); // 100 (BNI as Default Bank) + $GLOBAL_ACQUIRER_BANKS['onus'][] = array( + 'index' => "Bank-Installment-Acquirer-Onus-{$keval[0]}", + 'code' => $bank_code, + 'name' => $bank_name, + 'tenor' => array(), + ); + } + } + } + } + } + } + if (count($GLOBAL_ACQUIRER_BANKS['onus']) > 0) { + foreach ($GLOBAL_ACQUIRER_BANKS['onus'] as $k => $val) { + # Get Tenors + $getDokuPaymentTenors = dokuhosted_DokuAdmin::getDokuPaymentConfigs('tenors'); + if ((string)$val['code'] !== strval('100')) { // If NOT BNI + if (count($getDokuPaymentTenors) > 0) { + foreach ($getDokuPaymentTenors as $keval) { + $tenor_code = (isset($keval[0]) ? $keval[0] : '03'); // (03 Months as Default Tenor) + $tenor_name = (isset($keval[1]) ? $keval[1] : '03 Bulan'); // (03 Months as Default Tenor) + if (isset($params["{$val['index']}-{$tenor_code}"])) { + if ($params["{$val['index']}-{$tenor_code}"] == 'on') { + $val_tenor = array( + 'code' => $tenor_code, + 'name' => $tenor_name, + 'promo' => false, + ); + if (isset($params["{$val['index']}-{$tenor_code}-PromoId"])) { + if (!empty($params["{$val['index']}-{$tenor_code}-PromoId"]) && (strlen($params["{$val['index']}-{$tenor_code}-PromoId"]) > 0)) { + $val_tenor['promo'] = (string)$params["{$val['index']}-{$tenor_code}-PromoId"]; + } + } + // Add to GLOBAL_ACQUIRER_BANKS + if ($val_tenor['promo'] && ($val_tenor['promo'] != '')) { + $GLOBAL_ACQUIRER_BANKS['onus'][$k]['tenor'][] = $val_tenor; + } + } + } + } + } + } else { + if (count($getDokuPaymentTenors) > 0) { + foreach ($getDokuPaymentTenors as $keval) { + $tenor_code = (isset($keval[0]) ? $keval[0] : '03'); // (03 Months as Default Tenor) + $tenor_name = (isset($keval[1]) ? $keval[1] : '03 Bulan'); // (03 Months as Default Tenor) + if (isset($params["{$val['index']}-{$tenor_code}"])) { + if ($params["{$val['index']}-{$tenor_code}"] == 'on') { + $val_tenor = array( + 'code' => $tenor_code, + 'name' => $tenor_name, + 'promo' => false, + ); + if (isset($params["{$val['index']}-00"])) { // Only BNI using 00 as Tenor_Code + if (!empty($params["{$val['index']}-00"]) && (strlen($params["{$val['index']}-00"]) > 0)) { + $val_tenor['promo'] = (string)$params["{$val['index']}-00"]; + } + } + // Add to GLOBAL_ACQUIRER_BANKS + if ($val_tenor['promo'] && ($val_tenor['promo'] != '')) { + $GLOBAL_ACQUIRER_BANKS['onus'][$k]['tenor'][] = $val_tenor; + } + } + } + } + } + } + } + } + //----------------------- + // OFF US INSTALLMENT + //----------------------- + if (isset($getDokuPaymentAcquirers['offus'])) { + if (count($getDokuPaymentAcquirers['offus']) > 0) { + foreach ($getDokuPaymentAcquirers['offus'] as $key => $keval) { + if (isset($keval[0])) { + if (isset($params["Bank-Installment-Acquirer-Offus-{$keval[0]}-{$key}"])) { + if ($params["Bank-Installment-Acquirer-Offus-{$keval[0]}-{$key}"] == 'on') { + $bank_code = (isset($keval[0]) ? $keval[0] : '100'); // 100 (BNI as Default Bank) + $bank_name = (isset($keval[1]) ? $keval[1] : 'Bank BNI'); // 100 (BNI as Default Bank) + $GLOBAL_ACQUIRER_BANKS['offus'][] = array( + 'index' => "Bank-Installment-Acquirer-Offus-{$keval[0]}-{$key}", + 'code' => $bank_code, + 'name' => $bank_name, + 'tenor' => array(), + ); + } + } + } + } + } + } + if (count($GLOBAL_ACQUIRER_BANKS['offus']) > 0) { + foreach ($GLOBAL_ACQUIRER_BANKS['offus'] as $k => $val) { + # Get Tenors + $getDokuPaymentTenors = dokuhosted_DokuAdmin::getDokuPaymentConfigs('tenors'); + if ((string)$val['code'] !== strval('000')) { // If NOT BNI + if (count($getDokuPaymentTenors) > 0) { + foreach ($getDokuPaymentTenors as $keval) { + $tenor_code = (isset($keval[0]) ? $keval[0] : '03'); // (03 Months as Default Tenor) + $tenor_name = (isset($keval[1]) ? $keval[1] : '03 Bulan'); // (03 Months as Default Tenor) + if (isset($params["{$val['index']}-{$tenor_code}"])) { + if ($params["{$val['index']}-{$tenor_code}"] == 'on') { + $val_tenor = array( + 'code' => $tenor_code, + 'name' => $tenor_name, + 'promo' => false, + ); + if (isset($params["{$val['index']}-{$tenor_code}-PromoId"])) { + if (!empty($params["{$val['index']}-{$tenor_code}-PromoId"]) && (strlen($params["{$val['index']}-{$tenor_code}-PromoId"]) > 0)) { + $val_tenor['promo'] = (string)$params["{$val['index']}-{$tenor_code}-PromoId"]; + } + } + // Add to GLOBAL_ACQUIRER_BANKS + if ($val_tenor['promo'] && ($val_tenor['promo'] != '')) { + $GLOBAL_ACQUIRER_BANKS['offus'][$k]['tenor'][] = $val_tenor; + } + } + } + } + } + } else { + if (count($getDokuPaymentTenors) > 0) { + foreach ($getDokuPaymentTenors as $keval) { + $tenor_code = (isset($keval[0]) ? $keval[0] : '03'); // (03 Months as Default Tenor) + $tenor_name = (isset($keval[1]) ? $keval[1] : '03 Bulan'); // (03 Months as Default Tenor) + if (isset($params["{$val['index']}-{$tenor_code}"])) { + if ($params["{$val['index']}-{$tenor_code}"] == 'on') { + $val_tenor = array( + 'code' => $tenor_code, + 'name' => $tenor_name, + 'promo' => false, + ); + if (isset($params["{$val['index']}-00"])) { // Only BNI using 00 as Tenor_Code + if (!empty($params["{$val['index']}-00"]) && (strlen($params["{$val['index']}-00"]) > 0)) { + $val_tenor['promo'] = (string)$params["{$val['index']}-00"]; + } + } + // Add to GLOBAL_ACQUIRER_BANKS + if ($val_tenor['promo'] && ($val_tenor['promo'] != '')) { + $GLOBAL_ACQUIRER_BANKS['offus'][$k]['tenor'][] = $val_tenor; + } + } + } + } + } + } + } + } + //--------------------------------------------- + # Make Front-End of available installment banks + $BankInstallmentActive = array( + 'onus' => array(), + 'offus' => array(), + ); + $InstallmentBanks = array(); + // From On-us + if (count($GLOBAL_ACQUIRER_BANKS['onus']) > 0) { + foreach ($GLOBAL_ACQUIRER_BANKS['onus'] as $k => $keval) { + /** + * @string index + * @string code + * @string name + * @array tenor + **** @string code + * @string name + **** @string promo + */ + if (isset($keval['tenor']) && (isset($keval['code']))) { + $installment_code = $keval['code']; + if (count($keval['tenor']) > 0) { + array_push($BankInstallmentActive['onus'], $keval); + //$InstallmentBanks[] = $keval; + } + } + } + } + // From Off-us + if (count($GLOBAL_ACQUIRER_BANKS['offus']) > 0) { + foreach ($GLOBAL_ACQUIRER_BANKS['offus'] as $k => $keval) { + /** + * @string index + * @string code + * @string name + * @array tenor + **** @string code + * @string name + **** @string promo + */ + if (isset($keval['tenor']) && (isset($keval['code']))) { + $installment_code = $keval['code']; + if (count($keval['tenor']) > 0) { + array_push($BankInstallmentActive['offus'], $keval); + //$InstallmentBanks[] = $keval; + } + } + } + } + //------------------------- + // Get Active + //---- + if (strtoupper($params['Installment-Enabled']) === strtoupper('ONUS')) { + if (count($BankInstallmentActive['onus']) > 0) { + foreach ($BankInstallmentActive['onus'] as $keval) { + $InstallmentBanks[] = $keval; + } + } + } else if (strtoupper($params['Installment-Enabled']) === strtoupper('OFFUS')) { + if (count($BankInstallmentActive['offus']) > 0) { + foreach ($BankInstallmentActive['offus'] as $keval) { + $InstallmentBanks[] = $keval; + } + } + } + //------------------------- + /* + echo ""; + ksort($params); + print_r($params); + echo "
"; + print_r($InstallmentBanks); + + + echo "
"; + echo "
"; + echo "
"; + print_r($getDokuPaymentAcquirers); + print_r($GLOBAL_ACQUIRER_BANKS); + + exit; + */ + //------------------------------------------------------------------------------------------------ + /* + $InstallmentBanks = array(); + $getDokuPaymentAcquirers = dokuhosted_DokuAdmin::getDokuPaymentConfigs('acquirers'); + if (count($getDokuPaymentAcquirers) > 0) { + foreach ($getDokuPaymentAcquirers as $keval) { + if (isset($keval[0])) { + if (isset($params["Bank-Installment-Acquirer-{$keval[0]}"])) { + if ($params["Bank-Installment-Acquirer-{$keval[0]}"] == 'on') { + $bank_code = $keval[0]; + $bank_name = (isset($keval[1]) ? $keval[1] : '--Un-Named Acquirer Bank Name--'); + $bank_promo = ""; + if (isset($params["Payment-Installment-Promoid-{$keval[0]}"])) { + $bank_promo = $params["Payment-Installment-Promoid-{$keval[0]}"]; + } + $InstallmentBanks[] = array( + 'code' => $bank_code, + 'name' => $bank_name, + 'promo' => $bank_promo, + ); + } + } + } + } + } + // Available Tenors + $InstallmentTenors = array(); + $getDokuPaymentTenors = dokuhosted_DokuAdmin::getDokuPaymentConfigs('tenors'); + if (count($getDokuPaymentTenors) > 0) { + foreach ($getDokuPaymentTenors as $keval) { + if (isset($keval[0])) { + if (isset($params["Payment-Installment-Tenor-{$keval[0]}"])) { + if ($params["Payment-Installment-Tenor-{$keval[0]}"] == 'on') { + $tenor_code = (string)$keval[0]; + $tenor_name = (isset($keval[1]) ? $keval[1] : '--Un-Named Tenor Installment Name--'); + $InstallmentTenors[] = array( + 'code' => (string)$tenor_code, + 'name' => $tenor_name, + ); + } + } + } + } + } + */ + //------------------------------------------------------------------------------------------------ + + + //Log for orders + if ($Log_Enabled) { + logTransaction($moduleName, $params, "(WHMCS-params)"); + } + + ########################### + # HTML Output + ########################### + $returnHtml = ""; + # URL Of Payment-Request + //--------------------------------------------------- + // Start Of Form + $returnHtml .= '
'; + //$returnHtml .= print_r($params, true); + //$returnHtml .= ''; + + + + + // Debug all params values + /* + $returnHtml .= '
'; + //$returnHtml .= "\n\n"; + $returnHtml .= ''; + $returnHtml .= '
"; + $retDebug .= print_r($InvoiceData, true); + return $retDebug; + } + */ + + $Invoice_BillCycle = 0; + if (!$error) { + if (isset($OrderData['lineitems']['lineitem'][0]['billingcycle'])) { + switch (strtolower($OrderData['lineitems']['lineitem'][0]['billingcycle'])) { + case 'monthly': + $Invoice_BillCycle = 1; + break; + case 'quarterly': + $Invoice_BillCycle = 3; + break; + case 'semi-annually': + $Invoice_BillCycle = 6; + break; + case 'annually': + $Invoice_BillCycle = 12; + break; + case 'biennially': + $Invoice_BillCycle = 24; + break; + case 'triennially': + $Invoice_BillCycle = 36; + break; + } + } + } + if (!$error) { + $params_input['subscription'] = array( + 'CUSTOMERID' => (isset($InvoiceData['userid']) ? $InvoiceData['userid'] : ''), + 'BILLNUMBER' => '', // Generate later + 'BILLDETAIL' => substr($Invoice_BillDetail, 0, 256), + 'BILLTYPE' => 'S', // Shopping as default + 'STARTDATE' => (isset($InvoiceData['date']) ? $InvoiceData['date'] : ''), + 'ENDDATE' => (isset($InvoiceData['enddate']) ? $InvoiceData['enddate'] : 'NA'), + 'EXECUTETYPE' => 'DATE', // DAY / DATE / FULLDATE + 'EXECUTEDATE' => '', + 'EXECUTEMONTH' => '', + 'FLATSTATUS' => '', + 'REGISTERAMOUNT' => '', + ); + #### Create Date Time Object #### + //DateTime::createFromFormat('Y-m-d', date('Y-m-d')); + $DateObject = $DokuPayment->get_datetime_object("Asia/Bangkok"); + $params_input['subscription']['BILLNUMBER'] = $DateObject->format('YmdHi'); + $params_input['subscription']['BILLNUMBER'] .= (isset($InvoiceData['invoiceid']) ? $InvoiceData['invoiceid'] : ''); + $params_input['subscription']['STARTDATE'] = DateTime::createFromFormat('Y-m-d', $params_input['subscription']['STARTDATE']); + $params_input['subscription']['STARTDATE'] = $params_input['subscription']['STARTDATE']->format('Ymd'); + // Make ENDDATE + $DateSubscribe = DateTime::createFromFormat('Y-m-d', date('Y-m-d')); + switch ($Invoice_BillCycle) { + case 1: + $DateSubscribe->add(new DateInterval('P1M')); + break; + case 3: + $DateSubscribe->add(new DateInterval('P3M')); + break; + case 6: + $DateSubscribe->add(new DateInterval('P6M')); + break; + case 12: + $DateSubscribe->add(new DateInterval('P12M')); + break; + case 24: + $DateSubscribe->add(new DateInterval('P2Y')); + break; + case 36: + $DateSubscribe->add(new DateInterval('P3Y')); + //$DateSubscribe->add(new DateInterval('P3Y0M0DT0H0M0S')); + break; + } + $params_input['subscription']['ENDDATE'] = $DateSubscribe->format('Ymd'); + } + $Invoice_BillCycle_Months = array(); + if (!$error) { + // Make lists of EXECUTEMONTH + if ($Invoice_BillCycle > 0) { + switch ($Invoice_BillCycle) { + case 1: + case 3: + case 6: + case 12: + for ($i_bill = 0; $i_bill <= $Invoice_BillCycle; $i_bill++) { + $DateSubscribeMonths = new DateTime(date('Y-m-d')); + $DateSubscribeMonths->add(new DateInterval("P{$i_bill}M")); + $Invoice_BillCycle_Months[] = $DateSubscribeMonths->format('M'); + } + break; + case 24: + case 36: + for ($i_bill = 0; $i_bill <= 12; $i_bill++) { + $DateSubscribeMonths = DateTime::createFromFormat('Y-m-d', date('Y-m-d')); + $DateSubscribeMonths->add(new DateInterval("P{$i_bill}M")); + $Invoice_BillCycle_Months[] = $DateSubscribeMonths->format('M'); + } + break; + } + } + //$params_input['subscription']['EXECUTEMONTH'] = $DateObject->format('M'); + //$params_input['subscription']['EXECUTEMONTH'] = strtoupper($params_input['subscription']['EXECUTEMONTH']); + $params_input['subscription']['EXECUTEMONTH'] = implode(",", $Invoice_BillCycle_Months); + } + if (!$error) { + // filter BILLDETAIL String + $params_input['subscription']['BILLDETAIL'] = filter_var($params_input['subscription']['BILLDETAIL'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH); + $params_input['subscription']['BILLDETAIL'] = preg_replace("/[^a-zA-Z0-9]+/", "", $params_input['subscription']['BILLDETAIL']); + $params_input['subscription']['BILLDETAIL'] = str_replace('(', '', $params_input['subscription']['BILLDETAIL']); + $params_input['subscription']['BILLDETAIL'] = str_replace(')', '', $params_input['subscription']['BILLDETAIL']); + $params_input['subscription']['BILLDETAIL'] = str_replace('#', '', $params_input['subscription']['BILLDETAIL']); + switch (strtoupper($params_input['subscription']['EXECUTETYPE'])) { + case 'DAY': + $params_input['subscription']['EXECUTEDATE'] = strtoupper($DateObject->format('D')); + break; + case 'DATE': + $params_input['subscription']['EXECUTEDATE'] = $DateObject->format('j'); + if ((int)$params_input['subscription']['EXECUTEDATE'] > 28) { + $params_input['subscription']['EXECUTEDATE'] = '28'; + } + break; + case 'FULLDATE': + $params_input['subscription']['EXECUTEDATE'] = $DateObject->format('Ymd'); + break; + } + + $params_input['subscription']['FLATSTATUS'] = 'TRUE'; // Static (Fix) Value + $params_input['subscription']['REGISTERAMOUNT'] = sprintf('%.2f', $InvoiceData['total']); + } + //------------------------------------------------------- + if (!$error) { + /* + echo "'; + // Js submit form + $htmlFormSubmit .= ''; + //------------------------------------------ + /* + $htmlFormSubmit .= ''; + */ + } + } + if (!$error) { + $htmlReturn = "{$htmlForm}{$htmlFormSubmit}"; + return $htmlReturn; + } else { + //$htmlReturn = print_r($error_msg, true); + return false; + } + + /* + if (!$error) { + echo $htmlForm; + echo $htmlFormSubmit; + + + + } + exit; + + if (!$error) { + + + + + + + $htmlForm .= ''; + + $htmlFormSubmit .= ''; + + + + echo ""; + if ($OrderData) { + echo "
"; + print_r($OrderData); + } + if ($InvoiceData) { + echo "
"; + print_r($InvoiceData); + } + exit; + */ + + # Create Subscription Payment Structure + $createPaymentStructure = $DokuPayment->create_payment_structure('subscription', 0, $params_input, $user_input, $params_input['items'], $user_input['shipping_address']); + $PaymentStructure = array( + 'words_sha1' => (isset($createPaymentStructure['WORDS']) ? $createPaymentStructure['WORDS'] : ""), + 'words_string' => (isset($createPaymentStructure['WORDS_STRING']) ? $createPaymentStructure['WORDS_STRING'] : ""), + 'session_id' => (isset($createPaymentStructure['SESSIONID']) ? $createPaymentStructure['SESSIONID'] : ""), + ); + // Generate Unique SESSIONID Every single payment + $PaymentStructure['session_id'] = sha1("{$PaymentStructure['session_id']}{$DokuPayment->generate_transaction_id()}"); + if ((isset($createPaymentStructure['WORDS_STRING'])) && (isset($createPaymentStructure['SESSIONID']))) { + unset($createPaymentStructure['WORDS_STRING']); + $PaymentStructureJson = json_encode($createPaymentStructure, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); + // do any log .... + $makepayment_data = json_decode($PaymentStructureJson, true, 512, JSON_BIGINT_AS_STRING); + ksort($makepayment_data); + if ($Log_Enabled) { + logTransaction($moduleName, $makepayment_data, "(WHMCS) REQUEST-PAYMENT"); + } + $rawdata['payment_form'] = $makepayment_data; + //-------------------------------------------------------------------------------------------------------------- + if (isset($rawdata['payment_form']['TOKENID'])) { + unset($rawdata['payment_form']['TOKENID']); + } + if (isset($rawdata['payment_form']['PAYMENTTYPE'])) { + unset($rawdata['payment_form']['PAYMENTTYPE']); + } + //-------------------------------------------------------------------------------------------------------------- + $rawdata['payment_input'] = http_build_query($rawdata['payment_form']); + // CURL AND SAVE LOG + $headers = $DokuPayment->create_curl_headers($DokuPayment->dokupayment_headers); + //$curlData = $DokuPayment->create_curl_request('POST', $DokuPayment->endpoint['request'], 'WHMCS Payment Plugin (http://www.doku.com)', $headers, $rawdata['payment_form'], 30); + //logTransaction($moduleName, $curlData, "(WHMCS) SUBSCRIPTION-REQUEST"); + $htmlForm .= ""; + $htmlForm .= '
"; + print_r($params); + + if ($InvoiceData) { + echo "
"; + print_r($InvoiceData); + } + + exit; + + + + + + + echo $htmlForm; + echo $htmlFormSubmit; + exit; + + + } + */ + //$curlData = curlCall($DokuPayment->endpoint['request'], $makepayment_data); + //$tokenize = array( + // "status" => "error", + // "rawdata" => $rawdata + //); + + // + //$tokenize = array( + // 'status' => 'success', + // 'transid' => "{$params['invoiceid']}_{$DokuPayment->generate_transaction_id()}", + // 'rawdata' => $rawdata, + //); + // + //return $tokenize; +} +function dokusubscription_nolocalcc($params) { + return true; +} + + + + + + + + + + + + + + + + + +/** + * Refund transaction. + * + * Called when a refund is requested for a previously successful transaction. + * + * @param array $params Payment Gateway Module Parameters + * + * @see https://developers.whmcs.com/payment-gateways/refunds/ + * + * @return array Transaction response status + */ +function dokusubscription_refund($params) { + // Gateway Configuration Parameters + $accountId = $params['accountID']; + $secretKey = $params['secretKey']; + $testMode = $params['testMode']; + $dropdownField = $params['dropdownField']; + $radioField = $params['radioField']; + $textareaField = $params['textareaField']; + + // Transaction Parameters + $transactionIdToRefund = $params['transid']; + $refundAmount = $params['amount']; + $currencyCode = $params['currency']; + + // Client Parameters + $firstname = $params['clientdetails']['firstname']; + $lastname = $params['clientdetails']['lastname']; + $email = $params['clientdetails']['email']; + $address1 = $params['clientdetails']['address1']; + $address2 = $params['clientdetails']['address2']; + $city = $params['clientdetails']['city']; + $state = $params['clientdetails']['state']; + $postcode = $params['clientdetails']['postcode']; + $country = $params['clientdetails']['country']; + $phone = $params['clientdetails']['phonenumber']; + + // System Parameters + $companyName = $params['companyname']; + $systemUrl = $params['systemurl']; + $langPayNow = $params['langpaynow']; + $moduleDisplayName = $params['name']; + $moduleName = $params['paymentmethod']; + $whmcsVersion = $params['whmcsVersion']; + + // perform API call to initiate refund and interpret result + + return array( + // 'success' if successful, otherwise 'declined', 'error' for failure + 'status' => 'success', + // Data to be recorded in the gateway log - can be a string or array + 'rawdata' => $responseData, + // Unique Transaction ID for the refund transaction + 'transid' => $refundTransactionId, + // Optional fee amount for the fee value refunded + 'fees' => $feeAmount, + ); +} + +/** + * Cancel subscription. + * + * If the payment gateway creates subscriptions and stores the subscription + * ID in tblhosting.subscriptionid, this function is called upon cancellation + * or request by an admin user. + * + * @param array $params Payment Gateway Module Parameters + * + * @see https://developers.whmcs.com/payment-gateways/subscription-management/ + * + * @return array Transaction response status + */ +function dokusubscription_cancelSubscription($params) { + // Gateway Configuration Parameters + $accountId = $params['accountID']; + $secretKey = $params['secretKey']; + $testMode = $params['testMode']; + $dropdownField = $params['dropdownField']; + $radioField = $params['radioField']; + $textareaField = $params['textareaField']; + + // Subscription Parameters + $subscriptionIdToCancel = $params['subscriptionID']; + + // System Parameters + $companyName = $params['companyname']; + $systemUrl = $params['systemurl']; + $langPayNow = $params['langpaynow']; + $moduleDisplayName = $params['name']; + $moduleName = $params['paymentmethod']; + $whmcsVersion = $params['whmcsVersion']; + + // perform API call to cancel subscription and interpret result + + return array( + // 'success' if successful, any other value for failure + 'status' => 'success', + // Data to be recorded in the gateway log - can be a string or array + 'rawdata' => $responseData, + ); +} + + +if (!defined("WHMCS")) { + die("This file cannot be accessed directly"); +} + +