-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
93875bd
commit c301d64
Showing
109 changed files
with
12,519 additions
and
2 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 |
---|---|---|
@@ -1,2 +1,70 @@ | ||
# utrust-for-whmcs | ||
Utrust for WHMCS (7 and 8) | ||
![Utrust integrations](https://user-images.githubusercontent.com/1558992/67495646-1e356b00-f673-11e9-8854-1beac877c586.png) | ||
|
||
# Utrust for WHMCS | ||
|
||
Accept Bitcoin, Ethereum, Utrust Token and other cryptocurrencies directly on your system with the Utrust payment gateway for WHMCS. | ||
Utrust is cryptocurrency agnostic and provides fiat settlements. | ||
The Utrust plugin extends WHMCS allowing you to take cryptocurrency payments directly on your store via the Utrust API. | ||
Find out more about Utrust at [utrust.com](https://utrust.com). | ||
|
||
## Requirements | ||
|
||
- Utrust Merchant account | ||
- WHMCS version 7 or above | ||
|
||
## Install | ||
|
||
### How to install | ||
|
||
1. Download our latest release zip file on the [releases page](https://github.com/utrustdev/utrust-for-WHMCS/releases). | ||
2. Extract the zip file. | ||
3. Copy the content to your server root folder of WHMCS. | ||
4. Once copied, follow the Setup instructions bellow. | ||
|
||
## Setup | ||
|
||
### On the Utrust side | ||
|
||
1. Go to [Utrust merchant dashboard](https://merchants.utrust.com). | ||
2. Log in or sign up if you didn't yet. | ||
3. On the left sidebar choose _Integrations_. | ||
4. Select _Custom API_ and click the button _Generate Credentials_. | ||
5. You will see now your `Api Key` and `Webhook Secret`, save them somewhere safe temporarily. | ||
|
||
:warning: You will only be able to see the `Webhook Secret` once, after refreshing or changing page it will be no longer available to copy; if needed, you can always generate new credentials. | ||
|
||
:no_entry_sign: Don't share your credentials with anyone. They can use it to place orders **on your behalf**. | ||
|
||
### On the WHMCS side | ||
|
||
1. Go to your WHMCS admin dashboard. | ||
2. Navigate to the _Modules and Services_ -> _Modules and Services_. | ||
3. Search for _Utrust_ in the list and click _Configure_ | ||
4. Add your `Api Key` and `Webhook Secret` and click Save. | ||
|
||
5. Go to your WHMCS admin dashboard. | ||
6. Navigate to _System Settings_ -> _Payment Gateways_ -> _All Payment Gateways_ and activate Utrust. | ||
7. Navigate to _System Settings_ -> _Payment Gateways_ -> _Manager Existing Gateways_. | ||
8. Add your `Api Key` and `Webhook Secret` and Save. | ||
|
||
## Support | ||
|
||
Feel free to reach [by opening an issue on GitHub](https://github.com/utrustdev/utrust-for-WHMCS/issues/new) if you need any help with the Utrust for WHMCS plugin. | ||
|
||
If you're having specific problems with your account, then please contact [email protected]. | ||
|
||
In both cases, our team will be happy to help :purple_heart:. | ||
|
||
## Contribute | ||
|
||
You can contribute by simply letting us know your suggestions or any problems that you find [by opening an issue on GitHub](https://github.com/utrustdev/utrust-for-WHMCS/issues/new). | ||
|
||
You can also fork the repository on GitHub and open a pull request for the `master` branch with your missing features and/or bug fixes. | ||
Please make sure the new code follows the same style and conventions as already written code. | ||
Our team is eager to welcome new contributors into the mix :blush:. | ||
|
||
## License | ||
|
||
The Utrust for WHMCS plugin is maintained with :purple_heart: by the Utrust development team, and is available to the public under the GNU GPLv3 license. Please see [LICENSE](https://github.com/utrustdev/utrust-for-WHMCS/blob/master/LICENSE) for further details. | ||
|
||
© Utrust 2020 |
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,102 @@ | ||
|
||
<?php | ||
|
||
// Require libraries needed for gateway module functions. | ||
require_once __DIR__ . '/../../../init.php'; | ||
require_once __DIR__ . '/../../../includes/gatewayfunctions.php'; | ||
require_once __DIR__ . '/../../../includes/invoicefunctions.php'; | ||
|
||
// Require libraries needed for utrust | ||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
use Utrust\Webhook\Event; | ||
|
||
// Detect module name from filename. | ||
$gatewayModuleName = basename(__FILE__, '.php'); | ||
|
||
// Fetch gateway configuration parameters. | ||
$gatewayParams = getGatewayVariables($gatewayModuleName); | ||
|
||
// Die if module is not active. | ||
if (!$gatewayParams['type']) { | ||
die("Module Not Activated"); | ||
} | ||
|
||
//call Webhooks | ||
$webhooksSecret = $gatewayParams['webhooks_key']; | ||
|
||
// Validate payload | ||
$payload = file_get_contents('php://input'); | ||
try { | ||
$event = new Event($payload); | ||
$event->validateSignature($webhooksSecret); | ||
http_response_code(200); // Don't delete this | ||
|
||
echo sprintf('Successully validated payload with order reference %s and type %s', $event->getOrderReference(), $event->getEventType()); | ||
|
||
} catch (\Exception $exception) { | ||
http_response_code(400); // Don't delete this | ||
|
||
// Handle webhook error | ||
echo 'Error: ' . $exception->getMessage(); | ||
} | ||
|
||
// Change payload data to whmcs variables | ||
$json = json_decode($payload, true); | ||
$status = $json['state']; | ||
$success = false; | ||
if ($status == "completed") { | ||
$status = "Success"; | ||
$success = true; | ||
} | ||
|
||
// Varies per payment gateway | ||
$transactionId = $json['resource']['reference']; | ||
$invoiceId = (int) $transactionId; | ||
$paymentAmount = (float) $json['resource']['amount']; | ||
$paymentFee = 0.00; | ||
|
||
// remove when bug was fix --------------------------------------\/ | ||
|
||
$milliseconds = round(microtime(true) * 1000); | ||
$firstnum = substr($milliseconds, 12, 1); | ||
$secondnum = substr($milliseconds, 11, 1); | ||
$thirdnum = substr($milliseconds, 10, 1); | ||
$total = $firstnum + $secondnum + $thirdnum; | ||
sleep($total); | ||
|
||
$firstsleep = rand(0, 5); | ||
$secondsleep = rand(0, 5); | ||
while ($firstsleep == $secondsleep) { | ||
$firstsleep = rand(0, 2); | ||
} | ||
|
||
sleep($firstsleep); | ||
sleep($secondsleep); | ||
// remove when bug was fix --------------------------------------/\ | ||
|
||
// transaction STATUS | ||
$transactionStatus = $success ? 'Success' : 'Failure'; | ||
|
||
// InvoiceId Check | ||
$invoiceId = checkCbInvoiceID($invoiceId, $gatewayParams['name']); | ||
|
||
// TransactionId Check | ||
checkCbTransID($transactionId); | ||
|
||
// Send Log Transaction | ||
logTransaction($gatewayParams['name'], $milliseconds . "-" . $total . $payload, $transactionStatus); | ||
|
||
// If status is Success then Add Invoice Payment | ||
if ($status == 'Success') { | ||
|
||
addInvoicePayment( | ||
$invoiceId, | ||
$transactionId, | ||
$paymentAmount, | ||
$paymentFee, | ||
$gatewayModuleName | ||
); | ||
|
||
} | ||
|
||
?> |
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,174 @@ | ||
<?php | ||
require_once __DIR__ . '/vendor/autoload.php'; | ||
use Utrust\ApiClient; | ||
use Utrust\Validator; | ||
|
||
if (!defined("WHMCS")) { | ||
die("This file cannot be accessed directly"); | ||
} | ||
|
||
// Configure Gateway Data | ||
function utrust_MetaData() | ||
{ | ||
return array( | ||
'DisplayName' => 'Utrust', | ||
'APIVersion' => '1.1', // Use API Version 1.1 | ||
'DisableLocalCredtCardInput' => true, | ||
'TokenisedStorage' => false, | ||
); | ||
} | ||
|
||
// Configure Gateway configurations | ||
function utrust_config() | ||
{ | ||
return array( | ||
// the friendly display name for a payment gateway should be | ||
// defined here for backwards compatibility | ||
'FriendlyName' => array( | ||
'Type' => 'System', | ||
'Value' => 'Utrust', | ||
), | ||
'api_key' => array( | ||
'Type' => 'text', | ||
'Default' => '', | ||
'Description' => 'Insert API Key', | ||
), | ||
'webhooks_key' => array( | ||
'Type' => 'text', | ||
'Default' => '', | ||
'Description' => 'Insert Webhooks key', | ||
), | ||
'testMode' => array( | ||
'FriendlyName' => 'Test Mode', | ||
'Type' => 'yesno', | ||
'Description' => 'Tick to enable test mode', | ||
), | ||
); | ||
} | ||
|
||
function utrust_link($params) | ||
{ | ||
|
||
// Gateway Configuration Parameters | ||
$accountId = $params['accountID']; | ||
$secretKey = $params['secretKey']; | ||
$dropdownField = $params['dropdownField']; | ||
$radioField = $params['radioField']; | ||
$textareaField = $params['textareaField']; | ||
$successurl = $params['returnurl'] . "&paymentsuccess=true"; | ||
$failurl = $params['returnurl'] . "&paymentfailed=true"; | ||
$api_key = $params['api_key']; | ||
$webhooks_key = $params['webhooks_key']; | ||
|
||
// TestMode verify | ||
if ($params['testMode'] == 'on') { | ||
$testMode = 'sandbox'; | ||
} else { | ||
$testMode = 'production'; | ||
} | ||
|
||
// Invoice Parameters | ||
$invoiceId = $params['invoiceid']; | ||
$description = $params["description"]; | ||
$amount = $params['amount']; | ||
$currencyCode = $params['currency']; | ||
$transid = $params['transid']; | ||
|
||
// 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']; | ||
|
||
$postfields = array(); | ||
$postfields['username'] = $username; | ||
$postfields['invoice_id'] = $invoiceId; | ||
$postfields['description'] = $description; | ||
$postfields['amount'] = $amount; | ||
$postfields['currency'] = $currencyCode; | ||
$postfields['first_name'] = $firstname; | ||
$postfields['last_name'] = $lastname; | ||
$postfields['email'] = $email; | ||
$postfields['address1'] = $address1; | ||
$postfields['address2'] = $address2; | ||
$postfields['city'] = $city; | ||
$postfields['state'] = $state; | ||
$postfields['postcode'] = $postcode; | ||
$postfields['country'] = $country; | ||
$postfields['phone'] = $phone; | ||
$callback = $systemUrl . '/modules/gateways/callback/utrust.php'; | ||
|
||
// Utrust | ||
$utrustApi = new ApiClient($api_key, $testMode); | ||
|
||
// Build Order data array | ||
$orderData = [ | ||
'reference' => "$invoiceId", | ||
'amount' => [ | ||
'total' => $amount, | ||
'currency' => $currencyCode, | ||
], | ||
'return_urls' => [ | ||
'return_url' => $successurl, | ||
'cancel_url' => $failurl, | ||
'callback_url' => $callback, | ||
], | ||
'line_items' => [ | ||
[ | ||
'sku' => "$invoiceId", | ||
'name' => $description, | ||
'price' => $amount, | ||
'currency' => $currencyCode, | ||
'quantity' => 1, | ||
], | ||
], | ||
]; | ||
|
||
// Build Customer data array | ||
$customerData = [ | ||
'first_name' => $firstname, | ||
'last_name' => $lastname, | ||
'email' => $email, | ||
'country' => $country, | ||
]; | ||
try { | ||
// Validate data | ||
$orderIsValid = Validator::order($orderData); | ||
$customerIsValid = Validator::customer($customerData); | ||
|
||
// Make the API request | ||
if ($orderIsValid == true && $customerIsValid == true) { | ||
$response = $utrustApi->createOrder($orderData, $customerData); | ||
} | ||
|
||
// Use the $redirect_url to redirect the customer to our Payment Widget | ||
//echo $response->attributes->redirect_url; | ||
} catch (Exception $e) { | ||
// Handle error (e.g.: show message to the customer) | ||
echo 'Something went wrong: ' . $e->getMessage(); | ||
} | ||
|
||
// Return url link to pay | ||
$htmlOutput = '<form method="post" action="' . $response->attributes->redirect_url . '">'; | ||
foreach ($postfields as $k => $v) { | ||
$htmlOutput .= '<input type="hidden" name="' . $k . '" value="' . urlencode($v) . '" />'; | ||
} | ||
$htmlOutput .= '<input type="submit" value="' . $langPayNow . '" />'; | ||
$htmlOutput .= '</form>'; | ||
return $htmlOutput; | ||
} |
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,7 @@ | ||
<?php | ||
|
||
// autoload.php @generated by Composer | ||
|
||
require_once __DIR__ . '/composer/autoload_real.php'; | ||
|
||
return ComposerAutoloaderInit4d59f6df2bd1b818801c4a5877064a6f::getLoader(); |
Oops, something went wrong.