flamelin / ECPay by flamelin
forked from ScottChayaa/Allpay

ECPay for Laravel 5
12,011
4
2
Package Data
Maintainer Username: flamelin
Maintainer Contact: service@airo.com.tw (AIRO)
Package Create Date: 2017-02-03
Package Last Update: 2018-12-25
Home Page:
Language: PHP
License: Unknown
Last Refreshed: 2024-11-19 03:05:03
Package Statistics
Total Downloads: 12,011
Monthly Downloads: 825
Daily Downloads: 31
Total Stars: 4
Total Watchers: 2
Total Forks: 10
Total Open Issues: 3

Ecpay

Ecpay - Laravel 5 version

step 1 : Download the package composer命令安裝

composer require flamelin/ecpay dev-master

或者是新增package至composer.json

"require": {
  "flamelin/ecpay": "dev-master"
},

然後更新安裝

composer update

或全新安裝

composer install

'aliases' => [ // ... 'Ecpay' => flamelin\ECPay\Facade\Ecpay::class, ]


<br>
**step 3 : Publish config to your project**<br>
執行下列命令,將package的config檔配置到你的專案中

php artisan vendor:publish


可至config/ecpay.php中查看
預設是測試Ecpay設定
```php
return [
    'ServiceURL' => env('PAY_SERVICE_URL', 'https://payment-stage.ecpay.com.tw/Cashier/AioCheckOut/V2'),
    'HashKey' => env('PAY_HASH_KEY', '5294y06JbISpM5x9'),
    'HashIV' => env('PAY_HASH_IV', 'v77hoKGq4kWxNNIS'),
    'MerchantID' => env('PAY_MERCHANT_ID', '2000132'),
];

PAY_SERVICE_URL=https://payment-stage.ecpay.com.tw/Cashier/AioCheckOut/V2 PAY_HASH_KEY=5294y06JbISpM5x9 PAY_HASH_IV=v77hoKGq4kWxNNIS PAY_MERCHANT_ID=2000132


---

### How To Use 
```php
use Ecpay;
public function Demo()
{
    //Official Example : 
    //https://github.com/ECPay/ECPayAIO_PHP/blob/master/AioSDK/example/sample_Credit_CreateOrder.php
    
    //基本參數(請依系統規劃自行調整)
    Ecpay::i()->Send['ReturnURL']         = "http://www.ecpay.com.tw/receive.php" ;
    Ecpay::i()->Send['MerchantTradeNo']   = "Test".time() ;           //訂單編號
    Ecpay::i()->Send['MerchantTradeDate'] = date('Y/m/d H:i:s');      //交易時間
    Ecpay::i()->Send['TotalAmount']       = 2000;                     //交易金額
    Ecpay::i()->Send['TradeDesc']         = "good to drink" ;         //交易描述
    Ecpay::i()->Send['ChoosePayment']     = \ECPay_PaymentMethod::ALL ;     //付款方式

    //訂單的商品資料
    array_push(Ecpay::i()->Send['Items'], array('Name' => "緑界黑芝麻豆漿", 'Price' => (int)"2000",
               'Currency' => "元", 'Quantity' => (int) "1", 'URL' => "dedwed"));

    //Go to ECPay
    echo "緑界頁面導向中...";
    echo Ecpay::i()->CheckOutString();
}

用laravel的人開發盡量使用CheckOutString()回傳String的方法 當然使用CheckOut()也是可以 但如果使用的話,我猜後面可能會碰到Get不到特定Session的問題

//付款成功後緑界背景callback
public function doneDemo(Request $request)
{
    $arFeedback = Ecpay::i()->CheckOutFeedback($request->all());
    print Ecpay::i()->getResponse($arFeedback);
}

Example (Localhost)

Example Link : http://localhost/[your-project]/public/ecpay_demo_201702