Skip to content

Commit dff0de9

Browse files
Merge pull request #9 from appinlet/release/1.0.7
Release/1.0.7
2 parents e072c7c + 8a881e9 commit dff0de9

20 files changed

+666
-560
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# PayBatch_PayHost_WHMCS
2-
## PayGate PayBatch (with PayHost tokenization) plugin v1.0.6 for WHMCS v7.7.0
2+
## PayGate PayBatch (with PayHost tokenization) plugin v1.0.7 for WHMCS v8.5.1
33

4-
This is the PayGate PayBatch (with PayHost tokenization) for WHMCS. Please feel free to contact the PayGate support team at [email protected] should you require any assistance.
4+
This is the PayGate PayBatch (with PayHost tokenization) for WHMCS. Please feel free to contact the PayGate support team at [email protected] should you require any assistance.
55

6-
This module is in the first release; we suggest thorough testing with your use case before proceeding to a live environment.
6+
We suggest thorough testing with your use case in staging before proceeding to a live environment.
77

88
## Installation
9-
Please navigate to the [releases page](https://github.com/PayGate/PayBatch_PayHost_WHMCS/releases), download the latest release (v1.0.6) and unzip. You will then be able to follow the integration guide which is included in the zip.
9+
Please navigate to the [releases page](https://github.com/PayGate/PayBatch_PayHost_WHMCS/releases), download the latest release (v1.0.7) and unzip. You will then be able to follow the integration guide which is included in the zip.
1010

1111
## Collaboration
1212

modules/addons/payhostpaybatch/hooks.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@
2424
*
2525
* add_hook(string $hookPointName, int $priority, string|array|Closure $function)
2626
*/
27-
add_hook( 'ClientAreaHomepage', 1, function ( array $params ) {
27+
add_hook('ClientAreaHomepage', 1, function (array $params) {
2828
try {
2929
// Call the service's function, using the values provided by WHMCS in
3030
// `$params`.
31-
} catch ( Exception $e ) {
31+
} catch (Exception $e) {
3232
// Consider logging or reporting the error.
3333
}
34-
} );
34+
});
3535

36-
add_hook( 'ClientAreaPrimaryNavbar', 1, function ( MenuItem $primaryNavbar ) {
37-
$primaryNavbar->addChild( 'Token Management' )
38-
->setOrder( 70 );
39-
$primaryNavbar->getChild( 'Token Management' )
40-
->addChild( 'RemoveToken', [
41-
'uri' => 'index.php?m=payhostpaybatch&action=secret',
42-
'order' => 100,
43-
] );
44-
} );
36+
add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) {
37+
$primaryNavbar->addChild('Token Management')
38+
->setOrder(70);
39+
$primaryNavbar->getChild('Token Management')
40+
->addChild('RemoveToken', [
41+
'uri' => 'index.php?m=payhostpaybatch&action=secret',
42+
'order' => 100,
43+
]);
44+
});

modules/addons/payhostpaybatch/lang/english.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/*
34
* Copyright (c) 2020 PayGate (Pty) Ltd
45
*

modules/addons/payhostpaybatch/lib/Admin/AdminDispatcher.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ class AdminDispatcher
2323
*
2424
* @return string
2525
*/
26-
public function dispatch( $action, $parameters )
26+
public function dispatch($action, $parameters)
2727
{
28-
if ( !$action ) {
28+
if ( ! $action) {
2929
// Default to index if no action specified
3030
$action = 'index';
3131
}
3232

3333
$controller = new Controller();
3434

3535
// Verify requested action is valid and callable
36-
if ( is_callable( array( $controller, $action ) ) ) {
37-
return $controller->$action( $parameters );
36+
if (is_callable(array($controller, $action))) {
37+
return $controller->$action($parameters);
3838
}
3939

4040
return '<p>Invalid action requested. Please go back and try again.</p>';

modules/addons/payhostpaybatch/lib/Admin/Controller.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*
77
* Released under the GNU General Public License
88
*/
9+
910
namespace WHMCS\Module\Addon\PayhostPaybatch\Admin;
1011

1112
/**
@@ -21,7 +22,7 @@ class Controller
2122
*
2223
* @return string
2324
*/
24-
public function index( $vars )
25+
public function index($vars)
2526
{
2627
// Get common module parameters
2728
$modulelink = $vars['modulelink']; // eg. addonmodules.php?module=addonmodule
@@ -76,7 +77,7 @@ public function index( $vars )
7677
*
7778
* @return string
7879
*/
79-
public function show( $vars )
80+
public function show($vars)
8081
{
8182
// Get common module parameters
8283
$modulelink = $vars['modulelink']; // eg. addonmodules.php?module=addonmodule

modules/addons/payhostpaybatch/lib/Client/ClientDispatcher.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ class ClientDispatcher
2323
*
2424
* @return array
2525
*/
26-
public function dispatch( $action, $parameters )
26+
public function dispatch($action, $parameters)
2727
{
28-
if ( !$action ) {
28+
if ( ! $action) {
2929
// Default to secret if no action specified
3030
$action = 'secret';
3131
}
3232

3333
$controller = new Controller();
3434

3535
// Verify requested action is valid and callable
36-
if ( is_callable( array( $controller, $action ) ) ) {
37-
return $controller->$action( $parameters );
36+
if (is_callable(array($controller, $action))) {
37+
return $controller->$action($parameters);
3838
}
3939
}
4040
}

modules/addons/payhostpaybatch/lib/Client/Controller.php

Lines changed: 58 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
*
77
* Released under the GNU General Public License
88
*/
9+
910
namespace WHMCS\Module\Addon\PayhostPaybatch\Client;
1011

12+
use SoapClient;
13+
use SoapFault;
14+
use SoapVar;
1115
use WHMCS\Database\Capsule;
1216

1317
/**
@@ -23,9 +27,9 @@ class Controller
2327
*
2428
* @return array
2529
*/
26-
public function index( $vars )
30+
public function index($vars)
2731
{
28-
return ( new ClientDispatcher() )->dispatch( 'secret', [] );
32+
return (new ClientDispatcher())->dispatch('secret', []);
2933
}
3034

3135
/**
@@ -35,33 +39,26 @@ public function index( $vars )
3539
*
3640
* @return array
3741
*/
38-
public function secret( $vars )
42+
public function secret($vars)
3943
{
40-
if ( !defined( '_DB_PREFIX_' ) ) {
41-
define( '_DB_PREFIX_', 'tbl' );
44+
if ( ! defined('_DB_PREFIX_')) {
45+
define('_DB_PREFIX_', 'tbl');
4246
}
4347

4448
// Get the stored tokens for the logged-in user
45-
$userId = $_SESSION['uid'] ?? null;
46-
$tblpayhostpaybatch = _DB_PREFIX_ . 'payhostpaybatch';
47-
$tokens = Capsule::table( $tblpayhostpaybatch )
48-
->select( 'recordval' )
49-
->where( 'recordtype', 'clientdetail' )
50-
->where( 'recordid', $userId )
51-
->get();
52-
53-
$tokenValues = [];
54-
foreach ( $tokens as $token ) {
55-
array_push( $tokenValues, $token->recordval );
56-
}
49+
$userId = $_SESSION['uid'] ?? null;
50+
$tblpayhostpaybatchvaults = _DB_PREFIX_ . 'payhostpaybatchvaults';
51+
$tokens = Capsule::table($tblpayhostpaybatchvaults)
52+
->select()
53+
->where('user_id', $userId)
54+
->get();
5755

5856
$cardDetails = [];
59-
foreach ( $tokenValues as $tokenValue ) {
60-
$cardDetail['token'] = $tokenValue;
61-
$card = $this->getVaultCard( $tokenValue )->LookUpVaultResponse->Status->PayVaultData;
62-
$cardDetail['cardNumber'] = $card[0]->value;
63-
$cardDetail['expDate'] = $card[1]->value;
64-
array_push( $cardDetails, $cardDetail );
57+
foreach ($tokens as $tokenValue) {
58+
$cardDetail['token'] = $tokenValue->token;
59+
$cardDetail['cardNumber'] = $tokenValue->card_number;
60+
$cardDetail['expDate'] = $tokenValue->card_expiry;
61+
array_push($cardDetails, $cardDetail);
6562
}
6663

6764
// Get common module parameters
@@ -78,19 +75,39 @@ public function secret( $vars )
7875
'forcessl' => false, // Deprecated as of Version 7.0. Requests will always use SSL if available.
7976
'vars' => array(
8077
'modulelink' => $modulelink,
81-
'configTextField' => json_encode( $cardDetails ),
78+
'configTextField' => json_encode($cardDetails),
8279
'customVariable' => 'your own content goes here',
8380
'userId' => $userId,
8481
'userTokens' => $cardDetails,
8582
),
8683
);
8784
}
8885

89-
private function getVaultCard( $vaultId )
86+
public function deleteToken($vars)
87+
{
88+
if ( ! defined('_DB_PREFIX_')) {
89+
define('_DB_PREFIX_', 'tbl');
90+
}
91+
92+
$tokenId = $_GET['tokenId'] ?? null;
93+
if ($tokenId) {
94+
$userId = $_SESSION['uid'] ?? null;
95+
$tblpayhostpaybatchvaults = _DB_PREFIX_ . 'payhostpaybatchvaults';
96+
Capsule::table($tblpayhostpaybatchvaults)
97+
->where('user_id', $userId)
98+
->where('token', $tokenId)
99+
->delete();
100+
}
101+
$dispatcher = new ClientDispatcher();
102+
103+
return $dispatcher->dispatch('secret', []);
104+
}
105+
106+
private function getVaultCard($vaultId)
90107
{
91108
$gatewaySettings = $this->getPayhostGatewayDetail();
92109
// Check for test mode
93-
if ( $gatewaySettings['testMode'] == 'on' ) {
110+
if ($gatewaySettings['testMode'] == 'on') {
94111
$payHostId = '10011072130';
95112
$payHostSecretKey = 'test';
96113
} else {
@@ -111,54 +128,33 @@ private function getVaultCard( $vaultId )
111128
SOAP;
112129

113130
$wsdl = 'https://secure.paygate.co.za/payhost/process.trans?wsdl';
114-
$sc = new \SoapClient( $wsdl, ['trace' => 1] );
131+
$sc = new SoapClient($wsdl, ['trace' => 1]);
115132
try {
116-
$result = $sc->__soapCall( 'SingleVault', [
117-
// $result = $sc->__soapCall('SingleFollowUp', [
118-
new \SoapVar( $soap, XSD_ANYXML ),
119-
] );
120-
} catch ( \SoapFault $f ) {
121-
return json_encode( $f );
133+
$result = $sc->__soapCall('SingleVault', [
134+
new SoapVar($soap, XSD_ANYXML),
135+
]);
136+
} catch (SoapFault $f) {
137+
return json_encode($f);
122138
}
123139

124140
return $result;
125141
}
126142

127143
private function getPayhostGatewayDetail()
128144
{
129-
if ( !defined( '_DB_PREFIX_' ) ) {
130-
define( '_DB_PREFIX_', 'tbl' );
145+
if ( ! defined('_DB_PREFIX_')) {
146+
define('_DB_PREFIX_', 'tbl');
131147
}
132148
$tblpaymentgateways = _DB_PREFIX_ . 'paymentgateways';
133-
$gatewayValues = Capsule::table( $tblpaymentgateways )
134-
->select( 'setting', 'value' )
135-
->where( 'gateway', 'payhostpaybatch' )
136-
->get();
137-
$gatewaySettings = [];
138-
foreach ( $gatewayValues as $gatewayValue ) {
149+
$gatewayValues = Capsule::table($tblpaymentgateways)
150+
->select('setting', 'value')
151+
->where('gateway', 'payhostpaybatch')
152+
->get();
153+
$gatewaySettings = [];
154+
foreach ($gatewayValues as $gatewayValue) {
139155
$gatewaySettings[$gatewayValue->setting] = $gatewayValue->value;
140156
}
141-
return $gatewaySettings;
142-
}
143-
144-
public function deleteToken( $vars )
145-
{
146-
if ( !defined( '_DB_PREFIX_' ) ) {
147-
define( '_DB_PREFIX_', 'tbl' );
148-
}
149157

150-
$tokenId = $_GET['tokenId'] ?? null;
151-
if ( $tokenId ) {
152-
$userId = $_SESSION['uid'] ?? null;
153-
$tblpayhostpaybatch = _DB_PREFIX_ . 'payhostpaybatch';
154-
Capsule::table( $tblpayhostpaybatch )
155-
->where( 'recordtype', 'clientdetail' )
156-
->where( 'recordid', $userId )
157-
->where( 'recordval', $tokenId )
158-
->delete();
159-
160-
}
161-
$dispatcher = new ClientDispatcher();
162-
return $dispatcher->dispatch( 'secret', [] );
158+
return $gatewaySettings;
163159
}
164160
}

modules/addons/payhostpaybatch/payhostpaybatch.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
use WHMCS\Module\Addon\payhostpaybatch\Admin\AdminDispatcher;
1414
use WHMCS\Module\Addon\payhostpaybatch\Client\ClientDispatcher;
1515

16-
if ( !defined( "WHMCS" ) ) {
17-
die( "This file cannot be accessed directly" );
16+
if ( ! defined("WHMCS")) {
17+
die("This file cannot be accessed directly");
1818
}
1919

2020
/**
@@ -139,7 +139,7 @@ function payhostpaybatch_deactivate()
139139
*
140140
* @return void
141141
*/
142-
function payhostpaybatch_upgrade( $vars )
142+
function payhostpaybatch_upgrade($vars)
143143
{
144144
}
145145

@@ -155,7 +155,7 @@ function payhostpaybatch_upgrade( $vars )
155155
* @see payhostpaybatch\Admin\Controller::index()
156156
*
157157
*/
158-
function payhostpaybatch_output( $vars )
158+
function payhostpaybatch_output($vars)
159159
{
160160
// Get common module parameters
161161
$modulelink = $vars['modulelink']; // eg. payhostpaybatchs.php?module=payhostpaybatch
@@ -173,10 +173,10 @@ function payhostpaybatch_output( $vars )
173173
// Dispatch and handle request here. What follows is a demonstration of one
174174
// possible way of handling this using a very basic dispatcher implementation.
175175

176-
$action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
176+
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
177177

178178
$dispatcher = new AdminDispatcher();
179-
$response = $dispatcher->dispatch( $action, $vars );
179+
$response = $dispatcher->dispatch($action, $vars);
180180
echo $response;
181181
}
182182

@@ -190,7 +190,7 @@ function payhostpaybatch_output( $vars )
190190
*
191191
* @return string
192192
*/
193-
function payhostpaybatch_sidebar( $vars )
193+
function payhostpaybatch_sidebar($vars)
194194
{
195195
// Get common module parameters
196196
$modulelink = $vars['modulelink'];
@@ -206,6 +206,7 @@ function payhostpaybatch_sidebar( $vars )
206206
$configTextareaField = $vars['Textarea Field Name'];
207207

208208
$sidebar = '<p>Sidebar output HTML goes here</p>';
209+
209210
return $sidebar;
210211
}
211212

@@ -221,7 +222,7 @@ function payhostpaybatch_sidebar( $vars )
221222
* @see payhostpaybatch\Client\Controller::index()
222223
*
223224
*/
224-
function payhostpaybatch_clientarea( $vars )
225+
function payhostpaybatch_clientarea($vars)
225226
{
226227
// Get common module parameters
227228
$modulelink = $vars['modulelink']; // eg. index.php?m=payhostpaybatch
@@ -241,8 +242,9 @@ function payhostpaybatch_clientarea( $vars )
241242
* possible way of handling this using a very basic dispatcher implementation.
242243
*/
243244

244-
$action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
245+
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
245246

246247
$dispatcher = new ClientDispatcher();
247-
return $dispatcher->dispatch( $action, $vars );
248+
249+
return $dispatcher->dispatch($action, $vars);
248250
}

0 commit comments

Comments
 (0)