PHP code example of vb-payment / esunacq-cardlink

1. Go to this page and download the library: Download vb-payment/esunacq-cardlink 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/ */

    

vb-payment / esunacq-cardlink example snippets



    use VeryBuy\Payment\EsunBank\Acq\CardLink\RequestBuilder;

    // $mac 由玉山銀行提供`註冊`用的押碼
    $builder = new RequestBuilder($mac);

    /**
     * $SID 商家代碼
     * $SKey 使用者編號
     * $targetUrl 玉山 API 接口
     *
     * production: https://card.esunbank.com.tw/EsunCreditweb/txnproc/cardLink/commVerify
     * testing: https://cardtest.esunbank.com.tw/EsunCreditweb/txnproc/cardLink/commVerify
     */
//    單一商店
//    $communicate = $builder->communicate($targetUrl, [
//        'SID' => $SID,
//        'SKey' => $SKey,
//    ]);

    /**
     * 多商店版本
     */
    $communicate = $builder->communicate($targetUrl, [
        'SID' => '{專案代碼}',
        'SKey' => $SKey,
        'PRJCD' => 'C001',
        'PRJINFO' => $SID
    ]);

    if ($communicate->isSuccessful()) {
        print_r($communicate->getVerifyToken());
    }


    use VeryBuy\Payment\EsunBank\Acq\CardLink\RequestBuilder;

    // $mac 由玉山銀行提供`註冊`用的押碼
    $builder = new RequestBuilder($mac);

    /**
     * $SID 商家代碼
     * $SKey 使用者編號
     * $targetUrl 玉山 API 接口
     *
     * production: https://card.esunbank.com.tw/EsunCreditweb/txnproc/cardLink/rgstACC
     * testing: https://cardtest.esunbank.com.tw/EsunCreditweb/txnproc/cardLink/rgstACC
     *
     */
//    單一商店
//    echo $builder->registerForm($targetUrl, [
//        'SID' => $SID,
//        'SKey' => $SKey,
//        'txToken' => $communicate->getVerifyToken(),
//        'rData' => '提供商家傳值,原封不動回傳 length:200',
//    ]);

    /**
     * 多商店版本
     */
    echo $builder->registerForm($targetUrl, [
        'SID' => '{專案代碼}',
        'SKey' => $SKey,
        'txToken' => $communicate->getVerifyToken(),
        'rData' => '提供商家傳值,原封不動回傳 length:200',
    ]);


    use VeryBuy\Payment\EsunBank\Acq\CardLink\Response\RegisterFormResponse;

    $response = new RegisterFormResponse($_POST);

    if ($response->isSuccessful()) {
        print_r($response->getAccessToken());
    }


    use VeryBuy\Payment\EsunBank\Acq\CardLink\RequestBuilder;

    // $mac 由玉山銀行提供`註冊`用的押碼
    $builder = new RequestBuilder($mac);

    /**
     * $SID 商家代碼
     * $SKey 使用者編號
     * $targetUrl 玉山 API 接口
     *
     * production: https://card.esunbank.com.tw/EsunCreditweb/txnproc/cardLink/tknService
     * testing: https://cardtest.esunbank.com.tw/EsunCreditweb/txnproc/cardLink/tknService
     *
     */
//    單一商店
//    $trade = $builder->trade($targetUrl, [
//        'SID' => $SID,
//        'SKey' => $SKey,
//        'txToken' => $communicate->getVerifyToken(),
//        'LKey' => $response->getAccessToken(),
//        'OrderNo' => sprintf('TO%08d', 3), // 訂單編號 length:50
//        'TxnAmt' => 1000,   // 訂單金額
//        'TxnDesc' => '顯示在 CardLink 頁面上',
//        'rData' => '提供商家傳值,原封不動回傳 length:200',
//    ]);

    /**
     * 多商店版本
     */
    $trade = $builder->trade($targetUrl, [
        'SID' => '{專案代碼}',
        'SKey' => $SKey,
        'txToken' => $communicate->getVerifyToken(),
        'LKey' => $response->getAccessToken(),
        'OrderNo' => sprintf('TO%08d', 3), // 訂單編號 length:50
        'TxnAmt' => 1000,   // 訂單金額
        'TxnDesc' => '顯示在 CardLink 頁面上',
        'rData' => '提供商家傳值,原封不動回傳 length:200',
    ]);

    if ($trade->isSuccessful()) {
        print_r($trade->getTradeToken());
    }


    use VeryBuy\Payment\EsunBank\Acq\CardLink\RequestBuilder;
    use VeryBuy\Payment\EsunBank\Acq\CardLink\Request\AuthorizeRequest;

    // $mac 由玉山銀行提供`交易`用的押碼
    $builder = new RequestBuilder($mac);

    /**
     * $MID 商家代碼 ( 等同於註冊時的 SID )
     * $targetUrl 玉山 API 接口
     *
     * production: https://acq.esunbank.com.tw/ACQTrans/esuncard/txnf013c
     * testing: https://acqtest.esunbank.com.tw/ACQTrans/esuncard/txnf013c
     *
     */
//    單一商店
//    $authorize= $builder->authorize($targetUrl, [
//        'MID' => $MID,
//        'TID' => AuthorizeRequest::TYPE_TRANSACTION,
//        'ONO' => sprintf('TO%08d', 3), // 訂單編號,不可重複,不可包含【_】字元,英數限用大寫 length:50
//        'TA' => 1000, // 訂單金額
//        'TK' => $trade->getTradeToken(),
//    ]);

    /**
     * 多商店版本
     */
    $authorize= $builder->authorize($targetUrl, [
        'MID' => $MID,
        'TID' => AuthorizeRequest::TYPE_TRANSACTION,
        'ONO' => sprintf('TO%08d', 3), // 訂單編號,不可重複,不可包含【_】字元,英數限用大寫 length:50
        'TA' => 1000, // 訂單金額
        'TK' => $trade->getTradeToken(),
        'SID' => '{專案代碼}',
        'PRJCD' => 'C001',
    ]);

    if ($authorize->isSuccessful()) {
        print_r($trade->getOrderNumber());
    }


    use VeryBuy\Payment\EsunBank\Acq\CardLink\RequestBuilder;

    // $mac 由玉山銀行提供`交易`用的押碼
    $builder = new RequestBuilder($mac);

    /**
     * $MID 商家代碼 ( 等同於註冊時的 SID )
     * $targetUrl 玉山 API 接口
     *
     * production: https://acq.esunbank.com.tw/ACQTrans/esuncard/txnf0150
     * testing: https://acqtest.esunbank.com.tw/ACQTrans/esuncard/txnf0150
     *
     */
    $unauthorize = $builder->unauthorize($targetUrl, [
        'MID' => $MID,
        'ONO' => sprintf('TO%08d', 3),
    ]);

    if ($unauthorize->isSuccessful()) {
        print_r($unauthorize->getOrderNumber());
    }