Package Data | |
---|---|
Maintainer Username: | jhaoda |
Maintainer Contact: | jhaoda@gmail.com (JhaoDa) |
Package Create Date: | 2017-05-28 |
Package Last Update: | 2022-05-18 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-22 03:15:36 |
Package Statistics | |
---|---|
Total Downloads: | 3,419 |
Monthly Downloads: | 18 |
Daily Downloads: | 0 |
Total Stars: | 37 |
Total Watchers: | 11 |
Total Forks: | 6 |
Total Open Issues: | 2 |
Ранняя альфа, использовать осторожно!
Возможности:
checkOrder
и paymentAviso
.Требования:
composer require appwilio/yakassa
Подключение сервис-провайдера:
// config/app.php
'providers' => [
...
Appwilio\YaKassa\YaKassaServiceProvider::class,
],
Настройки:
// config/services.php
...
'yakassa' => [
'test_mode' => env('YAKASSA_TEST_MODE', true),
'shop_id' => env('YAKASSA_SHOP_ID', ''),
'showcase_id' => env('YAKASSA_SHOWCASE_ID', ''),
'shop_password' => env('YAKASSA_SHOP_PASSWORD', ''),
],
...
Заказ должен имплементировать интерфейс \Appwilio\YaKassa\Contracts\YaKassaOrder
:
use Appwilio\YaKassa\Contracts\YaKassaOrder;
class Order implements YaKassaOrder
{
public function getOrderSum(): float
{
return $this->total;
}
public function getCustomerNumber(): string
{
return $this->customer->id;
}
public function getOrderNumber(): ?string
{
return $this->id;
}
public function getPaymentType(): ?string
{
return 'PC';
}
public function getCustomerEmail(): ?string
{
return $this->customer->email;
}
public function getCustomerPhone(): ?string
{
return $this->customer->phone;
}
}
Внимание! Протокол дополняется, текущая версия 2.1. Общая информация, описание изменений.
Заказ должен имплементировать интерфейс \Appwilio\YaKassa\Contracts\YaKassaOrder54FZ
:
use Appwilio\YaKassa\Contracts\YaKassaOrder54FZ;
class Order implements YaKassaOrder54FZ
{
public function getOrderSum(): float
{
return $this->total;
}
public function getCustomerNumber(): string
{
return $this->customer->id;
}
public function getItems(): iterable
{
return $this->items; // товары/услуги в заказе
}
public function getTaxSystem(): ?int
{
return YaKassaOrder54FZ::TAX_OSN;
}
public function getCustomerContact(): string
{
return $this->customer->phone;
}
public function getOrderNumber(): ?string
{
return $this->id;
}
public function getPaymentType(): ?string
{
return 'PC';
}
public function getCustomerEmail(): ?string
{
return $this->customer->email;
}
public function getCustomerPhone(): ?string
{
return $this->customer->phone;
}
}
Каждая позиция заказа должна имплементировать интерфейс \Appwilio\YaKassa\Contracts\YaKassaOrderItem54FZ
:
use Appwilio\YaKassa\Contracts\YaKassaOrderItem54FZ;
class OrderItem implements YaKassaOrderItem54FZ
{
public function getAmount(): float
{
return $this->amount;
}
public function getQuantity(): float
{
return $this->quantity;
}
public function getTaxRate(): int
{
return YaKassaOrderItem54FZ::VAT_18;
}
public function getCurrency(): ?string
{
return null; // равнозначно RUB
}
public function getTitle(): string
{
return $this->product->title;
}
}
В контролллере:
use Appwilio\YaKassa\YaKassa;
class OrdersController
{
public function showPaymentForm(YaKassa $kassa, $orderId)
{
$order = Order::find($orderId);
$paymentForm = $kassa->buildPaymentForm($order);
return view('payment', ['form' => $paymentForm]);
}
}
В шаблоне:
<form method="POST" action="{{ $form->getPaymentUrl() }}">
@foreach ($form->toArray() as $k => $v)
<input type="hidden" name="{{ $k }}" value="{{ $v }}" />
@endforeach
...
</form>
use Appwilio\YaKassa\YaKassa;
class YaHookController extends Controller
{
public function checkOrder(YaKassa $kassa)
{
$order = Order::find($kassa->getRequest()->getOrderNumber());
if (! $order) {
return $kassa->responseDeclined();
}
// используем реальное значение суммы заказа, а не присланное Я.Кассой
$kassa->setGenuineOrderSumAmount($order->total);
if (! $kassa->verify()) {
return $kassa->responseUnauthorized();
}
return $kassa->responseAccepted();
}
}