From bbeae335d2e3710973f8a1511da1ede890cf8c80 Mon Sep 17 00:00:00 2001 From: Mason Date: Thu, 21 Mar 2019 17:48:17 +0700 Subject: [PATCH] Update module to implement Cancellation API --- src/includes/api/paymentwall_api | 2 +- src/includes/hooks/paymentwall.php | 56 +++++++++++++++++++++++++++- src/modules/gateways/brick.php | 2 +- src/modules/gateways/paymentwall.php | 2 +- 4 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/includes/api/paymentwall_api b/src/includes/api/paymentwall_api index d60237e..b7e7c7d 160000 --- a/src/includes/api/paymentwall_api +++ b/src/includes/api/paymentwall_api @@ -1 +1 @@ -Subproject commit d60237e64ba00ba841809b1186d0c18ed6c5d8f2 +Subproject commit b7e7c7d83b945396b1aa163f2d8448006392cb31 diff --git a/src/includes/hooks/paymentwall.php b/src/includes/hooks/paymentwall.php index e51ddff..c9bc4f8 100755 --- a/src/includes/hooks/paymentwall.php +++ b/src/includes/hooks/paymentwall.php @@ -86,6 +86,15 @@ function cancelSubscription($vars) if (!$gateway["type"]) { die($gateway['name'] . " is not activated"); } + + if ($invoiceData['paymentmethod'] == 'paymentwall') { + return cancellPWInvoice($gateway, $invoiceId, 2); + } + + if ($invoiceData['paymentmethod'] != 'brick') { + return; + } + init_brick_config($gateway); $result = select_query("tblaccounts", "transid", array("invoiceid" => $invoiceId)); @@ -107,8 +116,14 @@ function refundInvoice($vars) { if (empty($gateway["type"])) { die($gateway['name'] . " is not activated"); } - if ($gateway['paymentmethod'] != 'brick') + + if ($invoiceData['paymentmethod'] == 'paymentwall') { + return cancellPWInvoice($gateway, $invoiceId); + } + + if ($invoiceData['paymentmethod'] != 'brick') { return; + } init_brick_config($gateway); @@ -168,6 +183,45 @@ function refundInvoice($vars) { }); } +function cancellPWInvoice($gateway, $invoiceId, $type = 1) { + $result = select_query("tblaccounts", "transid", array("invoiceid" => $invoiceId)); + $data = mysql_fetch_assoc($result); + + require_once(ROOTDIR . '/includes/api/paymentwall_api/lib/paymentwall.php'); + require_once(ROOTDIR . '/modules/gateways/paymentwall/helpers/helper.php'); + Paymentwall_Config::getInstance()->set(array( + 'api_base_url' => 'https://api.paymentwall.com/developers/api', + 'public_key' => $gateway['appKey'], // available in your Paymentwall merchant area + 'private_key' => $gateway['secretKey'] // available in your Paymentwall merchant area, + + )); + $params = array( + 'key' => $gateway['appKey'], + 'ref' => $data['transid'], + 'type' => $type, + 'message' => 'Please cancel asap', + 'test_mode' => $gateway['isTest'] == 'on' ? 1 : 0 // pass 1 to perform tests without an actual transaction + ); + $params['sign'] = generateCancellationSignature($params, $gateway['secretKey']); + + $api = new Paymentwall_GenerericApiObject('ticket'); + return $api->post($params); +} + +function generateCancellationSignature($params, $secret) { + // work with sorted data + ksort($params); + + // generate the base string + $baseString = ''; + foreach($params as $key => $value) { + $baseString .= $key . '=' . $value; + } + $baseString .= $secret; + + return strtolower(md5($baseString)); +} + add_hook("AfterModuleCreate", 1, "afterSetupProductEventListener"); diff --git a/src/modules/gateways/brick.php b/src/modules/gateways/brick.php index aa7e0a7..ff41176 100755 --- a/src/modules/gateways/brick.php +++ b/src/modules/gateways/brick.php @@ -4,7 +4,7 @@ * Plugin Name: Paymentwall for WHMCS * Plugin URI: https://docs.paymentwall.com/modules/whmcs * Description: Official Paymentwall module for Prestashop. - * Version: v1.6.1 + * Version: v1.6.2 * Author: The Paymentwall Team * Author URI: http://www.paymentwall.com/ * License: The MIT License (MIT) diff --git a/src/modules/gateways/paymentwall.php b/src/modules/gateways/paymentwall.php index 11bde87..fd4492d 100755 --- a/src/modules/gateways/paymentwall.php +++ b/src/modules/gateways/paymentwall.php @@ -4,7 +4,7 @@ * Plugin Name: Paymentwall for WHMCS * Plugin URI: https://docs.paymentwall.com/modules/whmcs * Description: Official Paymentwall module for Prestashop. - * Version: v1.6.1 + * Version: v1.6.2 * Author: The Paymentwall Team * Author URI: http://www.paymentwall.com/ * License: The MIT License (MIT)