Skip to content

Commit

Permalink
Merge pull request #9 from appinlet/release/1.0.7
Browse files Browse the repository at this point in the history
Release/1.0.7
  • Loading branch information
appinlet authored Oct 10, 2022
2 parents e072c7c + 8a881e9 commit dff0de9
Show file tree
Hide file tree
Showing 20 changed files with 666 additions and 560 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# PayBatch_PayHost_WHMCS
## PayGate PayBatch (with PayHost tokenization) plugin v1.0.6 for WHMCS v7.7.0
## PayGate PayBatch (with PayHost tokenization) plugin v1.0.7 for WHMCS v8.5.1

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.
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.

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

## Installation
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.
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.

## Collaboration

Expand Down
24 changes: 12 additions & 12 deletions modules/addons/payhostpaybatch/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@
*
* add_hook(string $hookPointName, int $priority, string|array|Closure $function)
*/
add_hook( 'ClientAreaHomepage', 1, function ( array $params ) {
add_hook('ClientAreaHomepage', 1, function (array $params) {
try {
// Call the service's function, using the values provided by WHMCS in
// `$params`.
} catch ( Exception $e ) {
} catch (Exception $e) {
// Consider logging or reporting the error.
}
} );
});

add_hook( 'ClientAreaPrimaryNavbar', 1, function ( MenuItem $primaryNavbar ) {
$primaryNavbar->addChild( 'Token Management' )
->setOrder( 70 );
$primaryNavbar->getChild( 'Token Management' )
->addChild( 'RemoveToken', [
'uri' => 'index.php?m=payhostpaybatch&action=secret',
'order' => 100,
] );
} );
add_hook('ClientAreaPrimaryNavbar', 1, function (MenuItem $primaryNavbar) {
$primaryNavbar->addChild('Token Management')
->setOrder(70);
$primaryNavbar->getChild('Token Management')
->addChild('RemoveToken', [
'uri' => 'index.php?m=payhostpaybatch&action=secret',
'order' => 100,
]);
});
1 change: 1 addition & 0 deletions modules/addons/payhostpaybatch/lang/english.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* Copyright (c) 2020 PayGate (Pty) Ltd
*
Expand Down
8 changes: 4 additions & 4 deletions modules/addons/payhostpaybatch/lib/Admin/AdminDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ class AdminDispatcher
*
* @return string
*/
public function dispatch( $action, $parameters )
public function dispatch($action, $parameters)
{
if ( !$action ) {
if ( ! $action) {
// Default to index if no action specified
$action = 'index';
}

$controller = new Controller();

// Verify requested action is valid and callable
if ( is_callable( array( $controller, $action ) ) ) {
return $controller->$action( $parameters );
if (is_callable(array($controller, $action))) {
return $controller->$action($parameters);
}

return '<p>Invalid action requested. Please go back and try again.</p>';
Expand Down
5 changes: 3 additions & 2 deletions modules/addons/payhostpaybatch/lib/Admin/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*
* Released under the GNU General Public License
*/

namespace WHMCS\Module\Addon\PayhostPaybatch\Admin;

/**
Expand All @@ -21,7 +22,7 @@ class Controller
*
* @return string
*/
public function index( $vars )
public function index($vars)
{
// Get common module parameters
$modulelink = $vars['modulelink']; // eg. addonmodules.php?module=addonmodule
Expand Down Expand Up @@ -76,7 +77,7 @@ public function index( $vars )
*
* @return string
*/
public function show( $vars )
public function show($vars)
{
// Get common module parameters
$modulelink = $vars['modulelink']; // eg. addonmodules.php?module=addonmodule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ class ClientDispatcher
*
* @return array
*/
public function dispatch( $action, $parameters )
public function dispatch($action, $parameters)
{
if ( !$action ) {
if ( ! $action) {
// Default to secret if no action specified
$action = 'secret';
}

$controller = new Controller();

// Verify requested action is valid and callable
if ( is_callable( array( $controller, $action ) ) ) {
return $controller->$action( $parameters );
if (is_callable(array($controller, $action))) {
return $controller->$action($parameters);
}
}
}
120 changes: 58 additions & 62 deletions modules/addons/payhostpaybatch/lib/Client/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
*
* Released under the GNU General Public License
*/

namespace WHMCS\Module\Addon\PayhostPaybatch\Client;

use SoapClient;
use SoapFault;
use SoapVar;
use WHMCS\Database\Capsule;

/**
Expand All @@ -23,9 +27,9 @@ class Controller
*
* @return array
*/
public function index( $vars )
public function index($vars)
{
return ( new ClientDispatcher() )->dispatch( 'secret', [] );
return (new ClientDispatcher())->dispatch('secret', []);
}

/**
Expand All @@ -35,33 +39,26 @@ public function index( $vars )
*
* @return array
*/
public function secret( $vars )
public function secret($vars)
{
if ( !defined( '_DB_PREFIX_' ) ) {
define( '_DB_PREFIX_', 'tbl' );
if ( ! defined('_DB_PREFIX_')) {
define('_DB_PREFIX_', 'tbl');
}

// Get the stored tokens for the logged-in user
$userId = $_SESSION['uid'] ?? null;
$tblpayhostpaybatch = _DB_PREFIX_ . 'payhostpaybatch';
$tokens = Capsule::table( $tblpayhostpaybatch )
->select( 'recordval' )
->where( 'recordtype', 'clientdetail' )
->where( 'recordid', $userId )
->get();

$tokenValues = [];
foreach ( $tokens as $token ) {
array_push( $tokenValues, $token->recordval );
}
$userId = $_SESSION['uid'] ?? null;
$tblpayhostpaybatchvaults = _DB_PREFIX_ . 'payhostpaybatchvaults';
$tokens = Capsule::table($tblpayhostpaybatchvaults)
->select()
->where('user_id', $userId)
->get();

$cardDetails = [];
foreach ( $tokenValues as $tokenValue ) {
$cardDetail['token'] = $tokenValue;
$card = $this->getVaultCard( $tokenValue )->LookUpVaultResponse->Status->PayVaultData;
$cardDetail['cardNumber'] = $card[0]->value;
$cardDetail['expDate'] = $card[1]->value;
array_push( $cardDetails, $cardDetail );
foreach ($tokens as $tokenValue) {
$cardDetail['token'] = $tokenValue->token;
$cardDetail['cardNumber'] = $tokenValue->card_number;
$cardDetail['expDate'] = $tokenValue->card_expiry;
array_push($cardDetails, $cardDetail);
}

// Get common module parameters
Expand All @@ -78,19 +75,39 @@ public function secret( $vars )
'forcessl' => false, // Deprecated as of Version 7.0. Requests will always use SSL if available.
'vars' => array(
'modulelink' => $modulelink,
'configTextField' => json_encode( $cardDetails ),
'configTextField' => json_encode($cardDetails),
'customVariable' => 'your own content goes here',
'userId' => $userId,
'userTokens' => $cardDetails,
),
);
}

private function getVaultCard( $vaultId )
public function deleteToken($vars)
{
if ( ! defined('_DB_PREFIX_')) {
define('_DB_PREFIX_', 'tbl');
}

$tokenId = $_GET['tokenId'] ?? null;
if ($tokenId) {
$userId = $_SESSION['uid'] ?? null;
$tblpayhostpaybatchvaults = _DB_PREFIX_ . 'payhostpaybatchvaults';
Capsule::table($tblpayhostpaybatchvaults)
->where('user_id', $userId)
->where('token', $tokenId)
->delete();
}
$dispatcher = new ClientDispatcher();

return $dispatcher->dispatch('secret', []);
}

private function getVaultCard($vaultId)
{
$gatewaySettings = $this->getPayhostGatewayDetail();
// Check for test mode
if ( $gatewaySettings['testMode'] == 'on' ) {
if ($gatewaySettings['testMode'] == 'on') {
$payHostId = '10011072130';
$payHostSecretKey = 'test';
} else {
Expand All @@ -111,54 +128,33 @@ private function getVaultCard( $vaultId )
SOAP;

$wsdl = 'https://secure.paygate.co.za/payhost/process.trans?wsdl';
$sc = new \SoapClient( $wsdl, ['trace' => 1] );
$sc = new SoapClient($wsdl, ['trace' => 1]);
try {
$result = $sc->__soapCall( 'SingleVault', [
// $result = $sc->__soapCall('SingleFollowUp', [
new \SoapVar( $soap, XSD_ANYXML ),
] );
} catch ( \SoapFault $f ) {
return json_encode( $f );
$result = $sc->__soapCall('SingleVault', [
new SoapVar($soap, XSD_ANYXML),
]);
} catch (SoapFault $f) {
return json_encode($f);
}

return $result;
}

private function getPayhostGatewayDetail()
{
if ( !defined( '_DB_PREFIX_' ) ) {
define( '_DB_PREFIX_', 'tbl' );
if ( ! defined('_DB_PREFIX_')) {
define('_DB_PREFIX_', 'tbl');
}
$tblpaymentgateways = _DB_PREFIX_ . 'paymentgateways';
$gatewayValues = Capsule::table( $tblpaymentgateways )
->select( 'setting', 'value' )
->where( 'gateway', 'payhostpaybatch' )
->get();
$gatewaySettings = [];
foreach ( $gatewayValues as $gatewayValue ) {
$gatewayValues = Capsule::table($tblpaymentgateways)
->select('setting', 'value')
->where('gateway', 'payhostpaybatch')
->get();
$gatewaySettings = [];
foreach ($gatewayValues as $gatewayValue) {
$gatewaySettings[$gatewayValue->setting] = $gatewayValue->value;
}
return $gatewaySettings;
}

public function deleteToken( $vars )
{
if ( !defined( '_DB_PREFIX_' ) ) {
define( '_DB_PREFIX_', 'tbl' );
}

$tokenId = $_GET['tokenId'] ?? null;
if ( $tokenId ) {
$userId = $_SESSION['uid'] ?? null;
$tblpayhostpaybatch = _DB_PREFIX_ . 'payhostpaybatch';
Capsule::table( $tblpayhostpaybatch )
->where( 'recordtype', 'clientdetail' )
->where( 'recordid', $userId )
->where( 'recordval', $tokenId )
->delete();

}
$dispatcher = new ClientDispatcher();
return $dispatcher->dispatch( 'secret', [] );
return $gatewaySettings;
}
}
22 changes: 12 additions & 10 deletions modules/addons/payhostpaybatch/payhostpaybatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
use WHMCS\Module\Addon\payhostpaybatch\Admin\AdminDispatcher;
use WHMCS\Module\Addon\payhostpaybatch\Client\ClientDispatcher;

if ( !defined( "WHMCS" ) ) {
die( "This file cannot be accessed directly" );
if ( ! defined("WHMCS")) {
die("This file cannot be accessed directly");
}

/**
Expand Down Expand Up @@ -139,7 +139,7 @@ function payhostpaybatch_deactivate()
*
* @return void
*/
function payhostpaybatch_upgrade( $vars )
function payhostpaybatch_upgrade($vars)
{
}

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

$action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';

$dispatcher = new AdminDispatcher();
$response = $dispatcher->dispatch( $action, $vars );
$response = $dispatcher->dispatch($action, $vars);
echo $response;
}

Expand All @@ -190,7 +190,7 @@ function payhostpaybatch_output( $vars )
*
* @return string
*/
function payhostpaybatch_sidebar( $vars )
function payhostpaybatch_sidebar($vars)
{
// Get common module parameters
$modulelink = $vars['modulelink'];
Expand All @@ -206,6 +206,7 @@ function payhostpaybatch_sidebar( $vars )
$configTextareaField = $vars['Textarea Field Name'];

$sidebar = '<p>Sidebar output HTML goes here</p>';

return $sidebar;
}

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

$action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';

$dispatcher = new ClientDispatcher();
return $dispatcher->dispatch( $action, $vars );

return $dispatcher->dispatch($action, $vars);
}
Loading

0 comments on commit dff0de9

Please sign in to comment.