PHP code example of muzik / omnipay-esafe

1. Go to this page and download the library: Download muzik/omnipay-esafe 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/ */

    

muzik / omnipay-esafe example snippets




use Omnipay\Omnipay;
use Muzik\OmnipayEsafe\EsafeGatewayFactory;
use Muzik\OmnipayEsafe\CreditCardGateway;

Omnipay::setFactory(new EsafeGatewayFactory());
$gateway = Omnipay::create(CreditCardGateway::class);
// When using testing endpoint for refunding, please use `$gateway->setTestMode(true)`
$gateway->setTestMode(true);

$gateway->setApiKey('abcd5888');
// The following two methods also can setting transaction password(API KEY) 
// $gateway->initialize(['api_key' => 'abcd5888']);
// $gateway->initialize(['transaction_password' => 'abcd5888']);



$response = $gateway->completePurchase([
    // POST from esafe.com.tw webhook
])->send();

if ($response->isSuccessful()) {
    // 付款成功
    var_dump($response->getData()); // 取得紅陽的回傳資料
} else {
    // 付款失敗
    var_dump($response);
}



$response = $gateway->refund([
    // 商家代號
    'web' => 'S1103020010',
    // 交易金額
    'MN' => '1688',
    // 紅陽交易編號
    'buysafeno' => '2400009912300000019',
    // 商家訂單編號
    'Td' => 'AC9087201',
    // 退貨原因
    'RefundMemo' => 'Foo Bar', 
])->send();

if ($response->isSuccessful()) {
    // 退款成功
} else {
    // 退款失敗
    var_dump($response->getData());
}



$response = $gateway->completePurchase([
    // POST from esafe.com.tw webhook
])->send();

if ($response->isSuccessful()) {
    // 付款成功
    var_dump($response->getData()); // 取得紅陽的回傳資料
} else {
    // 付款失敗
    var_dump($response);
}



$response = $gateway->refund([
    // 商家代號
    'web' => 'S1103020010',
    // 交易金額
    'MN' => '1688',
    // 紅陽交易編號
    'buysafeno' => '2400009912300000019',
    // 商家訂單編號
    'Td' => 'AC9087201',
    // 退貨原因
    'RefundMemo' => 'Foo Bar', 
])->send();

if ($response->isSuccessful()) {
    // 退款成功
} else {
    // 退款失敗
    var_dump($response->getData());
}