PHP code example of fall1600 / ecpay

1. Go to this page and download the library: Download fall1600/ecpay 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 / ecpay example snippets


$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 = new Ecpay();
$ecpay
    ->setIsProduction(false) // 設定環境, 預設就是走正式機
    ->setMerchant(new Merchant($merchantId, $hashKey, $hashIv))
    ->checkout($info);



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