apility/nets-easy 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

apility/nets-easy

最新稳定版本:v2.3.1

Composer 安装命令:

composer require apility/nets-easy

包简介

Nets Easy library

README 文档

README

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.

统计信息

  • 总下载量: 9.01k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 1
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-06