1. Home
  2. Libraries for webmasters
  3. Plate payments
  4. How to hook plate payments (PHP)?

How to hook plate payments (PHP)?

If you need a payment module in PHP to hook the plate payments, contact with us.

Server-side plate payment processing

The module requires extension JSON to support standard payments. You will need separate files or controller actions to download the tariff, initiate a start of payment series, initiate payment and one file or action to listen for the start of the series and for payment to handle the payments. All file and actions have to include file or function that should import the Billon library, create the payment object and called call the configuration methods:

require_once "billon/index.php"; // location of a script 'index.php' of the Billon payment module
$myShop = new \billon\Shop();
$alpha = 10; // the cheapest article, number of thousandths of a basic monetary unit, eg. 1 pence
$beta = 20; // a price of the second article, eg. 2 pence
$gamma = 100; // a price of the third article, eg. 10 pence
$delta = 200; // a price of the fourth article, eg. 20 pence
$epsilon = 1000; // a price of the most expensive article, eg. 1 pound
$myShop->user(function ($requestData, $cb)
{
	$cb($requestData->user);
}
)->products(function ($requestData, $cb)
{
	$cb($requestData->itemsId);
}
)->product(function ($requestData, $itemId, $cb) use ($alpha, $beta, $gamma, $delta, $epsilon)
{ // a list of articles - products, article setting according to the type of the plate is not recommended in case of tariffs consisting of a smaller number of plates
	if ($itemId == 1)
	{
		$cb($alpha);
	}
	else if ($itemId == 2)
	{
		$cb($beta);
	}
	else if ($itemId == 3)
	{
		$cb($gamma);
	}
	else if ($itemId == 4)
	{
		$cb($delta);
	}
	else if ($itemId == 5)
	{
		$cb($epsilon);
	}
})->plates(function($requestData, $cb) use ($alpha, $beta, $gamma, $delta, $epsilon)
{ // setting the prices of the plates, the lack of the argument and 0 removes the plate from the tariff
   $cb($alpha, $beta, $gamma, $delta, $epsilon);
})->platePayment(function($requestData, $cb)
{ // setting of series identifier and kind of plate 
   $cb($requestData->seriesId, $requestData->type);
}
)->currency(function ($requestData, $cb)
{ // ISO 4217 currency code, not required method, 'PLN' by default
	$cb('GBP');
}
)->paymentTitle(function ($requestData, $items, $delivery, $cb) {
	$cb('Payment title');
}
)->app24(function ($requestData, $items, $delivery, $cb) {
$cb('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1e2VyIjr7InlkIjo0MDksInNhbHQiOiJlMmZmOTUzMC1kNjgzLTExZTctYTk4ZS1iMWQ3OUIyNmHjN2EifSwiaWF0IjoxNTEyMTI0NzU5fQ.WaUHpsfkahoqiNIuoBd0OiouS1NF4-L0r8YUZcTr2yA'); // API key of the user of a service "billon.me"
	//$cb(array("Name" => "demo-payments", "Address" => "http://138.123.200.92:24391")); // the name of the logged in user, the address and the port - direct communication with the application 24/7
})->maxTotalAmount(function($requestData, $cb)
{ // the maximum sum payment in the series expressed in thousandths of a basic monetary unit, not required method
   $cb(10000);
})->duration(function($requestData, $cb)
{ // the duration of a series of payments in seconds, the required method in order that the series has a non-zero length of duration
   $cb(3600);
})->maxPaymentsInSeries(function($requestData, $cb)
{ // the maximum number of payments in the series, not required method
   $cb(10);
}
)->merchantBrandName(function ($requestData, $cb)
{ // setting of brand, not required method, domain of the page on which payment is executed by default
  $cb('Name of brand'); 
})->onReceivedPlatePaymentSeriesStatus(function ($response)
{
 // event of 24/7 app response during the proces of the acceptance of the series, not reqiured method
})->onAcceptedPlatePaymentSeries(function ($paymentData)
{
 // event of acceptance of the series, not required method
})->onFinishedPayment(function ($items, $delivery_option, $document, $requestData) 
{ // event of finished payment, not required metho
	file_put_contents('log.txt', serialize([$items, $delivery_option, $document, $requestData]));
}
)->onRequestSend(function ($requestName, $parameters, $requestResponse, $error)
{ // the event of sending SOAP request, not required method
});

Example file that outputs the tariff:

<?php 
require "myShop.inc.php"; // the file with the initiation of the payment object and the calls of the configuration methods
$myShop->tariff();

Example file that initiate the start of a series of plate payments:

<?php 
require "myShop.inc.php"; // the file with the initiation of the payment object and the calls of the configuration methods
$myShop->platePaymentSeriesStart();

Example file that initiate the payment:

<?php 
require "myShop.inc.php"; // the file with the initiation of the payment object and the calls of the configuration methods
$myShop->paymentInitiation();

Example file for listening to the start of a series of plate payments and payment monitoring:

<?php 
require "myShop.inc.php"; // the file with the initiation of the payment object and the calls of the configuration methods
$taskId = @json_decode(file_get_contents("php://input"))->taskId;
$myShop->paymentStatus($taskId ? $taskId : $_GET['taskId'], function($response)
{
    echo json_encode($response);
});

Taking plate payments on webpages

Use JavaScript Billon scripts for taking the plate payments on a webpage:

<div id="button-container-1"></div>
<script src="//cdn.billon.pro/js/billon.js"></script>
<script src="//cdn.billon.pro/js/billon-agent.js"></script>
<script src="//cdn.billon.pro/js/billon-object.js"></script>
<script src="//cdn.billon.pro/js/billon-user.js"></script>
<script src="//cdn.billon.pro/js/billon-plates.js"></script>
<script>
   billon.plates({
      connection: new billon.agent(loc.substring(0, loc.lastIndexOf('/'))), // an URL address pointing to the location of the scripts that support payment or an address of the controller with the actions that support psyment (to directory the same as the page in this case)
      lang: 'en', // language 'en' or 'pl', 'en' by default
      plateButtonAddress: "https://cdn.billon.pro/screen/plate-button/index.html", // in the case of not showing buttons, skip in the case of the lack of problems
      plateDialogAddress: "https://cdn.billon.pro/screen/plate-dialog/index.html", // in the case of not showing dialog, skip in the case of the lack of problems
      SkipAnotherUser: false, // optional - omission of the step of of choosing another user than detected, the step is not skipped by default
      DisableButtonsTitle: false, // optional - default not adding title (tooltip) with the price to the buttons, the titles are being set by default
      tariff: {
         Address: 'list.php', // name of the file of the action where method 'tariff' is being called
         DisplayedCurrency: ' £', // displayed currency, ISO 4217 currency code set in module 'billon' by default
         CentSign: 'p' // sign of currency for the hundredth part of the basic monetary unit displayed for the price lower than this unit, 
                       // sign set in parameter 'DisplayedCurrency'
                       // or ISO 4217 currency code set in module 'billon'
                       // in case of lack of this parameter is used by default
      },
      series: {
         request: {
            Address: 'initiation.php', // name of the file of the action where method 'platePaymentSeriesStart' is being called
            Data: function (user) 
            {
              return {
                user: user
              };
            }
         },
         ListenResponse: function (response, user)
         {
            if (response.status == "SERIES_ACCEPTED" || response.status == "TRANSFERRING" || response.status == "TRANSFERING")
            { // save of identifier of series and Billon username, in this case in Local Storage
               localStorage.setItem("seriesId", response.taskId);
	       localStorage.setItem("user", JSON.stringify(user));
            }
         }
      },
      paymentRequest: {
         Address: 'payment.php', // name of the file of the action where method 'paymentInitiation' is being called
         Data: function()
         { // reading previously saved identifier of series and Billon username, in this case from Local Storage
            try
            {
               return {
                  seriesId: localStorage.getItem("seriesId"),
                  user: JSON.parse(localStorage.getItem("user"))
               };
            }
            catch (e)
            {
               return {};
            }
         }
      },
      listen: {
         Address: "status.php", // name of the file of the action where method 'paymentStatus' is being called
         Data: function (requestResponse) 
         {
           return {
             taskId: requestResponse.taskId
           };
         }
      },
      buttons: [ // array of buttons
      {
         place: document.getElementById('button-container-1'), // HTML element in which the button is to be placed
         type: 'alpha', // type of the button
         DisableTitle: false, // optional - not setting the title of the button with the price,
                              // the global option 'DisableButtonsTitle' is acted on by default
         RequestData: function(type)
         {
            return {
               type: type,
               itemsId: [1] // array of identifiers of products
            }
         },
         ListenResponse: function(response)
         { // optional method
            switch (response.status)
            {
               case "FINISHED_OK":
                  // event of successfully purchase with the button
                  break;
               case "FINISHED_ERR_USER_REJECTED": // a lack of possibility to pay within the stored series
                  localStorage.setItem("seriesId", null);
		  localStorage.setItem("user", JSON.stringify(null));
            }
         }
      },
      {
         place: document.getElementById('button-container-2'),
         type: 'beta',
         RequestData: function(type)
         {
            return {
               type: type,
               itemsId: [2]
            }
         },
         ListenResponse: function(response)
         {
            switch (response.status)
            {
               case "FINISHED_OK":
                  // event of successfully purchase with the button
                  break;
               case "FINISHED_ERR_USER_REJECTED": // a lack of possibility to pay within the stored series
                  localStorage.setItem("seriesId", null);
		  localStorage.setItem("user", JSON.stringify(null));
            }
         }
      },
      {
         place: document.getElementById('button-container-3'),
         type: 'gamma',
         RequestData: function(type)
         {
            return {
               type: type,
               itemsId: [3]
            }
         },
         ListenResponse: function(response)
         {
            switch (response.status)
            {
               case "FINISHED_OK":
                  // event of successfully purchase with the button
                  break;
               case "FINISHED_ERR_USER_REJECTED": // a lack of possibility to pay within the stored series
                  localStorage.setItem("seriesId", null);
		  localStorage.setItem("user", JSON.stringify(null));
            }
         }
      },
      {
         place: document.getElementById('button-container-4'),
         type: 'delta',
         RequestData: function(type)
         {
            return {
               type: type,
               itemsId: [4]
            }
         },
         ListenResponse: function(response)
         {
            switch (response.status)
            {
               case "FINISHED_OK":
                  // event of successfully purchase with the button
                  break;
               case "FINISHED_ERR_USER_REJECTED": // a lack of possibility to pay within the stored series
                  localStorage.setItem("seriesId", null);
		  localStorage.setItem("user", JSON.stringify(null));
            }
         }
      },
      {
         place: document.getElementById('button-container-5'),
         type: 'epsilon',
         RequestData: function(type)
         {
            return {
               type: type,
               itemsId: [5]
            }
         },
         ListenResponse: function(response)
         {
            switch (response.status)
            {
               case "FINISHED_OK":
                  // event of successfully purchase with the button
                  break;
               case "FINISHED_ERR_USER_REJECTED": // a lack of possibility to pay within the stored series
                  localStorage.setItem("seriesId", null);
		  localStorage.setItem("user", JSON.stringify(null));
            }
         }
      }]
   });
</script>

 

Was this article helpful to you? Yes No

How can we help?