guanhui07/newebpay

NewebPay(藍新金流)的支付解决方案,使用纯PHP实现

v1.1.2 2021-07-19 14:35 UTC

This package is auto-updated.

Last update: 2024-09-27 10:09:59 UTC


README

程序版本 1.5
文件版本 1.0.4
官方文档

特性

  • 多功能收款 MPG
  • 单笔交易状态查询
  • 信用卡取消授权
  • 信用卡退款
  • 信用卡定期定额

如何使用

信用卡定期定额

建立交易信息 (BasicInfo)

  • $order: 你的订单对象,务必实现package中的OrderInterface
  • $contact: 你的付款人对象,务必实现package中的ContactInterface
  • $periodStartType: 检查卡号模式,参阅文件p.13
  • $version: 接口程序版本
    • 带入 1.0 版本,则[背面末三码]将为必填字段
    • 带入 1.1 版本,则[背面末三码]将为非必填
$info = new \fall1600\Package\Newebpay\Info\Period\BasicInfo($order, $payer, $periodStartType, $version);

可选参数

$info = new ReturnUrl($info, 'https://your.return.url');
$info = new NotifyUrl($info, 'https://your.notify.url');
$info = new BackUrl($info, 'https://your.back.url');
$info = new Memo($info, 'your memo here');

建立NewebPay对象,注入商店信息,带着交易信息前往藍新申请定期定额

  • $merchantId: 你在藍新商店代号
  • $hashKey: 你在藍新商店专用的HashKey
  • $hashIv: 你在藍新商店专用的HashIV
$newebpay = new NewebPay();
$newebpay
    ->setIsProduction(false) // 設定環境, 預設就是走正式機
    ->setMerchant(new Merchant($merchantId, $hashKey, $hashIv))
    ->issue($info);

请在你的订单对象实现OrderInterface

<?php

namespace Your\Namespace;

use fall1600\Package\Newebpay\Contracts\Period\OrderInterface;

class Order implements OrderInterface
{
    // your order detail...
}

请在你的付款人(假设是Member),实现ContactInterface

<?php

namespace Your\Namespace;

use fall1600\Package\Newebpay\Contracts\Period\ContactInterface;

class Member implements ContactInterface
{
    // your member detail...
}

各种url你分的清楚吗?

多功能收款

建立交易信息 (BasicInfo)

  • $merchantId: 你在藍新申请的商店代号
  • $notifyUrl: 用于接收藍新付款通知的callback url
  • $order: 你的订单对象,务必实现package中的OrderInterface
  • $payer: 你的付款人对象,务必实现package中的PayerInterface
$info = new BasicInfo($merchantId, $notifyUrl, $order, $payer);

根据场景开启各种付款方式,有需要再启用即可

// 啟用信用卡
$info = new EnableCredit($info);
// 啟用3, 6, 12 期分期付款
$info = new PayInInstallments($info, '3,6,12');
// 啟用超商條碼
$info = new EnableBarcode($info);
// 啟用Google Pay
$info = new EnableGooglePay($info);
// 啟用Web ATM
$info = new EnableWebAtm($info);
// 搭配非即時交易, 設定藍新通知付款資訊的callback url, 以及繳費期限
$info = new OfflinePay($info, $customerUrl, $ttl);
// 在藍新交易完成後導回的網址
$info = new PayComplete($info, $returnUrl);
// 設定讓消費者在付款頁按下返回時可以回導的頁面
$info = new PayCancel($info, $clientBackUrl);

// 文件末有付款方式對應表

建立NewebPay对象,注入商店信息,带着交易信息前往藍新付款

  • $merchantId: 你在藍新商店代号
  • $hashKey: 你在藍新商店专用的HashKey
  • $hashIv: 你在藍新商店专用的HashIV
$newebpay = new NewebPay();
$newebpay
    ->setIsProduction(false) // 設定環境, 預設就是走正式機
    ->setMerchant(new Merchant($merchantId, $hashKey, $hashIv))
    ->checkout($info);

请在你的订单对象实现OrderInterface

<?php

namespace Your\Namespace;

use fall1600\Package\Newebpay\Contracts\OrderInterface;

class Order implements OrderInterface
{
    // your order detail...
}

请在你的付款人(假设是Member),实现PayerInterface

<?php

namespace Your\Namespace;

use fall1600\Package\Newebpay\Contracts\PayerInterface;

class Member implements PayerInterface
{
    // your member detail...
}

解析来自藍新的交易通知

$isValid = $merchant->setRawData($request->all())->validateResponse(); //確認為true 後再往下走

// response 封裝了通知交易的結果, 以下僅列常用methods
$response = $merchant->getResponse();
// 付款成敗
$response->getStatus();
// 取得交易序號
$response->getTradeNo();
// 取得訂單編號, 就是OrderInterface 實作的getMerchantOrderNo
$response->getMerchantOrderNo();
// 付款時間
$response->getPayTime();

支付宝 (AliPay)

支付宝付款需要提供的参数更多

  • $payer: 你的付款人对象,务必实现package中的AliPayPayerInterface
  • $numberOfProducts: 此订单的物品数量(integer)
  • $product1: 第一个物品(实现AliPayProductInterface)
  • $product2: 第二个物品(实现AliPayProductInterface)
$info = new AliPayBasicInfo($merchantId, $notifyUrl, $order, $payer, $numberOfProducts);
$info = new EnableAliPay($info);

$info = new AliPayProduct($info, 1, $product1);
$info = new AliPayProduct($info, 2, $product2);

单笔交易查询

$resp = $newebpay
    ->setMerchant($merchant)
    ->query($order);

各种url你分的清楚吗?

付款方式对应的对象