Giter Site home page Giter Site logo

nets-easy-php's Introduction

Nets Easy PHP bindings

CircleCI License

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.

Requirements

PHP 7.3.0 and later.

Composer

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');

Getting Started

Simple usage looks like:

Backend integration

<?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
      ]
    ]
  ]
]);

Frontend integration

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>

Documentation

See the Official API docs.

nets-easy-php's People

Contributors

thomas-alrek avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.