Skip to content

Commit

Permalink
Merge branch 'pw-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
masonpham committed Mar 21, 2019
2 parents fe61ec6 + 6cd7897 commit e35ca6c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
56 changes: 55 additions & 1 deletion src/includes/hooks/paymentwall.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);

Expand Down Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion src/modules/gateways/brick.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/modules/gateways/paymentwall.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e35ca6c

Please sign in to comment.