-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from dzung2t/master
Add Brick support
- Loading branch information
Showing
9 changed files
with
380 additions
and
5 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,109 @@ | ||
<?php | ||
define("CLIENTAREA", true); | ||
define("FORCESSL", true); | ||
|
||
include("init.php"); | ||
require_once(ROOTDIR . '/includes/api/paymentwall_api/lib/paymentwall.php'); | ||
$whmcs->load_function('gateway'); | ||
$whmcs->load_function('clientarea'); | ||
$whmcs->load_function('invoice'); | ||
|
||
$gateway = getGatewayVariables("brick"); | ||
|
||
$whmcsVer = substr($CONFIG['Version'], 0, 1); | ||
if ($whmcsVer <= 5) { | ||
$gateways = new WHMCS_Gateways(); | ||
} else { | ||
$gateways = new WHMCS\Gateways(); | ||
} | ||
$publicKey = $gateway['isTest'] ? $gateway['publicTestKey'] : $gateway['publicKey']; | ||
Paymentwall_Config::getInstance()->set(array( | ||
'api_type' => Paymentwall_Config::API_GOODS, | ||
'public_key' => $publicKey, // available in your Paymentwall merchant area | ||
'private_key' => $gateway['isTest'] ? $gateway['privateTestKey'] : $gateway['privateKey'] // available in your Paymentwall merchant area | ||
)); | ||
|
||
$pagetitle = $_LANG['clientareatitle'] . " - Pay via Brick (Powered by Paymentwall)"; | ||
initialiseClientArea($pagetitle, '', 'Pay via Brick'); | ||
|
||
# Check login status | ||
if ($_SESSION['uid'] && isset($_POST['data']) && $post = json_decode(decrypt($_POST['data']), true)) { | ||
|
||
$smartyvalues = array_merge($smartyvalues, $post); | ||
$smartyvalues["data"] = $_POST['data']; | ||
$smartyvalues["whmcsVer"] = $whmcsVer; | ||
$smartyvalues["publicKey"] = $publicKey; | ||
$smartyvalues["processingerror"] = ''; | ||
$smartyvalues["success"] = false; | ||
|
||
if ($_POST['frominvoice'] == "true" || $_POST['fromCCForm'] == 'true') { | ||
|
||
if ($whmcsVer <= 5) { | ||
$invoice = new WHMCS_Invoice(); | ||
} else { | ||
$invoice = new WHMCS\Invoice(); | ||
} | ||
$invoice->setID($_POST["invoiceid"]); | ||
$invoiceData = $invoice->getOutput(); | ||
|
||
// Prepare form data | ||
$smartyvalues["client"] = $invoiceData['clientsdetails']; | ||
$smartyvalues['months'] = $gateways->getCCDateMonths(); | ||
$smartyvalues['years'] = $gateways->getCCExpiryDateYears(); | ||
$smartyvalues['invoice'] = $invoiceData; | ||
$smartyvalues['invoiceItems'] = $invoice->getLineItems(); | ||
|
||
if ($_POST['fromCCForm'] == 'true') { # Check form submit & capture payment | ||
|
||
$cardInfo = array( | ||
'email' => $invoiceData['clientsdetails']['email'], | ||
'amount' => $post['amount'], | ||
'currency' => $post["currency"], | ||
'token' => $_POST['brick_token'], | ||
'fingerprint' => $_POST['brick_fingerprint'], | ||
'description' => $invoiceData['pagetitle'] | ||
); | ||
|
||
$charge = new Paymentwall_Charge(); | ||
$charge->create(array_merge( | ||
$cardInfo, | ||
brick_get_user_profile_data($invoiceData) | ||
)); | ||
$response = $charge->getPublicData(); | ||
|
||
if ($charge->isSuccessful()) { | ||
if ($charge->isCaptured()) { | ||
addInvoicePayment($_POST["invoiceid"], $charge->getId(), null, null, 'brick'); | ||
} elseif ($charge->isUnderReview()) { | ||
// decide on risk charge | ||
} | ||
$smartyvalues["success"] = true; | ||
} else { | ||
$error = json_decode($response, true); | ||
$smartyvalues["processingerror"] = '<li>' . $error['error']['message'] . '</li>'; | ||
} | ||
|
||
} | ||
|
||
} else { // User is logged in but they shouldn't be here (i.e. they weren't here from an invoice) | ||
header("Location: " . $CONFIG['SystemURL'] . "/clientarea.php?action=details"); | ||
} | ||
} else { | ||
header("Location: " . $CONFIG['SystemURL'] . "/"); | ||
} | ||
|
||
outputClientArea("/modules/gateways/paymentwall/templates/ccform.tpl"); | ||
|
||
function brick_get_user_profile_data($params) | ||
{ | ||
return array( | ||
'customer[city]' => $params['clientsdetails']['city'], | ||
'customer[state]' => $params['clientsdetails']['fullstate'], | ||
'customer[address]' => $params['clientsdetails']['address1'], | ||
'customer[country]' => $params['clientsdetails']['countrycode'], | ||
'customer[zip]' => $params['clientsdetails']['postcode'], | ||
'customer[username]' => $params['clientsdetails']['userid'] ? $params['clientsdetails']['userid'] : $params['clientsdetails']['email'], | ||
'customer[firstname]' => $params['clientsdetails']['firstname'], | ||
'customer[lastname]' => $params['clientsdetails']['lastname'], | ||
); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,50 @@ | ||
<?php | ||
if (!defined("WHMCS")) { | ||
exit("This file cannot be accessed directly"); | ||
} | ||
|
||
function brick_config() | ||
{ | ||
$configarray = array( | ||
"FriendlyName" => array("Type" => "System", "Value" => "Brick (Powered by Paymentwall)"), | ||
"publicKey" => array("FriendlyName" => "Public Key", "Type" => "text", "Size" => "20",), | ||
"privateKey" => array("FriendlyName" => "Private Key", "Type" => "text", "Size" => "20",), | ||
"publicTestKey" => array("FriendlyName" => "Public Test Key", "Type" => "text", "Size" => "20",), | ||
"privateTestKey" => array("FriendlyName" => "Private Test Key", "Type" => "text", "Size" => "20",), | ||
"isTest" => array("FriendlyName" => "Is Test", "Type" => "yesno", "Size" => "5",), | ||
); | ||
return $configarray; | ||
} | ||
|
||
function init_brick_config($params) | ||
{ | ||
require_once(ROOTDIR . '/includes/api/paymentwall_api/lib/paymentwall.php'); | ||
Paymentwall_Config::getInstance()->set(array( | ||
'api_type' => Paymentwall_Config::API_GOODS, | ||
'public_key' => $params['isTest'] ? $params['publicTestKey'] : $params['publicKey'], // available in your Paymentwall merchant area | ||
'private_key' => $params['isTest'] ? $params['privateTestKey'] : $params['privateKey'] // available in your Paymentwall merchant area | ||
)); | ||
} | ||
|
||
function brick_link($params) | ||
{ | ||
global $CONFIG; | ||
|
||
init_brick_config($params); | ||
# Invoice Variables | ||
$invoiceid = $params['invoiceid']; | ||
|
||
# Enter your code submit to the gateway... | ||
$code = '<form method="post" action="' . $CONFIG['SystemURL'] . '/brickccform.php"> | ||
<input type="hidden" name="data" value="' . encrypt(json_encode(array( | ||
'invoiceid' => $params['invoiceid'], | ||
'description' => $params['description'], | ||
'amount' => $params['amount'], | ||
'currency' => $params['currency'] | ||
))) . '" /> | ||
<input type="hidden" name="invoiceid" value="' . $invoiceid . '" /> | ||
<input type="hidden" name="frominvoice" value="true" /> | ||
<button type="submit">Pay via <img src="' . $CONFIG['SystemURL'] . '/images/paymentwall/brick_logo.png" alt="Pay via Brick" /></button> | ||
</form>'; | ||
return $code; | ||
} |
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
Empty file.
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,176 @@ | ||
{if $whmcsVer <= 5} | ||
{include file="$template/pageheader.tpl" showbreadcrumb=false} | ||
{else} | ||
{include file="$template/includes/pageheader.tpl" showbreadcrumb=false} | ||
{/if} | ||
|
||
{if $success != true} | ||
<div class="alert alert-danger" id="payment-errors" {if !$processingerror}style="display: none"{/if}> | ||
<strong>The following errors occurred:</strong> | ||
<ul id="error-list"> | ||
{$processingerror} | ||
</ul> | ||
</div> | ||
<form class="form-horizontal" action="" method="POST" id="payment-form"> | ||
<div class="col-md-5"> | ||
<div id="invoiceIdSummary" class="invoice-summary"> | ||
<h2 class="text-center">{$LANG.invoicenumber}{$invoiceid}</h2> | ||
|
||
<div class="invoice-summary-table"> | ||
<table class="table table-condensed"> | ||
<tr> | ||
<td class="text-center"><strong>{$LANG.invoicesdescription}</strong></td> | ||
<td width="150" class="text-center"><strong>{$LANG.invoicesamount}</strong></td> | ||
</tr> | ||
{foreach $invoiceItems as $item} | ||
<tr> | ||
<td>{$item.description}</td> | ||
<td class="text-center">{$item.amount}</td> | ||
</tr> | ||
{/foreach} | ||
<tr> | ||
<td class="total-row text-right">{$LANG.invoicessubtotal}</td> | ||
<td class="total-row text-center">{$invoice.subtotal}</td> | ||
</tr> | ||
{if $invoice.taxrate} | ||
<tr> | ||
<td class="total-row text-right">{$invoice.taxrate}% {$invoice.taxname}</td> | ||
<td class="total-row text-center">{$invoice.tax}</td> | ||
</tr> | ||
{/if} | ||
{if $invoice.taxrate2} | ||
<tr> | ||
<td class="total-row text-right">{$invoice.taxrate2}% {$invoice.taxname2}</td> | ||
<td class="total-row text-center">{$invoice.tax2}</td> | ||
</tr> | ||
{/if} | ||
<tr> | ||
<td class="total-row text-right">{$LANG.invoicescredit}</td> | ||
<td class="total-row text-center">{$invoice.credit}</td> | ||
</tr> | ||
<tr> | ||
<td class="total-row text-right">{$LANG.invoicestotaldue}</td> | ||
<td class="total-row text-center">{$invoice.total}</td> | ||
</tr> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="col-md-7" style="margin-top: 20px;"> | ||
<div style="margin-bottom: 20px"> | ||
<h2 class="text-center">Credit Card Details</h2> | ||
</div> | ||
<div class="form-group cc-details"> | ||
<label for="inputCardNumber" class="col-sm-4 control-label">Card Number</label> | ||
|
||
<div class="col-sm-7"> | ||
<input type="text" name="ccnumber" data-brick="card-number" id="inputCardNumber" size="30" value="" autocomplete="off" | ||
class="form-control newccinfo"> | ||
</div> | ||
</div> | ||
<div class="form-group cc-details"> | ||
<label for="inputCardExpiry" class="col-sm-4 control-label">Expiry Date</label> | ||
|
||
<div class="col-sm-8"> | ||
<select name="ccexpirymonth" data-brick="card-expiration-month" id="inputCardExpiry" class="form-control select-inline"> | ||
{foreach from=$months item=month} | ||
<option value="{$month}">{$month}</option> | ||
{/foreach} | ||
</select> | ||
<select name="ccexpiryyear" data-brick="card-expiration-year" id="inputCardExpiryYear" class="form-control select-inline"> | ||
{foreach from=$years item=year} | ||
<option value="{$year}">{$year}</option> | ||
{/foreach} | ||
</select> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<label for="cctype" class="col-sm-4 control-label">CVV/CVC2 Number</label> | ||
|
||
<div class="col-sm-7"> | ||
<input type="text" data-brick="card-cvv" name="cccvv" id="inputCardCvv" autocomplete="off" | ||
class="form-control input-inline input-inline-100" maxlength="4"> | ||
<button type="button" class="btn btn-link" data-toggle="popover" | ||
data-content="<img src='{$systemurl}assets/img/ccv.gif' width='210' />" | ||
data-original-title="" title=""> | ||
Where do I find this? | ||
</button> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<div class="text-center"> | ||
<input id="hiddenToken" name="brick_token" type="hidden"/> | ||
<input id="hiddenFingerprint" name="brick_fingerprint" type="hidden"/> | ||
<input class="btn btn-primary btn-lg" id="buttonPayNow" type="submit" value="Pay Now"/> | ||
<a href="{$systemurl}viewinvoice.php?id={$invoiceid}" class="btn">Cancel Payment</a> | ||
</div> | ||
</div> | ||
</div> | ||
<input name="fromCCForm" type="hidden" value="true"/> | ||
<input name="data" type="hidden" value="{$data}"/> | ||
<input name="invoiceid" type="hidden" value="{$invoiceid}"/> | ||
</form> | ||
<script src="https://api.paymentwall.com/brick/brick.1.3.js"></script> | ||
<script type="text/javascript"> | ||
$(document).ready(function () { | ||
var publicKey = '{$publicKey}'; | ||
{literal} | ||
var $form = $('#payment-form'); | ||
var brick = new Brick({ | ||
public_key: publicKey, | ||
form: {formatter: true} | ||
}, 'custom'); | ||
$form.submit(function (e) { | ||
e.preventDefault(); | ||
brick.tokenizeCard({ | ||
card_number: $('#inputCardNumber').val(), | ||
card_expiration_month: $('#inputCardExpiry').val(), | ||
card_expiration_year: $('#inputCardExpiryYear').val(), | ||
card_cvv: $('#inputCardCvv').val() | ||
}, function (response) { | ||
if (response.type == 'Error') { | ||
// handle errors | ||
$("#error-list").html(''); | ||
$("#error-list").append(function () { | ||
if (typeof response.error == 'string') { | ||
return '<li>' + response.error + '</li>'; | ||
} | ||
for (var i in response.error) { | ||
return '<li>' + response.error.join("</li><li>") + '</li>'; | ||
} | ||
}); | ||
$("#payment-errors").show(); | ||
} else { | ||
$form.append($('#hiddenToken').val(response.token)); | ||
$form.append($('#hiddenFingerprint').val(Brick.getFingerprint())); | ||
$("#payment-errors").hide(); | ||
$form.get(0).submit(); | ||
} | ||
}); | ||
return false; | ||
}); | ||
{/literal} | ||
}); | ||
</script> | ||
<div style="clear: both"></div> | ||
{/if} | ||
{if $success == true} | ||
<div class="text-center"> | ||
<h1>Success</h1> | ||
<p>Your credit card payment was successful.</p> | ||
<p><a href="{$systemurl}viewinvoice.php?id={$invoiceid}&paymentsuccess=true" title="Invoice #{$invoiceid}">Click | ||
here</a> to view your paid invoice.</p> | ||
</div> | ||
{/if} | ||
<div class="text-center" style="margin:40px 0 0 0;"> | ||
<img src="https://www.paymentwall.com/uploaded/files/brand_pw_logo_black.png"> | ||
</div> | ||
<br/> | ||
<div style="clear: both"></div> | ||
<style> | ||
.invoice-summary { | ||
height: auto | ||
} | ||
</style> |
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,9 @@ | ||
{if $whmcsVer <= 5} | ||
{include file="$template/pageheader.tpl" showbreadcrumb=false} | ||
{else} | ||
{include file="$template/includes/pageheader.tpl" showbreadcrumb=false} | ||
{/if} | ||
|
||
<div class="col-md-12 paymentwall-widget"> | ||
{$iframe} | ||
</div> |
Oops, something went wrong.