abdallahmohammed/urway-laravel

为Laravel的URWAY REST API包

1.2.3 2023-07-31 00:23 UTC

This package is auto-updated.

Last update: 2024-08-30 01:28:57 UTC


README

安装

composer require abdallahmohammed/urway-laravel

在Laravel 6.x版本及以上,服务提供者会自动注册。在框架的旧版本中,只需在config/app.php文件中添加服务提供者。

'providers' => [
    // ...
    URWay\URWayServiceProvider::class,
],

您可以选择在config/app.php中注册门面。

'facades' => [
    // ...
    'URWay' => URWay\Facade\URWay::class,
],

您可以使用以下命令发布:

php artisan vendor:publish --provider="URWay\URWayServiceProvider"

发布后,config/urway.php配置文件将包含:

<?php

return [
    'mode' => env('URWAY_MODE', 'test'),
    'auth' => [
        'terminal_id' => env('URWAY_TERMINAL_ID'),
        'password' => env('URWAY_PASSWORD'),
        'merchant_key' => env('URWAY_MERCHANT_KEY'),
    ],
];

使用方法

use URWay\Client;

// Create clint instance.
$client = new Client();

$client->setTrackId('YOUR_TRAKING_ID')
        ->setCustomerEmail('...')
        ->setCustomerIp('...')
        ->setCurrency('USD')
        ->setCountry('EG')
        ->setAmount(5)
        ->setRedirectUrl('...');

// Replace presented attributes with the given array.
$client->setAttributes([
    '...' => '...'
]);

// Merge presented attributes the given array.
$client->mergeAttributes([
    '...' => '...'
]);

// Replace one of presented attributes with the new value.
$client->setAttribute('...', '...');

// Remove one of attributes.
$client->removeAttribute('...');

// Determine whether an attribute exists.
$client->hasAttribute('...'); // returns boolean (true, or false)

$redirect_url = $client->pay();

return redirect()->url($redirect_url);

并在回调中处理响应,请放置以下代码

use URWay\Client;

// Create clint instance.
$client = new Client();

$response = $client->find('TRANSACTION_ID');

if ($response->isSuccess()) {
    //
}

if ($response->isFailure()) {
    //
}

// To dump all payment details.
dd($response);

生产环境

要在生产模式下使用此包,只需将config/urway.php文件中的mode值更新为production