For the complete documentation index, see llms.txt. This page is also available as Markdown.

Example Library Code

The following section provides samples of how to integrate with the Gateway using our integration libraries.

Gateway Integration Library

Hosted Sale Transaction

The following example PHP code shows how to send a SALE transaction using the Gateway library:

<?PHP
require('gateway.php');

use \P3\SDK\Gateway;

// Signature key entered on MMS. The demo account is fixed to this value,
Gateway::$merchantSecret = 'Circle4Take40Idea';

// Gateway URL
Gateway::$hostedUrl = 'https://gateway.example.com/hosted/';

if (!isset($_POST['responseCode'])) {
	// Send request to gateway
	$req = array(
		'merchantID' => 100001,
		'action' => 'SALE',
		'type' => 1,
		'currencyCode' => 826,
		'countryCode' => 826,
		'amount' => 1001,
		'orderRef' => 'Test purchase',
		'redirectURL' => ($_SERVER['HTTPS'] == 'on' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
	);

	try {
		echo Gateway::hostedRequest($req);
	} catch (\Exception $e) {
		// You should exit gracefully
		die('Sorry, the request could not be sent: ' . $e);
	}

} else {
	// Received response from gateway
	try {
		Gateway::verifyResponse($_POST);
	} catch(\Exception $e) {
		// You should exit gracefully
		die('Sorry, the request could not be sent: ' . $e);
	}

	// Check the response code
	if ($_POST['responseCode'] === 0) {
		echo "<p>Thank you for your payment.</p>";
	} else {
		echo "<p>Failed to take payment: " . htmlentities($_POST['responseMessage']) . "</p>";
	}
}

?>

Direct Sale Transaction (with 3-D Secure)

The following example PHP code shows how to send a SALE transaction with support for 3-D Secure using the Gateway library:

Hosted Payment Page Library

Hosted Sale Transaction

The following example code shows how to prepare a payment form to open the Hosted Payment Page in a lightbox style overlay on your website using the Hosted Payment Page library:

Hosted Sale Transaction (jQuery)

The following example code shows how to prepare a payment form to open the Hosted Payment Page in a lightbox style overlay on your website using the Hosted Payment Page and jQuery libraries:

Hosted Sale Transaction #2

The following example code shows how to create a payment form to open the Hosted Payment Page in a lightbox style overlay on your website using the Hosted Payment Page library:

Hosted Sale Transaction #2 (jQuery)

The following example code shows how to create a payment form to open the Hosted Payment Page in a lightbox style overlay on your website using the Hosted Payment Page and jQuery libraries:

Hosted Payment Fields Library

The following example code shows how to create and manage Hosted Payment Fields using the Hosted Payment Field library.

The example shows how to style fields using an inline stylesheet and how to listen and react to the field’s events.

The example also shows how to set up the payment form both automatically and manually and integrate with the jQuery validator plugin. You should choose the set-up method best suited for your needs and whatever validation plugin or functions you are familiar with.

The example code demonstrates including the static transaction information, such as the merchantID and amount, in hidden form fields and POSTing the form directly to the Gateway’s Direct Integration using partial message signing. We would however recommend that you capture just the information you require and then POST this data to your own website where you can use it to build a new fully signed request to send to the Gateway’s Direct Integration as a server-to-server request.

Last updated

Was this helpful?