PHP code example of maras0830 / laravel-paynow

1. Go to this page and download the library: Download maras0830/laravel-paynow 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/ */

    

maras0830 / laravel-paynow example snippets


'providers' => [
   // ....
   Maras0830\PayNowSDK\Providers\PayNowServiceProvider::class
],

$now = \Carbon\Carbon::now('Asia/Taipei');
$transaction = new Maras0830\PayNowSDK\CreditCardTransaction($now);

$card_number = '4023730207292803';
$valid_year = '20';
$valid_month = '05';
$safe_code = '685';
    
// $res is transaction response.
$res = $transaction
    ->setEncrypt()
    ->setOrder('測試交易', 'OWLTEST1000111002', 100) // orderinfo strlen > 3
    ->setCreditCard($card_number, $valid_year, $valid_month, $safe_code)
    ->setCustomer(1, 'Eric', '09121212121212', '[email protected]', '127.0.0.1')
    ->checkout()
    ->decodeAndValidate();

$my_order_number = 'TEST10001';

$sdk = new Maras0830\PayNowSDK\PayNowAPI();

/**
 * @throws Maras0830\PayNowSDK\Exceptions\OrderNotFoundException
 * @throws Maras0830\PayNowSDK\Exceptions\TransactionException
 * @throws Maras0830\PayNowSDK\Exceptions\OrderIsCancelException
 * @throws Maras0830\PayNowSDK\Exceptions\UnKnownException
 */
$res = $sdk->transactionCheck($my_order_number);

/**
$res => [
    'order_number' => 'xxxxx' // Paynow Order number
    'last4' => 'xxxx'         // CreditCard last4 code
];
**/

$now = Carbon\Carbon::now('Asia/Taipei');
$transaction = new Maras0830\PayNowSDK\CreditCardTransaction($now);

$card_number = '4023730207292803';
$valid_year = '22';
$valid_month = '05';
$safe_code = '685';

$account = 'account';
$password = 'password';

/**
 * @throws Maras0830\PayNowSDK\Exceptions\PayNowException
 * @throws Maras0830\PayNowSDK\Exceptions\ValidateException
 * @throws Maras0830\PayNowSDK\Exceptions\TransactionException
 */
$res = $transaction
    ->setEncrypt()
    ->setOrder('測試交易', 'TEST123' . time(), 100) // orderinfo strlen > 3
    ->setCreditCard($card_number, $valid_year, $valid_month, $safe_code)
    ->setCustomer(1, 'Eric', '09121212121212', '[email protected]', '127.0.0.1', $account, $password)
    ->checkoutAndSaveCard()
    ->decodeAndValidate();

/**
$res = [
    "WebNo" => "70828783"
    "TotalPrice" => 100
    "OrderNo" => "TEST1231593574222"
    "ECPlatform" => null
    "BuySafeNo" => "8000002007014585819"
    "TranStatus" => "S"
    "PassCode" => "FDEA87E80373A00FAD48C89AD5BA32A954675678"
    "RespCode" => "00"
    "ResponseMSG" => ""
    "ApproveCode" => "A00001"
    "last4CardNo" => "2803"
    "CheckNo" => null
    "InvoiceNo" => null
    "batchNo" => null
    "InvoiceStatus" => null
    "Result3D" => ""
    "CIFID_SN" => "1"  // 該卡 token, 請保存
    "ReturnURL" => null
    "ErrorMessage" => ""
]
*/

$now = Carbon\Carbon::now('Asia/Taipei');
$transaction = new Maras0830\PayNowSDK\CreditCardTransaction($now);

$account = 'account';
$password = 'password';
$card_sn = '123'; // CIFID_SN

$res = $transaction
    ->setEncrypt()
    ->setOrder('測試交易', 'TEST123' . time(), 100) // orderinfo strlen > 3
    ->setCustomer(1, 'Eric', '09121212121212', '[email protected]', '127.0.0.1', $account, $password)
    ->checkoutBySN($card_sn) // safe_code can use 'XXX'
    ->decodeAndValidate();

/**
$res = [
    "WebNo" => "70828783"
    "TotalPrice" => 100
    "OrderNo" => "TEST1231593574222"
    "ECPlatform" => null
    "BuySafeNo" => "8000002007014585819"
    "TranStatus" => "S"
    "PassCode" => "FDEA87E80373A00FAD48C89AD5BA32A954675678"
    "RespCode" => "00"
    "ResponseMSG" => ""
    "ApproveCode" => "A00001"
    "last4CardNo" => "2803"
    "CheckNo" => null
    "InvoiceNo" => null
    "batchNo" => null
    "InvoiceStatus" => null
    "Result3D" => ""
    "CIFID_SN" => "1"  // 該卡 token, 請保存
    "ReturnURL" => null
    "ErrorMessage" => ""
]
*/



$payment_refund = new Maras0830\PayNowSDK\PaymentRefund();

$res = $payment_refund->refund(
    '8000001910145799460',
    '860.0000',
    '退款測試',
    1,
    '',
    '',
    '',
    '[email protected]',
    'Harley',
    '[email protected]'
);


$ php artisan vendor:publish --provider=Maras0830\PayNowSDK\Providers\PayNowServiceProvider