armezit/omnipay-nextpay

为 Omnipay PHP 支付处理库提供的 NextPay 驱动程序

v1.2.0 2022-10-21 16:15 UTC

This package is auto-updated.

Last update: 2024-09-21 22:00:03 UTC


README

NextPay 为 Omnipay PHP 支付处理库提供的驱动程序

Packagist Version PHP from Packagist Packagist

Omnipay 是一个与框架无关的、多网关的 PHP 支付处理库。本包实现了 Omnipay 对 Nextpay 的支持。

安装

Omnipay 通过 Composer 安装。要安装,只需使用 Composer 需要 league/omnipayarmezit/omnipay-nextpay

composer require league/omnipay armezit/omnipay-nextpay

基本用法

本包提供以下网关

  • NextPay

有关一般使用说明,请参阅主要的 Omnipay 仓库。

示例

购买

结果将重定向到网关或银行。

use Omnipay\Omnipay;

$gateway = Omnipay::create('Nextpay');
$gateway->setApiKey('API_KEY');
$gateway->setReturnUrl('https://www.example.com/return');

// Send purchase request
$response = $gateway->purchase([
    'amount' => $amount,
    'currency' => $currency,
    'transactionId' => $orderId, // order_id on merchant side
])->send();

// Process response
if ($response->isSuccessful() && $response->isRedirect()) {
    // store the transaction reference to use in completePurchase()
    $transactionReference = $response->getTransactionReference();
    // Redirect to offsite payment gateway
    $response->redirect();
} else {
    // Payment failed: display message to customer
    echo $response->getMessage();
}

完成购买(验证)

返回时,通常的 completePurchase 将提供交易尝试的结果。

最终结果包括以下方法以检查其他详细信息

// Send purchase complete request
$response = $gateway->completePurchase([
    'amount' => $amount,
    'transactionReference' => $transactionReference, 
])->send();

if (!$response->isSuccessful() || $response->isCancelled()) {
    // Payment failed: display message to customer
    echo $response->getMessage();
} else {
    // Payment was successful
    print_r($response);
}

退款订单

通过 $transactionReference 退款订单

$response = $gateway->refund([
    'amount' => $amount,
    'transactionReference' => $transactionReference,
])->send();

if ($response->isSuccessful()) {
    // Refund was successful
    print_r($response);
} else {
    // Refund failed
    echo $response->getMessage();
}

测试

composer test

支持

如果您遇到 Omnipay 的一般问题,我们建议在 Stack Overflow 上发布。确保添加 omnipay 标签,以便易于找到。

如果您想了解发布公告,讨论项目的想法或提出更详细的问题,还有一个您可以订阅的 邮件列表

如果您认为您已找到错误,请使用 GitHub 问题跟踪器 报告错误,或者更好的是,分支库并提交拉取请求。