定制 apility/nets-easy-omnipay 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

apility/nets-easy-omnipay

最新稳定版本:v1.1.1

Composer 安装命令:

composer require apility/nets-easy-omnipay

包简介

Nets Easy driver for the Omnipay PHP payment processing library

README 文档

README

Nets Easy driver for the Omnipay PHP payment processing library

Omnipay is a framework agnostic, multi-gateway payment processing library for PHP. This package implements Stripe support for Omnipay.

Table Of Contents

Installation

Omnipay is installed via Composer. To install, simply require league/omnipay and apility/nets-easy-omnipay with Composer:

composer require league/omnipay apility/nets-easy-omnipay

Basic Usage

The following gateway os provided by this package:

For general usage instructions, please see the main Omnipay repository.

Initial setup

<?php

use Omnipay\Common\GatewayFactory;
use Apility\Omnipay\NetsEasy\Gateway as NetsEasyGateway;

$factory = new GatewayFactory();
$gateway = $factory->create(NetsEasyGateway::class);

$gateway->setMerchantNumber(/* ... */);
$gateway->setSecretKey(/* ... */);
$gateway->setCheckoutKey(/* ... */);

// Some API keys contains the "test-" prefix. If this is present, we automatically enable test mode.
// However, if your API key does not contain this prefix, you can manually toggle test mode using this method:
$gateway->setTestMode(true);

Hosted Payment Page

If you don't want to host the checkout page yourself (EmbeddedCheckout), you may the the HostedPaymentPage integration type. This will use a checkout page hosted by Nexi Group.

authorize.php

```php
<?php

use Apility\Omnipay\NetsEasy\Types\Checkout\IntegrationType;

$authorization = $gateway->authorize([
    // ...
    'checkout' => [
        // ...
        'returnUrl' => 'http://example.com/callback.php',
        'integrationType' => IntegrationType::HostedPaymentPage
        // ...
    ]
])->send();

if (!$authorization->isSuccessful()) {
    if ($authorization->isRedirect()) {
        return $authorization->redirect();
    }

    die('Authorize failed: ' . $authorization->getMessage());
}

header('Location: /callback.php?paymentid=' . $authorization->getPaymentId());

callback.php

<?php

$transaction = $gateway->fetchTransaction(['paymentId' => $_GET['paymentid']])->send();

if (!$transaction->isSuccessful()) {
    die('Failed to fetch transaction: ' . $transaction->getMessage());
}

if ($transaction->getChargedAmount()) {
    header('Location: /receipt.php?paymentid=' . $transaction->getPaymentId());
    return;
}

if ($transaction->getCancelledAmount() > 0) {
    die('Payment was cancelled: ' . $transaction->getPaymentId());
    return;
}

if ($transaction->getRefundedAmount() > 0) {
    die('Payment refunded: ' . $transaction->getPaymentId());
}

if ($transaction->getUnscheduledSubscriptionId()) {
    header('Location: /unscheduledSubscriptionCallback.php?paymentid=' . $transaction->getPaymentId());
    return;
}

header('Location: /capture.php?paymentid=' . $transaction->getPaymentId());

capture.php

<?php

$transaction = $gateway->fetchTransaction(['paymentId' => $_GET['paymentid']])->send();

if (!$transaction->isSuccessful()) {
    die('Failed to fetch transaction: ' . $transaction->getMessage());
}

if ($transaction->getCancelledAmount() > 0) {
    die('Cannot capture payment, already cancelled: ' . $transaction->getPaymentId());
}

if ($transaction->getRefundedAmount() > 0) {
    die('Cannot capture payment, already refunded: ' . $transaction->getPaymentId());
}

if (!$transaction->getReservedAmount()) {
    header('Location: ' . $transaction->getCheckoutUrl());
    return;
}

if ($transaction->getChargedAmount() == $transaction->getReservedAmount()) {
    header('Location: /receipt.php?paymentid=' . $transaction->getPaymentId());
    return;
}

$capture = $gateway->capture([
    'paymentId' => $transaction->getPaymentId(),
    'amount' => $transaction->getReservedAmount(),
])->send();

if (!$capture->isSuccessful()) {
    die('Capture failed: ' . $capture->getMessage());
}

header('Location: /receipt.php&paymentid=' . $transaction->getPaymentId());

Checkout JS SDK

The Nets Easy integration is fairly straight forward. Essentially you just pass the checkoutKey and paymentId fields through to Nets Easy instead of the regular authorization flow.

Start by following the standard Stripe JS guide here: https://developer.nexigroup.com/nexi-checkout/en-EU/api/checkout-js-sdk/

Example:

Backend

<?php

use Apility\Omnipay\NetsEasy\Types\Checkout\IntegrationType;

$authorization = $gateway->authorize([
    // ...
    'checkout' => [
        // ...
        'integrationType' => IntegrationType::EmbeddedCheckout
        // ...
    ]
])->send();

if (!$authorization->isSuccessful()) {
    die('Authorization failed: ' . $authorization->getMessage());
}

$paymentId = $authorization->getPaymentId();
$checkoutKey = $gateway->getCheckoutKey();

Frontend

<!-- Production -->
<script src="https://checkout.dibspayment.eu/v1/checkout.js?v=1"></script>
<!-- Test -->
<script src="https://test.checkout.dibspayment.eu/v1/checkout.js?v=1"></script>
<script>
    const checkoutOptions = {
        checkoutKey: "<?php echo $checkoutKey; ?>",
        paymentId : "<?php echo $paymentId; ?>",
        containerId : "checkout-container-div",
        language: "en-GB"
    };
    
    const checkout = new Dibs.Checkout(checkoutOptions);

    checkout.on('payment-completed', function(response) {
        window.location.href = '/callback.php?paymentid=' + response.paymentId;
    });
</script>

<div id="checkout-container-div"></div>
</html>

Example Implementation

A fully implemented example can be found in the example directory.

To serve this example navigate to the example directory and start up a php server on port 8000:

cd examples
php -S localhost:8000

You need valid credentials for Nets Easy to run the examples.

Copy the .env.example file to a new file named .env in the same directory. Add your credentials to the .env file.

You can now open http://localhost:8000 in your browser.

Copyright © 2025 Apility AS

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-30