-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d979a94
Showing
8 changed files
with
467 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.tar.gz | ||
ioncube_* | ||
ioncube_loader_* | ||
*.code-workspace | ||
whmcs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
## Esewa Payment Gateway Plugin for WHMCS | ||
|
||
eSewa Payment Gateway as a payment method in your WHMCS Panel. | ||
|
||
The eSewa payment plugin for WHMCS was created separate from the eSewa company. There are no connections between any of the plugin's creators and any of these two businesses. | ||
|
||
## Folder Structure | ||
|
||
``` | ||
├── modules | ||
│ ├── gateways | ||
| | |── callback | ||
| | └────── esewa.php | ||
| | |── esewa | ||
| | └────── helper.php | ||
| | └────── init.php | ||
| | └────── logo.png | ||
| | └────── whmcs.json | ||
| ├── esewa.php | ||
├── .gitignore | ||
└── README.md | ||
``` | ||
|
||
## Features | ||
|
||
- Order Invoice Payment | ||
- Manual Invoice Payment | ||
|
||
## Installation | ||
|
||
How to install plugin in WHMCS | ||
|
||
- Go to the appropriate interface in the WHMCS Admin Area. ... | ||
- Find the desired payment gateway in the list (for example, Stripe) and click on it. | ||
- Click Activate. | ||
- Click Save Changes. | ||
|
||
Check out the installation guide and configuration of WHMCS Panel [Documentation](https://help.whmcs.com/m/setup/l/1075240-configuring-your-first-payment-gateway) | ||
|
||
## Documentation | ||
Check out the installation guide and configuration of [WHMCS Panel](https://help.whmcs.com/m/setup/l/1075240-configuring-your-first-payment-gateway) | ||
|
||
- Click on active button | ||
- Click on manage button and update your merchant code | ||
|
||
## License | ||
|
||
The eSewa WHMCS module is open-sourced software licensed under the [MIT license.](https://opensource.org/license/mit/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<?php | ||
|
||
/** | ||
* WHMCS eSewa Payment Gateway Module - Callback Script | ||
* | ||
* This script handles the callback response from the eSewa payment gateway. | ||
* It updates the payment status in WHMCS based on the callback response. | ||
* | ||
* For more information, please refer to the online documentation. | ||
* | ||
* @see https://github.com/surazdott/esewa-whmcs | ||
* | ||
* @copyright Copyright (c) Suraj Datheputhe | ||
* @author : @Suraj Datheputhe | ||
*/ | ||
|
||
# Include the WHMCS initialization file | ||
require_once __DIR__ . '/../../../init.php'; | ||
require_once __DIR__ . '/../../../includes/gatewayfunctions.php'; | ||
require_once __DIR__ . '/../../../includes/invoicefunctions.php'; | ||
|
||
# Require libraries | ||
require_once __DIR__ . '/../esewa/init.php'; | ||
|
||
# Get module name | ||
$gatewayModuleName = basename(__FILE__, '.php'); | ||
|
||
# Get the gateway module parameters | ||
$gatewayParams = getGatewayVariables($gatewayModuleName); | ||
|
||
# Check if the gateway is activated | ||
if (!$gatewayParams['type']) { | ||
die("Module Not Activated"); | ||
} | ||
|
||
# Variable per payment gateway | ||
$invoiceId = decodeInvoice($_GET['oid']); | ||
$transactionId = $_GET['refId']; | ||
$paymentAmount = $_GET['amt']; | ||
$transactionStatus = $transactionId != null ? 'Success' : 'Failure'; | ||
|
||
/** | ||
* Validate Callback Invoice ID. | ||
* | ||
* Checks invoice ID is a valid invoice number. Note it will count an | ||
* invoice in any status as valid. | ||
* | ||
* Performs a die upon encountering an invalid Invoice ID. | ||
* | ||
* Returns a normalised invoice ID. | ||
* | ||
* @param int $invoiceId Invoice ID | ||
* @param string $gatewayName Gateway Name | ||
*/ | ||
|
||
$invoiceId = checkCbInvoiceID($invoiceId, $gatewayParams['gatewayParams']); | ||
|
||
/** | ||
* Get invoice number | ||
* | ||
* @param int invoiceId | ||
* @return data | ||
*/ | ||
$invoice = WHMCS\Billing\Invoice::find($invoiceId); | ||
|
||
|
||
/** | ||
* Validate invoice amount | ||
* | ||
* @return boolean | ||
*/ | ||
if ($invoice->total != $paymentAmount) { | ||
$failedUrl = $gatewayParams['systemurl'].'/viewinvoice.php?id='.$invoiceId.'&paymentfailed=true'; | ||
redirect($failedUrl); | ||
} else { | ||
|
||
/** | ||
* Log Transaction. | ||
* | ||
* Add an entry to the Gateway Log for debugging purposes. | ||
* | ||
* The debug data can be a string or an array. In the case of an | ||
* array it will be | ||
* | ||
* @param string $gatewayName Display label | ||
* @param string|array $debugData Data to log | ||
* @param string $transactionStatus Status | ||
*/ | ||
|
||
logTransaction($gatewayModuleName, $_GET, $transactionStatus); | ||
|
||
/** | ||
* Payment Verification Process and Update Invoice Paid | ||
* | ||
* @param int invoiceId | ||
* @param string transactionId | ||
*/ | ||
|
||
$url = $gatewayParams['testMode'] == true ? | ||
'https://uat.esewa.com.np/epay/transrec' : | ||
'https://esewa.com.np/epay/transrec'; | ||
|
||
$paymentData = [ | ||
'amt'=> $_GET['amt'], | ||
'rid'=> $_GET['refId'], | ||
'pid'=> $_GET['oid'], | ||
'scd'=> $gatewayParams['MerchantCode'] | ||
]; | ||
|
||
$curl = curl_init($url); | ||
curl_setopt($curl, CURLOPT_POST, true); | ||
curl_setopt($curl, CURLOPT_POSTFIELDS, $paymentData); | ||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | ||
|
||
$result = curl_exec($curl); | ||
curl_close($curl); | ||
|
||
$response = (string) simplexml_load_string($result)->response_code; | ||
|
||
if (strpos($response, 'Success') == true) { | ||
$paymentFee = '0.0'; | ||
|
||
/** | ||
* Add Invoice Payment. | ||
* | ||
* Applies a payment transaction entry to the given invoice ID. | ||
* | ||
* @param int $invoiceId Invoice ID | ||
* @param string $transactionId Transaction ID | ||
* @param float $paymentAmount Amount paid (defaults to full balance) | ||
* @param float $paymentFee Payment fee (optional) | ||
* @param string $gatewayModule Gateway module name | ||
*/ | ||
addInvoicePayment( | ||
$invoiceId, | ||
$transactionId, | ||
$paymentAmount, | ||
$paymentFee, | ||
$gatewayModuleName | ||
); | ||
|
||
$successUrl = $gatewayParams['systemurl'].'/viewinvoice.php?id='.$invoiceId.'&paymentsuccess=true'; | ||
redirect($successUrl); | ||
} else { | ||
$failedUrl = $gatewayParams['systemurl'].'/viewinvoice.php?id='.$invoiceId.'&paymentfailed=true'; | ||
redirect($failedUrl); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
<?php | ||
|
||
/** | ||
* WHMCS eSewa Payment Gateway Module | ||
* | ||
* eSewa Payment Gateway modules WHMCS platform. | ||
* | ||
* For more information, please refer to the online documentation. | ||
* | ||
* @see https://github.com/surazdott/esewa-whmcs | ||
* | ||
* @copyright Copyright (c) Suraj Datheputhe | ||
* @author : @Suraj Datheputhe | ||
*/ | ||
|
||
if (!defined("WHMCS")) { | ||
die("This file cannot be accessed directly"); | ||
} | ||
|
||
# Require libraries | ||
require_once __DIR__ . '/esewa/init.php'; | ||
|
||
/** | ||
* Define module related meta data. | ||
* | ||
* Values returned here are used to determine module related abilities and | ||
* settings. | ||
* | ||
* @see https://developers.whmcs.com/provisioning-modules/meta-data-params/ | ||
* | ||
* @return array | ||
*/ | ||
function esewa_MetaData() | ||
{ | ||
return array( | ||
'DisplayName' => 'eSewa Payment Gateway', | ||
'APIVersion' => '1.1', | ||
'DisableLocalCreditCardInput' => true, | ||
'TokenisedStorage' => false, | ||
); | ||
} | ||
|
||
/** | ||
* Define eSewa configuration options. | ||
* | ||
* @see https://developers.whmcs.com/provisioning-modules/config-options/ | ||
* | ||
* @return array | ||
*/ | ||
function esewa_config() | ||
{ | ||
return array( | ||
'FriendlyName' => array( | ||
'Type' => 'System', | ||
'Value' => 'eSewa Payment Gateway', | ||
), | ||
'MerchantCode' => array( | ||
'FriendlyName' => 'Merchant Code', | ||
'Type' => 'password', | ||
'Size' => '25', | ||
'Default' => '', | ||
'Description' => 'Enter your Merchant Code here provided by eSewa', | ||
), | ||
'testMode' => array( | ||
'FriendlyName' => 'Test Mode', | ||
'Type' => 'yesno', | ||
'Description' => 'Tick to enable test mode', | ||
), | ||
); | ||
} | ||
|
||
/** | ||
* eSewa Payment Gateway link. | ||
* | ||
* | ||
* Defines the HTML output displayed on an invoice. Typically consists of an | ||
* HTML form that will take the user to the payment gateway endpoint. | ||
* | ||
* @param array $params Payment Gateway Module Parameters | ||
* | ||
* @see https://developers.whmcs.com/payment-gateways/third-party-gateway/ | ||
* | ||
* @return string | ||
*/ | ||
function esewa_link($params) | ||
{ | ||
// Gateway Configuration Parameters | ||
$testMode = $params['testMode']; | ||
$merchantCode = $params['MerchantCode']; | ||
|
||
// Invoice Parameters | ||
$invoiceId = $params['invoiceid']; | ||
$description = $params["description"]; | ||
$amount = $params['amount']; | ||
$currencyCode = $params['currency']; | ||
|
||
// Client Parameters | ||
$firstname = $params['clientdetails']['firstname']; | ||
$lastname = $params['clientdetails']['lastname']; | ||
$email = $params['clientdetails']['email']; | ||
$address1 = $params['clientdetails']['address1']; | ||
$address2 = $params['clientdetails']['address2']; | ||
$city = $params['clientdetails']['city']; | ||
$state = $params['clientdetails']['state']; | ||
$postcode = $params['clientdetails']['postcode']; | ||
$country = $params['clientdetails']['country']; | ||
$phone = $params['clientdetails']['phonenumber']; | ||
|
||
// System Parameters | ||
$companyName = $params['companyname']; | ||
$systemUrl = $params['systemurl']; | ||
$returnUrl = $params['returnurl']; | ||
$langPayNow = $params['langpaynow']; | ||
$moduleDisplayName = $params['name']; | ||
$moduleName = $params['paymentmethod']; | ||
$whmcsVersion = $params['whmcsVersion']; | ||
|
||
$url = $params['testMode'] == true ? 'https://uat.esewa.com.np/epay/main' : 'https://esewa.com.np/epay/main'; | ||
|
||
$postfields = array(); | ||
$postfields['pid'] = encodeInvoice($invoiceId); | ||
$postfields['tAmt'] = $amount; | ||
$postfields['amt'] = $amount; | ||
$postfields['txAmt'] = '0'; | ||
$postfields['psc'] = '0'; | ||
$postfields['pdc'] = '0'; | ||
$postfields['scd'] = $merchantCode; | ||
$postfields['su'] = $systemUrl . '/modules/gateways/callback/' . $moduleName . '.php'; | ||
$postfields['fu'] = $returnUrl; | ||
|
||
$htmlOutput = '<form method="post" action="' . $url . '">'; | ||
|
||
foreach ($postfields as $k => $v) { | ||
$htmlOutput .= '<input type="hidden" name="' . $k . '" value="' . $v . '" />'; | ||
} | ||
|
||
$logo = $systemUrl . '/modules/gateways/esewa/logo.png'; | ||
|
||
$htmlOutput .= '<img src="'.$logo.'" width="130"><br>'; | ||
|
||
$htmlOutput .= '<input class="btn btn-success" type="submit" value="' . $langPayNow . '" />'; | ||
$htmlOutput .= '</form>'; | ||
|
||
return $htmlOutput; | ||
} | ||
|
||
/** | ||
* eSewa Payment Gateway refund transaction. | ||
* | ||
* Called when a refund is requested for a previously successful transaction. | ||
* | ||
* @param array $params Payment Gateway Module Parameters | ||
* | ||
* @see https://developers.whmcs.com/payment-gateways/refunds/ | ||
* | ||
* @return array Transaction response status | ||
*/ | ||
function esewa_refund($params) | ||
{ | ||
return false; | ||
} |
Oops, something went wrong.