abdallahmohammed/

laravel-telr

通过 Laravel 使用 Telr 支付网关在线支付

v1.0.1 2024-03-24 02:49 UTC

This package is auto-updated.

Last update: 2024-09-24 03:54:29 UTC


README

安装

您可以通过 composer 安装此包

composer require abdallahmohammed/laravel-telr

从 Laravel 6.x 版本开始,服务提供程序将自动注册。在框架的旧版本中,只需在 config/app.php 文件中添加服务提供程序即可

'providers' => [
    // ...
    TelrGateway\TelrServiceProvider::class,
];

您可以使用以下提供程序进行发布

php artisan vendor:publish --provider="TelrGateway\TelrServiceProvider"

之后,您可以通过运行迁移命令来创建 telr 交易表

php artisan migrate

发布后,配置文件 config/telr.php 包含

return [
    // The current mode is live|production or test
    'test_mode' => env('TELR_TEST_MODE', true),

    // The currency of store

    'currency' => 'SAR',

    // The sale endpoint that receive the params
    // @see https://telr.com/support/knowledge-base/hosted-payment-page-integration-guide
    'sale' => [
        'endpoint' => 'https://secure.telr.com/gateway/order.json',
    ],

    // The hosted payment page use the following params as it explained in the integration guide
    // @see https://telr.com/support/knowledge-base/hosted-payment-page-integration-guide/#request-method-and-format
    'create' => [
        'ivp_method' => "create",
        'ivp_store' => env('TELR_STORE_ID', null),
        'ivp_authkey' => env('TELR_STORE_AUTH_KEY', null),
        'return_auth' => '/handle-payment/success',
        'return_can' => '/handle-payment/cancel',
        'return_decl' => '/handle-payment/declined',
    ]
];

用法

在创建路由后,将以下代码放置以跳转到银行页面

$telrManager = new \TelrGateway\TelrManager();

$billingParams = [
        'first_name' => 'John',
        'sur_name' => 'Doe',
        // optional
        // 'address_1' => '',
        // 'address_2' => '',
        // 'city' => '',
        // 'region' => '',
        // 'zip' => '',
        'country' => 'EG',
        'email' => 'abdallah.r660@gmail.com',
    ];

return $telrManager->pay('ORDER_ID_GOES_HERE', 'TOTAL_AMOUNT', 'DESCRIPTION ...', $billingParams)->redirect();


> - note that if you want to avoid sending billing params while creating token to process the payment its applicable and the `Telr hosted payment page` will require it and will get the customer information on**check**request.

And on telr callback **(Success|Cancel|Declined)** to handle response put the following code:
```php
use \TelrGateway\TelrManager;

$telrManager = new TelrManager();
$telrManager->handleTransactionResponse($request);