yorki/laravel-payu

Laravel的PayU客户端

v1.0 2018-05-23 15:32 UTC

This package is auto-updated.

Last update: 2024-09-26 01:55:50 UTC


README

PayU服务的REST API的Laravel实现

composer require yorki/laravel-payu

发布配置

php artian vendor:publish --provider="Yorki\Payu\ServiceProvider"

我们控制器中实现的示例

<?php
//$client is instance of Client
$orderRequest = $client->getNewOrderRequest();
$orderRequest->setCurrencyCode(NewOrder::CURRENCY_PLN)
    ->setExtOrderId(123456)
    ->setTotalAmount(10000)
    ->setDescription('Premium')
    ->setCustomerIp($request->getClientIp());

//Lets get instance of NewOrder request and fill it up
$product = $orderRequest->getProducts()->create();
$product->setName('Konto premium')
    ->setQuantity(1)
    ->setUnitPrice(10000);

//Send our request and get response object
$response = $orderRequest->send();

//Check if we are fine
if ($response->isSuccess()) {
    //We should redirect to payment gateway
    redirect($response->getRedirectUri());
} else {
    //Something went wrong
    echo 'Error: ' . $response->getStatus()->getStatusCode();
}

我们通知端点的实现示例

<?php
$notification = $client->getNotification();
//Get external order Id and find in database
$notification->getOrder()->getExtOrderId();
//Check status
if ($notification->getOrder()->getStatus() === Yorki\Payu\Notifications\Schema\Order::STATUS_COMPLETED) {
    //you can extract buyer info from order
    $buyer = $notification->getOrder()->getBuyer();
    $buyerEmail = $buyer->getEmail();
    $buyerWholeData = $buyer->toArray();
}

通知路由的示例

<?php
//api.php
Route::group([
    'prefix' => 'payu',
], function () {
    $this->post('notification', 'PayuController@notification');
});