Skip to content

Commit

Permalink
Merge pull request #2 from Sellix/New-Code-11
Browse files Browse the repository at this point in the history
Initial Version - 1.1
  • Loading branch information
committedpro authored Mar 24, 2023
2 parents be7f213 + c01ad15 commit 2e56200
Show file tree
Hide file tree
Showing 9 changed files with 539 additions and 417 deletions.
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

39 changes: 39 additions & 0 deletions modules/gateways/callback/sellixpay/return.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* WHMCS Sellix Pay Payment Gateway Module Return Page
*
* @copyright Copyright (c) WHMCS Limited 2023
* @license http://www.whmcs.com/license/ WHMCS Eula
*/

require_once __DIR__ . '/../../../../init.php';
require_once __DIR__ . '/../../../../includes/gatewayfunctions.php';
require_once __DIR__ . '/../../../../includes/invoicefunctions.php';
require_once __DIR__ . '/../../../../modules/gateways/sellixpay.php';

$gatewayModuleName = 'sellixpay';

$gatewayParams = getGatewayVariables($gatewayModuleName);

if (!$gatewayParams['type']) {
die("Module Not Activated");
}

try {
if (isset($_REQUEST["invoiceid"]) && !empty($_REQUEST["invoiceid"])) {
$invoiceid = $_REQUEST["invoiceid"];
$invoiceid = trim($invoiceid);
$invoiceid = (int)$invoiceid;
$systemUrl = $gatewayParams['systemurl'];
$redirectUrl = $systemUrl.'/viewinvoice.php?id='.$invoiceid;
sellixRedirect($redirectUrl);
} else {
throw new \Exception('Empty response received from gateway.');
}
} catch (\Exception $e) {
$error_message = $e->getMessage();
sellixLog($gatewayParams['name'], $error_message, 'Return from gateway');
$htmlOutput = '<h6 style="color:red">An error occurred while returning from payment gateway: '.$error_message.'</h6>';
echo $htmlOutput;
exit;
}
73 changes: 73 additions & 0 deletions modules/gateways/callback/sellixpay/webhook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* WHMCS Sellix Pay Payment Gateway Module Webhook Page
*
* @copyright Copyright (c) WHMCS Limited 2023
* @license http://www.whmcs.com/license/ WHMCS Eula
*/

require_once __DIR__ . '/../../../../init.php';
require_once __DIR__ . '/../../../../includes/gatewayfunctions.php';
require_once __DIR__ . '/../../../../includes/invoicefunctions.php';
require_once __DIR__ . '/../../../../modules/gateways/sellixpay.php';

$jsonData = file_get_contents('php://input');
$data = json_decode($jsonData, true);

$gatewayModuleName = 'sellixpay';
$gatewayParams = getGatewayVariables($gatewayModuleName);

try {

sellixLog($gatewayParams['name'], $data, 'Webhook received data');

if ((null === $data['data']) || (null === $data['data']['uniqid']) || empty($data['data']['uniqid'])) {
$message = 'Sellixpay: suspected fraud. Code-001';
throw new \Exception($message);
}

$sellix_order = sellixValidSellixOrder($gatewayParams, $data['data']['uniqid']);

if (isset($_REQUEST["invoiceid"]) && !empty($_REQUEST["invoiceid"])) {
$invoiceid = $_REQUEST["invoiceid"];
$invoiceid = trim($invoiceid);
$invoiceid = (int)$invoiceid;

$transactionId = $sellix_order['uniqid'];
$paymentAmount = $sellix_order['total'];
$message1 = 'Invoice #' . $invoiceid;
$message2 = ' (' . $sellix_order['uniqid'] . '). Status: ' . $sellix_order['status'];

updateSellixpayOrder($invoiceid, 'status', $sellix_order['status']);
updateSellixpayOrder($invoiceid, 'transaction_id', $transactionId);
updateSellixpayOrder($invoiceid, 'response', json_encode($sellix_order));

sellixLog($gatewayParams['name'], $message1.$message2, 'Webhook Concern Invoice');

$invoiceId = checkCbInvoiceID($invoiceid, $gatewayParams['name']);
checkCbTransID($transactionId);

if ($sellix_order['status'] == 'PROCESSING') {
addInvoicePayment($invoiceid,$transactionId,$paymentAmount,0,$gatewayModuleName);
} elseif ($sellix_order['status'] == 'COMPLETED') {
addInvoicePayment($invoiceid,$transactionId,$paymentAmount,0,$gatewayModuleName);
} elseif ($sellix_order['status'] == 'WAITING_FOR_CONFIRMATIONS') {

} elseif ($sellix_order['status'] == 'PARTIAL') {

} elseif ($sellix_order['status'] == 'PENDING') {

}
} else {
throw new \Exception('Empty response received from gateway.');
}
} catch (\Exception $e) {
$error_message = $e->getMessage();
$message = 'Payment error. '.$error_message;
sellixLog($gatewayParams['name'], $message, 'Webhook from Gateway Catch');
echo $message;
exit;

}
echo 'Web hook finished';
exit;
99 changes: 0 additions & 99 deletions modules/gateways/callback/sellixpayment.php

This file was deleted.

Loading

0 comments on commit 2e56200

Please sign in to comment.