SergioMadness / payment-laravel by SergioMadness

Payment drivers for laravel
8,760
14
4
Package Data
Maintainer Username: SergioMadness
Maintainer Contact: zinchenko@web-development.pw (Zinchenko Sergey)
Package Create Date: 2016-10-19
Package Last Update: 2023-04-28
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-04-27 03:04:22
Package Statistics
Total Downloads: 8,760
Monthly Downloads: 22
Daily Downloads: 0
Total Stars: 14
Total Watchers: 4
Total Forks: 6
Total Open Issues: 2

Payment provider for Laravel

Latest Stable Version Code Climate Dependency Status License Latest Unstable Version

Project structure

contracts/          Abstractions
facades/            Payment facade

Requirements

  • PHP 5.5+

Dependencies

Installation

Module is available through composer

composer require professionalweb/payment-laravel "dev-master"

Alternatively you can add the following to the require section in your composer.json manually:

"professionalweb/payment-laravel": "^2.2"

Run composer update afterwards.

Initialization

##config/app.php

<?php
return [
    'providers' => [
        ...
        \professionalweb\payment\PaymentProvider::class,
        ...
    ],
];

If you need only one specific payment provider:

PayOnline:

return [
    'providers' => [
        ...
        \professionalweb\payment\PayOnlineProvider::class,
        ...
    ],
];

Tinkoff:

return [
    'providers' => [
        ...
        \professionalweb\payment\TinkoffProvider::class,
        ...
    ],
];

Yandex.Kassa:

return [
    'providers' => [
        ...
        \professionalweb\payment\YandexProvider::class,
        ...
    ],
];

##config/payment.php

<?php
return [
    'default_driver' => env('DEFAULT_PAYMENT_SYSTEM', \professionalweb\payment\PaymentProvider::PAYMENT_TINKOFF),
    'tinkoff'        => [
        'merchantId' => env('TINKOFF_MERCHANT_ID'),
        'secretKey'  => env('TINKOFF_SECRET_KEY'),
        'successURL' => env('TINKOFF_SUCCESS_URL', '/'),
        'failURL'    => env('TINKOFF_FAIL_URL', '/'),
        'apiUrl'     => env('TINKOFF_API_URL', 'https://securepay.tinkoff.ru/rest/'),
    ],
    'payonline'      => [
        'merchantId' => env('PAYONLINE_MERCHANT_ID'),
        'secretKey'  => env('PAYONLINE_SECRET_KEY'),
        'successURL' => env('PAYONLINE_SUCCESS_URL', '/'),
        'failURL'    => env('PAYONLINE_FAIL_URL', '/'),
    ],
    'yandex'      => [
        'merchantId' => env('YANDEX_SHOP_ID'),
        'scid'       => env('YANDEX_SCID'),
        'secretKey'  => env('YANDEX_SECRET_KEY'),
        'successURL' => env('YANDEX_SUCCESS_URL', '/'),
        'failURL'    => env('YANDEX_FAIL_URL', '/'),
        'isTest'     => false,
    ],
];

Using

At first user must be redirected to payment system page:

<?php

public function action(PayService $paymentService) {
    redirect()->to(
        $paymentService->getPaymentLink($order->id,
            $payment->id,
            $payment->amount,
            $payment->currency,
            $successfulPaymentReturnUrl, //Tinkoff doesn't need it
            $failedPaymentReturnUrl, //Tinkoff doesn't need it
            $description
        );
    );
}

Then you need to handle async response:

<?php

public function responseHandler(PayService $paymentService) {
    if($paymentService->setResponse($this->getRequest()->all())->isSuccess()) {
        $orderId = $paymentService->getOrderId();
        $status = $paymentService->getStatus();
        $amount = $paymentService->getAmount();
        $errorCode = $paymentService->getErrorCode();
        $pan = $paymentService->getPan();
        $paymentDate = $paymentService->getDateTime();
        $transactionId = $paymentService->getTransactionId();
        $provider = $service->getProvider();

        // Update order, payment record, etc...
    } else {
        // something else
    }
}

Receipts

To send receipt to IRS

/**
 * Prepare Receipt
 *
 * @param Order $order
 *
 * @return Receipt
 */
public function prepareReceipt(Order $order)
{
    $receipt = new Receipt($order->user->email);
    /** @var Item $item */
    foreach ($order->items as $item) {
        $receipt->addItem(new ReceiptItem($item->name, $item->qty, $item->price, config('payment.tax')));
    }

    return $receipt;
}

PayOnline has separate service to send register receipts and send to users.

use professionalweb\payment\contracts\ReceiptService;

$receipt = new Receipt($order->user->email);
$receipt->setTransactionId($transactionIdFromPayOnlineResponse);
/** @var Item $item */
foreach ($order->items as $item) {
    $receipt->addItem(new ReceiptItem($item->name, $item->qty, $item->price, config('payment.tax')));
}

app(ReceiptService::class)->sendReceipt(
    $this->prepareReceipt()
);

The MIT License (MIT)

Copyright (c) 2016 Sergey Zinchenko, Professional web

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.