PHP code example of rober-song / laravel-line-pay

1. Go to this page and download the library: Download rober-song/laravel-line-pay 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/ */

    

rober-song / laravel-line-pay example snippets


use Rober\LinePay\LinePay;

$response = LinePay::request([
    'amount' => 100,
    'currency' => 'TWD',
    'orderId' => 'order-123'
    ]);

return $response->getInfo();



/**
 * fake預設回傳
 * @see \Rober\LinePay\Fakes\PaymentFake::DEFAULT_RETURN
 */
use Rober\LinePay\LinePay;


test('[api] 測試確認', function () {
    LinePay::fake()->setReturn(info: ['orderId' => 'B',]);

    // 請求自己的對應api
    $response = $this->json('POST', '/line/pay/confirm/1');
    
    // 驗證
    $response->assertJson(['orderId' => 'B']);
});

test('[api] 多個請求', function () {
    LinePay::fake()
        ->setReturn(info: ['orderId' => 'A',])
        ->setReturn(code: '1141', message: 'Payment account error');

    // 請求自己的對應api
    $response = $this->json('POST', '/line/pay/A/and/B');
    // 驗證
    $response->assertStatus(400);
});
bash
php artisan vendor:publish --provider="Rober\LinePay\LinePayProvider"