PHPackages                             ycs77/laravel-newebpay - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. ycs77/laravel-newebpay

ActiveLibrary[API Development](/categories/api)

ycs77/laravel-newebpay
======================

A library of connecting newebpay's API service.

v1.0.0(1y ago)319.1k↓18.8%17MITPHPPHP &gt;=8.1CI passing

Since May 11Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/ycs77/laravel-newebpay)[ Packagist](https://packagist.org/packages/ycs77/laravel-newebpay)[ Docs](https://github.com/ycs77/laravel-newebpay)[ Patreon](https://www.patreon.com/ycs77)[ RSS](/packages/ycs77-laravel-newebpay/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (10)Dependencies (9)Versions (11)Used By (0)

Laravel NewebPay - 藍新金流
=======================

[](#laravel-newebpay---藍新金流)

> Fork from [treerful/laravel-newebpay](https://bitbucket.org/pickone/laravel-newebpay)

[![Latest Version on Packagist](https://camo.githubusercontent.com/acad726caecfc473f9722b12d6cc9373fed67e175d08eedd22d487e4a3d57b8f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f79637337372f6c61726176656c2d6e657765627061793f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ycs77/laravel-newebpay)[![Software License](https://camo.githubusercontent.com/c090e080484e2a2bc766446291d04437db823929042bf614b26a1643660ddf6f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e3f7374796c653d666c61742d737175617265)](LICENSE)[![GitHub Tests Action Status](https://camo.githubusercontent.com/58401ef1b390e4eadc4f8611f92876f98240db10e008df275068269eb6b9d6e1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f79637337372f6c61726176656c2d6e657765627061792f74657374732e796d6c3f6272616e63683d322e78266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/ycs77/laravel-newebpay/actions/workflows/tests.yml?query=branch%3A2.x)[![Total Downloads](https://camo.githubusercontent.com/34f9ee5fe6f25041e0e457476250e5f765fe7913385c9c0fa8eeb2a72aa6cddb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f79637337372f6c61726176656c2d6e657765627061793f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ycs77/laravel-newebpay)

**Laravel NewebPay** 為針對 Laravel 所寫的藍新金流（智付通）金流串接套件。

### 套件功能

[](#套件功能)

- 💳 MPG 多功能收款 API
- 🔍 交易查詢 API
- 🚫 信用卡取消授權 API
- 💸 信用卡請退款 API
- 🔁 信用卡定期定額委託 API

目錄
--

[](#目錄)

- [版本需求](#%E7%89%88%E6%9C%AC%E9%9C%80%E6%B1%82)
- [安裝](#%E5%AE%89%E8%A3%9D)
- [設定](#%E8%A8%AD%E5%AE%9A)
- [測試信用卡號](#%E6%B8%AC%E8%A9%A6%E4%BF%A1%E7%94%A8%E5%8D%A1%E8%99%9F)
- [MPG 多功能付款](#mpg-%E5%A4%9A%E5%8A%9F%E8%83%BD%E4%BB%98%E6%AC%BE)
    - [建立付款流程](#%E5%BB%BA%E7%AB%8B%E4%BB%98%E6%AC%BE%E6%B5%81%E7%A8%8B)
    - [自訂付款選項](#%E8%87%AA%E8%A8%82%E4%BB%98%E6%AC%BE%E9%81%B8%E9%A0%85)
    - [接收付款結果](#%E6%8E%A5%E6%94%B6%E4%BB%98%E6%AC%BE%E7%B5%90%E6%9E%9C)
    - [取得付款結果的詳細資訊](#%E5%8F%96%E5%BE%97%E4%BB%98%E6%AC%BE%E7%B5%90%E6%9E%9C%E7%9A%84%E8%A9%B3%E7%B4%B0%E8%B3%87%E8%A8%8A)
- [ATM/超商取號](#atm%E8%B6%85%E5%95%86%E5%8F%96%E8%99%9F)
- [單筆交易查詢](#%E5%96%AE%E7%AD%86%E4%BA%A4%E6%98%93%E6%9F%A5%E8%A9%A2)
- [信用卡取消授權](#%E4%BF%A1%E7%94%A8%E5%8D%A1%E5%8F%96%E6%B6%88%E6%8E%88%E6%AC%8A)
- [信用卡請款](#%E4%BF%A1%E7%94%A8%E5%8D%A1%E8%AB%8B%E6%AC%BE)
- [信用卡退款](#%E4%BF%A1%E7%94%A8%E5%8D%A1%E9%80%80%E6%AC%BE)
- [信用卡定期定額委託](#%E4%BF%A1%E7%94%A8%E5%8D%A1%E5%AE%9A%E6%9C%9F%E5%AE%9A%E9%A1%8D%E5%A7%94%E8%A8%97)
    - [建立委託](#%E5%BB%BA%E7%AB%8B%E5%A7%94%E8%A8%97)
    - [授權週期](#%E6%8E%88%E6%AC%8A%E9%80%B1%E6%9C%9F)
    - [授權期數](#%E6%8E%88%E6%AC%8A%E6%9C%9F%E6%95%B8)
    - [授權起始方式](#%E6%8E%88%E6%AC%8A%E8%B5%B7%E5%A7%8B%E6%96%B9%E5%BC%8F)
    - [接收委託結果](#%E6%8E%A5%E6%94%B6%E5%A7%94%E8%A8%97%E7%B5%90%E6%9E%9C)
    - [修改委託狀態](#%E4%BF%AE%E6%94%B9%E5%A7%94%E8%A8%97%E7%8B%80%E6%85%8B)
    - [修改委託內容](#%E4%BF%AE%E6%94%B9%E5%A7%94%E8%A8%97%E5%85%A7%E5%AE%B9)
- [參考](#%E5%8F%83%E8%80%83)
- [贊助](#%E8%B4%8A%E5%8A%A9)
- [License](#license)

版本需求
----

[](#版本需求)

版本PHP 版本Laravel 版本1.x&gt;=8.1&gt;=9.x2.x&gt;=8.1&gt;=9.x安裝
--

[](#安裝)

使用 Composer 安裝套件：

```
composer require ycs77/laravel-newebpay
```

發布設置檔案：

```
php artisan vendor:publish --tag=newebpay-config
```

設定
--

[](#設定)

前往藍新金流的網站上註冊帳號（測試時需註冊測試帳號）和建立商店。然後在「商店資料設定」中啟用需要使用的金流功能（測試時可以盡量全部啟用），並複製商店串接 API 的商店代號、`HashKey` 和 `HashIV`。

設定 `.env` 的商店代號和 HashKey 等參數：

```
NEWEBPAY_ENV=test            # 設定 API 運行環境 (production 或 test)
NEWEBPAY_MERCHANT_ID=...        # 貼上 商店代號 (Ex: MS3311...)
NEWEBPAY_MERCHANT_HASH_KEY=...  # 貼上 HashKey
NEWEBPAY_MERCHANT_HASH_IV=...   # 貼上 HashIV
```

`NEWEBPAY_ENV` 可以設定為 `test`（測試環境）或 `production`（正式環境）。

測試信用卡號
------

[](#測試信用卡號)

測試環境僅接受以下的測試信用卡號：

- 4000-2211-1111-1111 (一次付清+分期付款)
- 4003-5511-1111-1111 (紅利折抵)

測試卡號有效月年及卡片背面末三碼，可任意填寫。

MPG 多功能付款
---------

[](#mpg-多功能付款)

### 建立付款流程

[](#建立付款流程)

首先建立一個含有表單的頁面，讓用戶點擊「付款」按鈕後送出 POST 請求：

*resources/views/pay.blade.php*

```

    @csrf
    付款

```

Inertia.js 可以參考以下：

*resources/js/pages/Pay.vue*

```

    付款

defineProps()

```

然後設定路由來發送 MPG 多功能付款請求：

```
use Ycs77\NewebPay\Facades\NewebPay;

Route::post('/pay', function () {
    return NewebPay::payment()
        ->withOrder('Vanespl_ec_'.time())                    // 訂單編號
        ->withAmount(120)                                    // 交易金額
        ->withItemDescription('我的商品')                     // 商品名稱
        ->withEmail('test@example.com')                      // 付款人信箱
        ->withReturnUrl(config('app.url').'/pay/callback')   // 前景回傳網址 (Callback)
        ->withNotifyUrl(config('app.url').'/pay/notify')     // 背景通知網址 (Notify)
        ->submit();
});
```

付款完成後，藍新金流會將結果回傳到指定的網址。信用卡之類可以直接跳轉回網站的付款方式，設定 callback：

```
use Illuminate\Http\Request;
use Ycs77\NewebPay\Facades\NewebPay;

Route::post('/pay/callback', function (Request $request) {
    $result = NewebPay::result($request);

    if ($result->isFail()) {
        return redirect()
            ->to('/pay')
            ->with('error', $result->message());
    }

    // 訂單付款成功，處理訂單邏輯...

    return redirect()
        ->to('/pay')
        ->with('success', '付款成功');
});
```

如果是 ATM 的付款方式，需要透過幕後回傳的，設定 notify：

```
use Illuminate\Http\Request;
use Ycs77\NewebPay\Facades\NewebPay;

Route::post('/pay/notify', function (Request $request) {
    $result = NewebPay::result($request);

    if ($result->isFail()) {
        return;
    }

    logger('藍新金流 交易資訊 notify', ['result' => $result->toArray()]);

    // 訂單付款成功，處理訂單邏輯...
});
```

還要把這些路徑在 `app/Http/Middleware/VerifyCsrfToken.php` 中排除 CSRF 檢查：

```
class VerifyCsrfToken extends Middleware
{
    protected $except = [
        '/pay/callback',
        '/pay/notify',
    ];
}
```

### 自訂付款選項

[](#自訂付款選項)

基本上一般交易可直接在 `config/newebpay.php` 做設定，但若遇到特殊情況，可依據個別交易設定更多付款選項。

**交易限制**

設定交易的秒數限制和截止天數：

```
NewebPay::payment()
    ...
    ->withTradeLimit(900)  // 交易秒數限制 (60~900 秒)
    ->withExpireDays(14)   // 交易截止日 (天數，最大 180 天)
    ->submit();
```

**回傳網址**

設定付款完成後的回傳網址：

```
NewebPay::payment()
    ...
    ->withReturnUrl(config('app.url').'/pay/callback')      // 前景回傳網址 (Callback)
    ->withNotifyUrl(config('app.url').'/pay/notify')        // 背景通知網址 (Notify)
    ->withCustomerUrl(config('app.url').'/pay/customer')    // 商店取號網址
    ->withClientBackUrl(config('app.url').'/pay/back')      // 返回按鈕網址
    ->submit();
```

**付款方式**

覆蓋 config 中的付款方式設定，格式與 config 相同：

```
NewebPay::payment()
    ...
    ->withPaymentMethods([...]) // 付款方式 *依照 config 格式傳送*
    ->submit();
```

**信用卡記憶卡號**

啟用信用卡記憶卡號功能，傳入付款人名稱：

```
NewebPay::payment()
    ...
    ->withCreditRemember('John Doe')
    ->submit();
```

**其他選項**

```
NewebPay::payment()
    ...
    ->disableEmailModify()           // 禁止修改 email
    ->withOrderComment('這是訂單備註') // 商店備註 (最大 300 字)
    ->submit();
```

**物流設定**

設定超商物流相關選項：

```
use Ycs77\NewebPay\Enums\CVSCOM;
use Ycs77\NewebPay\Enums\LgsType;

NewebPay::payment()
    ...
    ->withLogisticsPayment(CVSCOM::NOT_PAY_AND_PAY) // 物流方式
    ->withLogisticsType(LgsType::C2C)               // 物流型態
    ->submit();
```

### 接收付款結果

[](#接收付款結果)

在[建立付款流程](#%E5%BB%BA%E7%AB%8B%E4%BB%98%E6%AC%BE%E6%B5%81%E7%A8%8B)中已設定了基本的 callback 和 notify 路由。如果同時設定了 callback 和 notify，進行部分交易時兩個 API 都會發送訊息，這時就要各司其職，callback 只設定返回給用戶的訊息，而 notify 只負責處理交易的邏輯：

```
use Illuminate\Http\Request;
use Ycs77\NewebPay\Facades\NewebPay;

Route::post('/pay/callback', function (Request $request) {
    $result = NewebPay::result($request);

    if ($result->isFail()) {
        return redirect()
            ->to('/pay')
            ->with('error', $result->message());
    }

    return redirect()
        ->to('/pay')
        ->with('success', '付款成功');
});

Route::post('/pay/notify', function (Request $request) {
    $result = NewebPay::result($request);

    if ($result->isFail()) {
        return;
    }

    logger('藍新金流 交易資訊 notify', ['result' => $result->toArray()]);

    // 訂單付款成功，處理訂單邏輯...
});
```

回傳結果可以使用各個方法來取得需要的資料：

```
$result = NewebPay::result($request);
$result->status()          // 交易狀態：'SUCCESS' 或錯誤代碼
$result->isSuccess()       // 交易是否成功
$result->isFail()          // 交易是否失敗
$result->message()         // 交易狀態描述：'授權成功'
$result->result()          // 回傳參數 (陣列)
$result->merchantId()      // 藍新金流商店代號：'MS3311...'
$result->amount()          // 交易金額：120
$result->tradeNo()         // 藍新金流交易序號：'23061500000000000'
$result->orderNo()         // 商店訂單編號：'1686759318'
$result->paymentType()     // 付款方式：PaymentType::CREDIT
$result->payTime()         // 支付完成時間：Carbon 實例
$result->ip()              // 交易 IP：'127.0.0.1'
$result->escrowBank()      // 款項保管銀行：'HNCB'
```

### 取得付款結果的詳細資訊

[](#取得付款結果的詳細資訊)

根據不同的付款方式，可以取得對應的詳細資訊：

```
use Ycs77\NewebPay\Enums\PaymentType;

// 信用卡支付回傳（一次付清、Google Pay、Samaung Pay、國民旅遊卡、銀聯）
if ($result->paymentType() === PaymentType::CREDIT) {
    $credit = $result->credit();
    // 參考：\Ycs77\NewebPay\Results\Trade\CreditResult
}

// WEBATM、ATM 繳費回傳
if ($result->paymentType() === PaymentType::VACC || $result->paymentType() === PaymentType::WEBATM) {
    $atm = $result->atm();
    // 參考：\Ycs77\NewebPay\Results\Trade\ATMResult
}

// 超商代碼繳費回傳
if ($result->paymentType() === PaymentType::CVS) {
    $storeCode = $result->storeCode();
    // 參考：\Ycs77\NewebPay\Results\Trade\StoreCodeResult
}

// 超商條碼繳費回傳
if ($result->paymentType() === PaymentType::BARCODE) {
    $storeBarcode = $result->storeBarcode();
    // 參考：\Ycs77\NewebPay\Results\Trade\StoreBarcodeResult
}

// 超商物流回傳
if ($result->paymentType() === PaymentType::CVSCOM) {
    $lgs = $result->lgs();
    // 參考：\Ycs77\NewebPay\Results\Trade\LgsResult
}

// 跨境支付回傳 (包含簡單付電子錢包、簡單付微信支付、簡單付支付寶)
$ezPay = $result->ezPay();
// 參考：\Ycs77\NewebPay\Results\Trade\EzPayResult

// 玉山 Wallet 回傳
if ($result->paymentType() === PaymentType::ESUNWALLET) {
    $esunWallet = $result->esunWallet();
    // 參考：\Ycs77\NewebPay\Results\Trade\EsunWalletResult
}

// 台灣 Pay 回傳
if ($result->paymentType() === PaymentType::TAIWANPAY) {
    $taiwanPay = $result->taiwanPay();
    // 參考：\Ycs77\NewebPay\Results\Trade\TaiwanPayResult
}
```

ATM/超商取號
--------

[](#atm超商取號)

預設會直接導向到藍新金流的取號頁面，沒有特別需求不需要自己做。但如果要自訂取號頁面的話，也是可以自己客製調整：

```
use Illuminate\Http\Request;
use Ycs77\NewebPay\Facades\NewebPay;

Route::post('/pay/customer', function (Request $request) {
    $result = NewebPay::customer($request);

    if ($result->isFail()) {
        // 取號錯誤...
        return;
    }

    $result->merchantId()  // 藍新金流商店代號：'MS3311...'
    $result->amount()      // 交易金額：120
    $result->tradeNo()     // 藍新金流交易序號：'23061500000000000'
    $result->orderNo()     // 商店訂單編號：'1686763446'
    $result->paymentType() // 付款方式：PaymentType::BARCODE
    $result->expireTime()  // 繳費截止日期：Carbon 實例

    // 根據付款方式取得對應的取號資訊：
    $result->atm()          // ATM 繳費資訊
    $result->storeCode()    // 超商代碼繳費資訊
    $result->storeBarcode() // 超商條碼繳費資訊
    $result->lgs()          // 超商物流資訊

    // 自訂取號結果頁面...
});
```

還要把路徑在 `app/Http/Middleware/VerifyCsrfToken.php` 中排除 CSRF 檢查：

```
class VerifyCsrfToken extends Middleware
{
    protected $except = [
        ...
        '/pay/customer',
    ];
}
```

單筆交易查詢
------

[](#單筆交易查詢)

從訂單編號和該筆交易的金額來查詢交易詳情：

```
use Ycs77\NewebPay\Facades\NewebPay;

$result = NewebPay::query()
    ->withOrder('Order001') // 該筆交易的訂單編號
    ->withAmount(1050)      // 該筆交易的金額
    ->get();

$result->merchantId() // 藍新金流商店代號：'TestMerchantID1234'
$result->orderNo()    // 商店訂單編號：'Order001'
$result->tradeNo()    // 藍新金流交易序號：'23061500000000000'
$result->amount()     // 交易金額：1050
```

如果是組合型商店，可以使用 `forCompositeStore()` 來查詢：

```
$result = NewebPay::query()
    ->withOrder('Order001')
    ->withAmount(1050)
    ->forCompositeStore()
    ->get();
```

信用卡取消授權
-------

[](#信用卡取消授權)

在尚未請款時可以發動取消信用卡交易。使用訂單編號取消授權：

```
use Ycs77\NewebPay\Facades\NewebPay;

$result = NewebPay::creditCard()
    ->reverse()
    ->withOrder('Order001') // 該筆交易的訂單編號
    ->withAmount(1050)      // 該筆交易的金額
    ->send();

$result->merchantId() // 藍新金流商店代號：'TestMerchantID1234'
$result->orderNo()    // 商店訂單編號：'Order001'
$result->tradeNo()    // 藍新金流交易序號：'23061500000000000'
$result->amount()     // 取消授權金額：1050
```

或者使用藍新交易編號取消授權：

```
$result = NewebPay::creditCard()
    ->reverse()
    ->withTrade('23061500000000000') // 藍新金流交易序號
    ->withAmount(1050)
    ->send();
```

信用卡請款
-----

[](#信用卡請款)

信用卡請款：

```
use Ycs77\NewebPay\Facades\NewebPay;

$result = NewebPay::creditCard()
    ->capture()
    ->withOrder('Order001') // 該筆交易的訂單編號
    ->withAmount(1050)      // 該筆交易的金額
    ->send();

$result->merchantId() // 藍新金流商店代號：'TestMerchantID1234'
$result->orderNo()    // 商店訂單編號：'Order001'
$result->tradeNo()    // 藍新金流交易序號：'23061500000000000'
$result->amount()     // 請款金額：1050
```

取消請款，在請款的基礎上加上 `reverse()`：

```
$result = NewebPay::creditCard()
    ->capture()
    ->withOrder('Order001')
    ->withAmount(1050)
    ->reverse() // 取消請款
    ->send();
```

信用卡退款
-----

[](#信用卡退款)

信用卡退款：

```
use Ycs77\NewebPay\Facades\NewebPay;

$result = NewebPay::creditCard()
    ->refund()
    ->withOrder('Order001') // 該筆交易的訂單編號
    ->withAmount(1050)      // 該筆交易的金額
    ->send();

$result->merchantId() // 藍新金流商店代號：'TestMerchantID1234'
$result->orderNo()    // 商店訂單編號：'Order001'
$result->tradeNo()    // 藍新金流交易序號：'23061500000000000'
$result->amount()     // 退款金額：1050
```

取消退款，在退款的基礎上加上 `reverse()`：

```
$result = NewebPay::creditCard()
    ->refund()
    ->withOrder('Order001')
    ->withAmount(1050)
    ->reverse() // 取消退款
    ->send();
```

信用卡定期定額委託
---------

[](#信用卡定期定額委託)

### 建立委託

[](#建立委託)

建立信用卡定期定額委託的基本範例：

```
use Ycs77\NewebPay\Facades\NewebPay;

Route::post('/subscribe', function () {
    return NewebPay::period()
        ->create()
        ->withOrder('Order'.time())                                   // 訂單編號
        ->withAmount(120)                                             // 交易金額
        ->withItemDescription('我的訂閱制商品')                        // 商品名稱
        ->withEmail('test@example.com')                               // 付款人信箱
        ->withReturnUrl(config('app.url').'/pay/period/callback')     // 前景回傳網址 (Callback)
        ->withNotifyUrl(config('app.url').'/pay/period/notify')       // 背景通知網址 (Notify)
        ->everyFewDays(2)                                             // 每隔 2 天授權一次
        ->times(3)                                                    // 共授權 3 次
        ->submit();
});
```

發送建立委託前需要先建立一個含有表單的頁面：

*resources/views/subscribe.blade.php*

```

    @csrf
    訂閱

```

### 授權週期

[](#授權週期)

若於週期內需授權多次，請以建立多次委託方式執行。

設定此委託於固定天期制授權，輸入數字為間隔天數 2~999。以授權日期隔日起算，以下為每隔 40 天授權一次：

```
NewebPay::period()
    ->create()
    ...
    ->everyFewDays(40)
    ->times(1)
    ->submit();
```

設定此委託於每週授權，輸入數字為 1~7，代表每週一至週日。以下為每週日授權一次：

```
NewebPay::period()
    ->create()
    ...
    ->weekly(7)
    ->times(1)
    ->submit();
```

設定此委託於每月授權，輸入數字為 1~31，每月的第幾天執行委託，若當月沒該日期則由該月的最後一天做為扣款日。以下為每月 20 日授權一次：

```
NewebPay::period()
    ->create()
    ...
    ->monthly(20)
    ->times(1)
    ->submit();
```

設定此委託於每年授權，輸入每年的幾月幾日執行委託。以下為每年 3 月 4 日授權一次：

```
NewebPay::period()
    ->create()
    ...
    ->yearly(3, 4)
    ->times(1)
    ->submit();
```

### 授權期數

[](#授權期數)

設定授權委託的期數。以下為每月 4 日授權，共授權 6 次，為期 6 個月：

```
NewebPay::period()
    ->create()
    ...
    ->monthly(4)
    ->times(6)
    ->submit();
```

### 授權起始方式

[](#授權起始方式)

設定立即執行十元授權，以驗證信用卡：

```
'period' => [
    'start_type' => PeriodStartType::TEN_DOLLARS_NOW,
],
```

設定立即執行委託金額授權：

```
'period' => [
    'start_type' => PeriodStartType::AUTHORIZE_NOW,
],
```

設定刷卡完之後，不檢查信用卡資訊，也不執行授權：

```
'period' => [
    'start_type' => PeriodStartType::NO_AUTHORIZE,
],
```

當選擇不授權時，需要設定首期授權日：

```
NewebPay::period()
    ->create()
    ...
    ->everyFewDays(2)
    ->times(3)
    ->firstChargeAt(2023, 3, 1) // 首期授權日
    ->submit();
```

### 接收委託結果

[](#接收委託結果)

設定建立委託完成後，將頁面導向回原本的網站頁面：

```
use Illuminate\Http\Request;
use Ycs77\NewebPay\Facades\NewebPay;

Route::post('/pay/period/callback', function (Request $request) {
    $result = NewebPay::periodResult($request);

    if ($result->isFail()) {
        return redirect()->to('/pay')->with('error', $result->message());
    }

    $result->merchantID()   // 藍新金流商店代號：'TestMerchantID1234'
    $result->orderNo()      // 商店訂單編號：'Order001'
    $result->periodNo()     // 委託單號：'20200101000000001'
    $result->periodAmount() // 委託金額：1050

    return redirect()->to('/pay')->with('success', '付款成功');
});
```

以及設定每期委託授權結果通知：

```
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Ycs77\NewebPay\Facades\NewebPay;

Route::post('/pay/period/notify', function (Request $request) {
    $result = NewebPay::periodNotify($request);

    if ($result->isFail()) {
        Log::error('藍新金流 定期定額 定期交易錯誤', $result->toArray());

        return;
    }

    $result->merchantID()  // 藍新金流商店代號：'TestMerchantID1234'
    $result->orderNo()     // 商店訂單編號：'Order001'
    $result->authAmount()  // 本期授權金額：1050
    $result->periodNo()    // 委託單號：'20200101000000001'

    // 委託授權成功，處理訂單邏輯...
});
```

記得要把這些路徑在 `app/Http/Middleware/VerifyCsrfToken.php` 中排除 CSRF 檢查：

*app/Http/Middleware/VerifyCsrfToken.php*

```
class VerifyCsrfToken extends Middleware
{
    protected $except = [
        ...
        '/pay/period/callback',
        '/pay/period/notify',
    ];
}
```

### 修改委託狀態

[](#修改委託狀態)

修改委託狀態需要傳入訂單編號和委託單號，並呼叫對應的狀態方法：

終止委託：

```
use Ycs77\NewebPay\Facades\NewebPay;

$result = NewebPay::period()
    ->alterStatus()
    ->withOrder('Order001')                // 訂單編號
    ->withPeriod('20200101000000001')       // 委託單號
    ->terminate();                         // 終止委託

$result->orderNo()       // 商店訂單編號：'Order001'
$result->periodNo()      // 委託單號：'20200101000000001'
$result->periodStatus()  // 委託狀態：PeriodStatus::TERMINATE
```

暫停委託：

```
$result = NewebPay::period()
    ->alterStatus()
    ->withOrder('Order001')
    ->withPeriod('20200101000000001')
    ->suspend(); // 暫停委託
```

暫停後重新啟用委託：

```
$result = NewebPay::period()
    ->alterStatus()
    ->withOrder('Order001')
    ->withPeriod('20200101000000001')
    ->resume(); // 重新啟用委託
```

Important

委託狀態設定成暫停之後可以改成啟用，但終止委託後就無法再次啟用了。暫停後再次啟用的委託將於最近一期開始授權，總期數不變，扣款時間將向後展延至期數滿期。

### 修改委託內容

[](#修改委託內容)

修改委託內容需要傳入訂單編號、委託單號，和設定要修改成的委託觸發週期和授權次數：

```
use Ycs77\NewebPay\Facades\NewebPay;

$result = NewebPay::period()
    ->alter()
    ->withOrder('Order001')            // 訂單編號
    ->withPeriod('20200101000000001')  // 委託單號
    ->withAmount(1000)                 // 新的委託金額
    ->everyFewDays(3)                  // 新的授權週期
    ->times(10)                        // 新的授權次數
    ->send();

$result->orderNo()       // 商店訂單編號：'Order001'
$result->periodNo()      // 委託單號：'20200101000000001'
$result->periodAmount()  // 新的委託金額：1000
```

參考
--

[](#參考)

[NewebPay Payment API](https://www.newebpay.com/website/Page/content/download_api#1)

貢獻專案
----

[](#貢獻專案)

歡迎參與貢獻專案，請參考 [貢獻指南](CONTRIBUTING.md) 文件。

贊助
--

[](#贊助)

如果我維護的套件有幫助到你，可以考慮[贊助我](https://www.patreon.com/ycs77)~ 我會很感謝你~ 而且還可以顯示您的大頭貼在我的主要專案中。

 [ ![](https://camo.githubusercontent.com/be34c63895cd13789477fcf54bf48d2f6d9e0872b33e3a2a88aa17be43037e9f/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f67682f79637337372f7374617469632f73706f6e736f72732e737667) ](https://www.patreon.com/ycs77)

[ ![Become a Patron](https://camo.githubusercontent.com/ef7b855018f1f680eeba6fd1ac470b9c1971ef883b2f4b9fcf41034274510e3f/68747470733a2f2f63352e70617472656f6e2e636f6d2f65787465726e616c2f6c6f676f2f6265636f6d655f615f706174726f6e5f627574746f6e2e706e67)](https://www.patreon.com/ycs77)License
-------

[](#license)

Under the [MIT LICENSE](LICENSE)

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance68

Regular maintenance activity

Popularity38

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 92.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~214 days

Total

11

Last Release

52d ago

Major Versions

v0.3.1 → v1.0.02024-12-12

1.x-dev → 2.x-dev2026-03-28

PHP version history (2 changes)v0.1.0PHP &gt;=5.6

v0.3.0-alpha.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/a5a1e0caa0c50990d8ffc70d4a095706a4e2b71bd6a0f08860744f773c6f99a9?d=identicon)[ycs77](/maintainers/ycs77)

---

Top Contributors

[![ycs77](https://avatars.githubusercontent.com/u/38133356?v=4)](https://github.com/ycs77 "ycs77 (187 commits)")[![wallasehuang](https://avatars.githubusercontent.com/u/6116336?v=4)](https://github.com/wallasehuang "wallasehuang (15 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/ycs77-laravel-newebpay/health.svg)

```
[![Health](https://phpackages.com/badges/ycs77-laravel-newebpay/health.svg)](https://phpackages.com/packages/ycs77-laravel-newebpay)
```

###  Alternatives

[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[andreaselia/laravel-api-to-postman

Generate a Postman collection automatically from your Laravel API

1.0k586.2k3](/packages/andreaselia-laravel-api-to-postman)[laravel-zero/framework

The Laravel Zero Framework.

3371.4M369](/packages/laravel-zero-framework)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[simplestats-io/laravel-client

Client for SimpleStats!

4515.5k](/packages/simplestats-io-laravel-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
