Friday, August 22, 2014

Stripe Now Part of BlueBox Payment Gateways

BlueBox has recently added the Stripe Payment System to it's list of available payment methods/gateways.

A typical Pay Function would work like this:

function pay(){
global $global;
if($_GET[test]){
$pkey="pk_test_***********************";
$key="sk_test_***********************";
}else{
$pkey="pk_live_***********************";
$key="sk_live_***********************";
}
$out.="
<div class='bb_main_content_title'>Make a Payment:</div>
<div class='bb_main_content_paragraph'>
Please use this page to make payments with your credit or debit card.<br>
This is a secure payment service provided by our payment provider <a href=http://www.stripe.com target=_blank>Stripe</a>. We do not store any of your card information on our servers/system - all data is stored and processed securely by <a href=http://www.stripe.com target=_blank>Stripe</a>.
</div>
";
if($global[fields][name] && $_POST['stripeToken'] && is_numeric($global[fields][payNUM]) && $global[fields][payNUM]*1>1 && $global[fields][payNUM]*1<3000 && $_POST['stripeEmail']){
require_once($_SERVER[DOCUMENT_ROOT].'/engine/3rdparty/stripe/Stripe.php');
Stripe::setApiKey($key);
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
$amt=$global[fields][payNUM]*1;
try {
//
$customer = Stripe_Customer::create(array(
'email' => $_POST['stripeEmail'],
'card' => $token
));
$charge = Stripe_Charge::create(array(
'customer' => $customer->id,
'amount' => $amt*100,
'currency' => 'GBP',
'description' => $global[fields][name]
));
$out.=("
<div class='bb_main_content_affirm'>Thanks, payment of &pound;".display_currency($global[fields][payNUM])." has been made.</div></div>
");
} catch(Stripe_CardError $e) {
$body = $e->getJsonBody();
$err = $body['error'];
$out.=("
<div class='bb_main_content_alert'>Payment failed: ".$err['message']." (".$err['code'].") </div>
");
}
}elseif($global[fields][name] && is_numeric($global[fields][payNUM]) && $global[fields][payNUM]*1>1 && $global[fields][payNUM]*1<3000){
$out.="
<form action=\"/?Pay".($_GET[test]?"&test=1":"")."\" method=\"POST\">
<b>Please click the button below to load the secure payment form:</b>
<div style=clear:both;height:15px;></div>
<input type=hidden name=global[fields][payNUM] value=\"".$global[fields][payNUM]."\">
<input type=hidden name=global[fields][name] value=\"".$global[fields][name]."\">
<div style=width:300px;float:left;>
<script
src=\"https://checkout.stripe.com/checkout.js\" class=\"stripe-button\"
data-key=\"$pkey\"
data-currency=\"GBP\"
data-amount=\"".($global[fields][payNUM]*100)."\"
data-name=\"Make a Payment\"
data-allowRememberMe=false
data-description=\"From ".$global[fields][name]." (&pound;".display_currency($global[fields][payNUM]).")\"
data-label=\"Load the secure payment form\"
data-image=\"/portal/".DATABASE_NAME."/UserFiles/Image/logo.png\">
</script>
</div>
".($_GET[test]?"<div style=float:left;margin-left:15px;background:yellow;color:black;padding:6px;>Test Mode</div>":"")."
<div style=clear:both;height:15px;></div>
<b>Important:</b> Please wait for the page to fully re-load once you have entered your card details. You will see a confirmation message once the transaction is complete.
</form>
";
}else{
$out.="
<script>
function frm_validate(){
if(!\$('global[fields][name]').value){
alert('Please enter your name.');
return;
}
if(isNaN(\$('global[fields][payNUM]').value) || !\$('global[fields][payNUM]').value || \$('global[fields][payNUM]').value*1<=1 || \$('global[fields][payNUM]').value*1>=3000){
alert('Please enter an amount greater than 1 and less than 3000.');
return;
}else{
\$('psf').submit();
}
}
</script>
<form id=psf action=/?Pay".($_GET[test]?"&test=1":"")." method=post>
<div style=margin-bottom:15px;><b>Please enter your name and the amount you want to pay:</b></div>
<div style=\"margin-bottom:10px;\">
<div style=float:left;margin-right:10px;margin-top:6px;>
Your name:
</div>
<div style=float:left;width:300px;>
<!--:formfield:name:-->
</div>
<div style=clear:both;></div>
</div>
<div style=float:left;font-size:24pt;margin-right:10px;margin-top:6px;>&pound;</div>
<!--:formfield:payNUM||0.00| onclick=this.value=''; style=text-align:right;width:100px;float:left;margin-right:20px; :-->
<a href=# onclick=\"frm_validate();return false;\" style=float:left;margin-top:4px; class='bb_main_content_styled_button_blue' >Next ></a>
".($_GET[test]?"<div style=float:left;margin-left:15px;background:yellow;color:black;padding:6px;>Test Mode</div>":"")."
<div style=clear:both;></div>
</form>
";
}
return($out);
}
view raw stripe example hosted with ❤ by GitHub

Friday, August 15, 2014

jQuery Fixed Table Headers in BlueBox

A recent plugin added to BlueBox is Misha Koryak's FloatThread. This allows you to fix the table header within a fixed-width div as follows:


<div style=width:1000px;height:300px;overflow:auto; id=reportwrapper>

<table width=100% cellpadding=5 cellspacing=1 bgcolor=silver id=report_table_pointer>
<thead>
   <tr>
     <th> .. some content here .. </th>
     <th> .. some content here .. </th>
   </tr>
</thead>
<tbody>
   <tr>
     <td> .. some content here .. </td>
     <td> .. some content here .. </td>
   </tr>
</tbody>
</table>

</div>

<script src=\"engine/3rdparty/jquery/table_headers/jquery.floatThead.min.js\"></script>
<script>
var float_headers = jQuery('#report_table_pointer');
float_headers.floatThead({
scrollContainer: function(table){
return table.closest('#reportwrapper');
        }
});
</script>

Thursday, August 14, 2014

Redirect to Despatch Note after Auto-Generating Invoice

A new BlueBox setting has been installed which redirects the 'view' back to a despatch note after a debtors invoice has been auto-generated from it. The usual behaviour is for the end document to display the debtors invoice. bb_sales_debtors_invoices->bbsetting_inv_show_dsp_after_add - if set to 1 (on) will trigger a redirect back to the despatch note automatically.