Ecpay
Payment solution of ECPay(綠界科技), implementing by pure PHP
Install / Use
/learn @fall1600/EcpayREADME
EcPay 綠界金流
How to use
建立交易資訊 (BasicInfo)
- $merchantId: 你在綠界申請的商店代號
- $returnUrl: 用來接收綠界付款通知的callback url
- $order: 你的訂單物件, 務必實作package 中的OrderInterface
- $paymentType: 預設交易方式全部開啟
$info = new BasicInfo($merchantId, $returnUrl, $order, $paymentType = 'ALL');
控制交易方式
// 反向的設定概念, 依需求關閉付款方式(可參考PaymentType 付款方式)
$info = new IgnorePayment($info, 'ATM', 'BARCODE');
// 信用卡設定, quickCredit 可開啟記憶信用卡(需實作QuickCreditInterface), 以及設定紅利折抵
$info = new Credit($info, $quickCredit, true);
// 信用卡分期付款設定
$info = new PayInInstallments($info, '3,6,12,18,24');
// 虛擬ATM 繳費設定, 接收取號的webhook url, 要號完成的回導位置, 繳費期限(天), 預設3天
$info = new Atm($info, $paymentInfoUrl, $clientRedirectUrl, 10);
// 超商繳費設定, 繳費期限(分鐘), 預設10080分鐘=7天
$info = new Cvs($info, $paymentInfoUrl, $clientRedirectUrl, 30);
// 超商條碼繳費設定, 繳費期限(天), 預設7天
$info = new Barcode($info, $paymentInfoUrl, $clientRedirectUrl, 3);
// 是否需要額外的付款資訊
$info = new ExtraInfo($info);
// 特店子商城id
$info = new SubMerchant($info, $subMerchantId);
建立Ecpay 物件, 注入商店資訊, 帶著交易資訊前往綠界付款
- $merchantId: 你在綠界商店代號
- $hashKey: 你在綠界商店專屬的HashKey
- $hashIv: 你在綠界商店專屬的HashIV
$ecpay = new Ecpay();
$ecpay
->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...
}
解開來自綠界的交易通知
$isValid = $merchant->setRawData($request->all())->validateResponse(); //確認為true 後再往下走
// response 封裝了通知交易的結果, 以下僅列常用methods
$response = $merchant->getResponse();
// 付款成敗
$response->getReturnCode();
// 取得交易序號
$response->getTradeNo();
// 取得訂單編號, 就是OrderInterface 實作的getMerchantOrderNo
$response->getMerchantOrderNo();
// 付款時間
$response->getPaymentDate();
// 整包payload
$response->getData();
單筆交易查詢
$resp = $ecpay
->setMerchant($merchant)
->query($order, $platformId = null);
$isValid = $merchant->setRawData($resp)->validResponse(); // 查詢的response, 有需要也可以validate
各種url 你分的清楚嗎?
| Name | 用途 | 設定的物件 | 備註 | |:-----------------|:------------------------------------ |:-------------|:---------------------------------------------------------| | ReturnURL | 通知你系統交易資訊的callback url | BasicInfo | 通常用在訂單付款狀態切換, 最重要,所以BasicInfo 就要設定了, 此webhook 檢查完checksum 後要return 1|OK (半形的|) 給綠界 | | OrderResultURL | 付款完成回到你系統的位置 | PayComplete | 沒設定就是顯示在綠界 | | PaymentInfoURL | 離線付款取號完成通知你系統的callback url | Atm, Barcode, Cvs | 用在紀錄離線付款的取號, 務必設定, 此webhook 檢查完checksum 後要return 1|OK (半形的|) 給綠界 | | ClientRedirectURL| 離線付款取號完成要回到你系統的位置 | Atm, Barcode, Cvs | 沒設定就是顯示在綠界 | | ClientBackURL | 任何時候在綠界想返回你系統的位置 | ClientBack | 沒設定在綠界就不會顯示[返回商店] | | PeriodReturnURL | 定期定額授權結果回傳通知你系統的 callback url | PayInPeriods | 用在定期定額的執行結果, 務必設定 |
Related Skills
node-connect
340.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
340.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.1kCommit, push, and open a PR
