The NETS Easy PHP library provides convenient access to the NETS Easy API from applications written in the PHP language. It includes a pre-defined set of classes for API resources that initialize themselves dynamically from API responses.
PHP 7.3.0 and later.
You can install the bindings via Composer. Run the following command:
composer require apility/nets-easy
To use the bindings, use Composer's autoload:
require_once('vendor/autoload.php');
Simple usage looks like:
<?php
use Nets\Easy;
use Nets\Easy\Payment;
Easy::setup([
'secret_key' => '00000000000000000000000000000000',
'checkout_key' => '00000000000000000000000000000000',
'merchant_id' => '000000000'
]);
$payment = Payment::create([
'checkout' => [
'url' => 'https://domain.tld/checkout', // The exact URL where your checkout is hosted (except query parameters and fragments)
'termsUrl' => 'https://domain.tld/terms', // Your terms
],
'order' => [
'currency' => 'NOK',
'reference' => '1', // A unique reference for this specific order
'amount' => 10000, // Total order amount in cents
'items' => [
[
'reference' => '1', // A unique reference for this specific item
'name' => 'Test',
'quantity' => 1,
'unit' => 'pcs',
'unitPrice' => 8000, // Price per unit except tax in cents
'taxRate' => 25000 // Taxrate (e.g 25.0 in this case),
'taxAmount' => 2000 // The total tax amount for this item in cents,
'grossTotalAmount' => 10000 // Total for this item with tax in cents,
'netTotalAmount' => 8000 // Total for this item without tax in cents
]
]
]
]);
The simplest way to integrate the checkout form in the frontend, is to use the form
helper method on the Payment object.
<?php
use Nets\Easy;
use Nets\Easy\Payment;
Easy::setCredentials(...);
$payment = isset($_GET['paymentId']
? Payment::retrieve($_GET['paymentId'])
: Payment::create(...);
$form = $payment->form([
'redirect' => 'https://domain.tld/checkout/complete', // URL to redirect to on payment completion (paymentId query parameter is appended)
'theme' => [ // Optional
'textColor' => 'blue',
'linkColor' => '#bada55',
'buttonRadius' => '50px'
]
]);
?>
<div id="easy-complete-checkout"></div>
<?php echo $form; ?>
Alternatively, if you require full control of checkout flow, implement it manually:
<html>
<head>
<title>Example checkout</title>
</head>
<body>
<div id="easy-complete-checkout"></div>
<script>
document.addEventListener('DOMContentLoaded', () => {
const checkout = new Dibs.Checkout({
checkoutKey: "00000000000000000000000000000000", // Checkout Key
paymentId: "00000000000000000000000000000000", // Payment ID created in the backend integration
partnerMerchantNumber: "000000000", // Merchant ID
containerId: "easy-complete-checkout", // Container element where the checkout form should be created
})
checkout.on('payment-completed', ({ paymentId }) => {
// Payment is completed, do what you need to do here
})
})
</script>
<script src="https://test.checkout.dibspayment.eu/v1/checkout.js?v=1"></script>
<!-- or if in production: -->
<script src="https://checkout.dibspayment.eu/v1/checkout.js?v=1"></script> </body>
</html>
See the Official API docs.