PHP code example of fall1600 / suntech
1. Go to this page and download the library: Download fall1600/suntech library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fall1600 / suntech example snippets
// 信用卡付款
$info = new CreditInfo($creditMerchantId, $order, $payer);
// 銀聯卡付款, 與信用卡共用merchantId, webhook url設定; 文件第7頁
$info = new UnionPayInfo($unionMerchantId, $order, $payer);
// 虛擬Atm 付款, 與超商代收(條碼繳費單) 共用merchantId, webhook url設定; 文件第8頁
$info = (new AtmInfo($atmMerchantId, $order, $payer))
->appendProduct($product1)
->appendProduct($product2);
// 超商代收(條碼繳費單)
$info = (new CvsBarcodeInfo($barcodeMerchantId, $order, $payer))
->appendProduct($product1)
->appendProduct($product2);
// 超商代碼(ibon, FamiPort 那種)
$info = new CvsPaycodeInfo($paycodeMerchantId, $order, $payer);
// 台灣pay
$info = new TaiwanPayInfo($twpayMerchantId, $order, $payer);
$suntech = new Suntech();
$suntech
->setIsProduction(false) // 設定環境, 預設就是走正式機
->setMerchant(new Merchant($merchantId, $tradePassword))
->checkout($info);
namespace Your\Namespace;
use fall1600\Package\Suntech\Contracts\OrderInterface;
class Order implements OrderInterface
{
// your order detail...
}
namespace Your\Namespace;
use fall1600\Package\Suntech\Contracts\PayerInterface;
class Member implements PayerInterface
{
// your member detail...
}
// 信用卡的交易結果
$isValid = $merchant->setRawData($request->all(), ServiceType::CREDIT)->validateResponse();
// 超商代碼的交易結果
$isValid = $merchant->setRawData($request->all(), ServiceType::CVS_PAYCODE)->validateResponse();
// 超商代收(條碼繳費單)的交易結果
$isValid = $merchant->setRawData($request->all(), ServiceType::CVS_BARCODE)->validateResponse();
// 虛擬ATM 的交易結果
$isValid = $merchant->setRawData($request->all(), ServiceType::ATM)->validateResponse();
// WebATM 的交易結果
$isValid = $merchant->setRawData($request->all(), ServiceType::WEB_ATM)->validateResponse();
// 台灣pay 的交易結果
$isValid = $merchant->setRawData($request->all(), ServiceType::TAIWAN_PAY)->validateResponse();
// response 封裝了通知交易的結果, 以下僅列常用methods
$resp = $merchant->getResponse();
// 商城id
$resp->getMerchantId();
// 紅陽提供的交易代碼
$resp->getBuySafeNo();
// 交易金額
$resp->getAmount();
// 此回傳的檢核碼
$resp->getChecksum();
// 整包payload
$resp->getData();
$resp = $suntech
->setMerchant($merchant)
->query(new QueryRequest($merchantId, $order, $buySafeNo = null, $orderNumber = null, $note1 = null, $note2 = null));
$isValid = $merchant->setRawData($resp, 'query')->validResponse(); // 查詢的response, 有需要也可以validate