Skip to content

Commit

Permalink
Улучшено форматирование чисел, уменьшена зависимость от illuminate/su…
Browse files Browse the repository at this point in the history
…pport, cs
  • Loading branch information
jhaoda committed Sep 12, 2017
1 parent c3deda0 commit 22309aa
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Contracts/YaKassaOrder54FZ.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface YaKassaOrder54FZ extends YaKassaOrder
/**
* Товары/услуги в чеке.
*
* @return iterable массив/итератор/генератор объектов YaKassaOrderItem54FZ
* @return iterable массив/итератор/генератор объектов YaKassaOrderItem54FZ
*/
public function getItems(): iterable;

Expand Down
9 changes: 4 additions & 5 deletions src/YaKassa.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Appwilio\YaKassa;

use Illuminate\Support\Arr;
use Illuminate\Http\Response;
use Appwilio\YaKassa\Contracts\YaKassaOrder;

Expand Down Expand Up @@ -49,7 +48,7 @@ class YaKassa
'orderSumBankPaycash',
'shopId',
'invoiceId',
'customerNumber'
'customerNumber',
];

/** @var bool */
Expand Down Expand Up @@ -93,7 +92,7 @@ public function verify(): bool
return false;
}

$source = Arr::only($this->request->all(), self::$significantFields);
$source = array_intersect_key($this->request->all(), array_flip(self::$significantFields));

$source['shopId'] = $this->shopId;
$source['orderSumAmount'] = $this->genuineAmount;
Expand Down Expand Up @@ -136,14 +135,14 @@ public function buildPaymentForm(YaKassaOrder $order): YaKassaPaymentForm

private function buildResponse(int $code): Response
{
$content = '<?xml version="1.0" encoding="UTF-8"?>';
$content = '<?xml version="1.0" encoding="UTF-8"?>';

$content .= vsprintf('<%sResponse performedDatetime="%s" code="%d" invoiceId="%d" shopId="%d" />', [
$this->request->getAction(),
date(\DateTime::RFC3339),
$code,
$this->request->getInvoiceId(),
$this->shopId
$this->shopId,
]);

return new Response($content, Response::HTTP_OK, ['Content-Type' => 'application/xml']);
Expand Down
17 changes: 12 additions & 5 deletions src/YaKassaPaymentForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Appwilio\YaKassa;

use Illuminate\Support\Str;
use Appwilio\YaKassa\Contracts\YaKassaOrder;
use Appwilio\YaKassa\Contracts\YaKassaOrder54FZ;
use Appwilio\YaKassa\Contracts\YaKassaOrderItem54FZ;
Expand Down Expand Up @@ -73,7 +72,7 @@ public function getPaymentUrl(): string

public function toArray(): array
{
$this->setParameter('sum', $this->order->getOrderSum());
$this->setParameter('sum', number_format($this->order->getOrderSum(), 2, '.', ''));
$this->setParameter('orderNumber', $this->order->getOrderNumber());
$this->setParameter('customerNumber', $this->order->getCustomerNumber());

Expand All @@ -85,7 +84,10 @@ public function toArray(): array
}

if ($this->order instanceof YaKassaOrder54FZ) {
$this->setParameter('ym_merchant_receipt', json_encode($this->getMerchantReceipt($this->order)));
$this->setParameter('ym_merchant_receipt', json_encode(
$this->getMerchantReceipt($this->order),
JSON_UNESCAPED_UNICODE
));
}

return array_filter($this->parameters);
Expand Down Expand Up @@ -120,10 +122,15 @@ private function convertItemToArray(YaKassaOrderItem54FZ $item): array
'price' => [
'amount' => number_format($item->getAmount(), 2, '.', '')
],
'text' => Str::substr($item->getTitle(), 0, 127),
'text' => mb_substr($item->getTitle(), 0, 127, 'UTF-8'),
'tax' => $item->getTaxRate(),
'quantity' => number_format($item->getQuantity(), 3, '.', ''),
'quantity' => $this->formatQuantity($item->getQuantity()),
'currency' => $item->getCurrency(),
]);
}

private function formatQuantity($quantity)
{
return is_int($quantity) ? $quantity : (float) number_format($quantity, 3, '.', '');
}
}
4 changes: 4 additions & 0 deletions src/YaKassaServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
namespace Appwilio\YaKassa;

use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\Foundation\Application;

class YaKassaServiceProvider extends ServiceProvider
{
/** @var Application */
protected $app;

protected $defer = true;

public function register(): void
Expand Down

0 comments on commit 22309aa

Please sign in to comment.