Skip to content

Commit

Permalink
Merge pull request #9 from dzung2t/master
Browse files Browse the repository at this point in the history
Add Brick support
  • Loading branch information
Roman Sevastyanov committed Sep 23, 2015
2 parents 36e2595 + 7c084d9 commit cf27670
Show file tree
Hide file tree
Showing 9 changed files with 380 additions and 5 deletions.
109 changes: 109 additions & 0 deletions src/brickccform.php
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'],
);
}
Binary file added src/images/paymentwall/brick_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/paymentwall/paymentwall_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions src/modules/gateways/brick.php
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;
}
16 changes: 11 additions & 5 deletions src/modules/gateways/paymentwall.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function paymentwall_config()

function init_paymentwall_config($params)
{
require_once(getcwd() . '/includes/api/paymentwall_api/lib/paymentwall.php');
require_once(ROOTDIR . '/includes/api/paymentwall_api/lib/paymentwall.php');
Paymentwall_Config::getInstance()->set(array(
'api_type' => Paymentwall_Config::API_GOODS,
'public_key' => $params['appKey'], // available in your Paymentwall merchant area
Expand Down Expand Up @@ -47,14 +47,20 @@ function paymentwall_link($params)
get_user_profile_data($params)
)
);
$widgetUrl = $widget->getUrl();
$code = '<form method=POST action="' . $widgetUrl . '"><a href="' . $widgetUrl .'"><img src="' . $params['systemurl'] . '/images/paymentwall/paymentwall_button.png" alt="Paymentwall logo" /></a></form>';
$widgetUrl = $params['systemurl'] . '/paymentwallwidget.php';
$code = '<form method=POST action="' . $widgetUrl . '">
<input type="hidden" name="data" value="' . encrypt($widget->getHtmlCode(array(
'width' => '100%',
'height' => '500'
))) . '" />
<button type="submit">Pay via <img src="' . $params['systemurl'] . '/images/paymentwall/paymentwall_logo.png" alt="Pay via Paymentwall" /></button>
</form>';

return $code;
}

function get_user_profile_data($params){

function get_user_profile_data($params)
{
return array(
'customer[city]' => $params['clientdetails']['city'],
'customer[state]' => $params['clientdetails']['fullstate'],
Expand Down
Empty file.
176 changes: 176 additions & 0 deletions src/modules/gateways/paymentwall/templates/ccform.tpl
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>
9 changes: 9 additions & 0 deletions src/modules/gateways/paymentwall/templates/widget.tpl
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>
Loading

0 comments on commit cf27670

Please sign in to comment.