Skip to content

Commit 15d4d2b

Browse files
committed
1.6.4
1 parent 152da70 commit 15d4d2b

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
Офф. документация:
6363
-
6464
* https://securepayments.sberbank.ru/wiki/doku.php/integration:api:rest:requests:register_cart#items
65-
* https://developer.sberbank.ru/doc/v1/acquiring/api-basket
6665
6766
Тестовые карты:
6867
-

Sberbank.php

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ public function checkout_form($order_id, $button_text = null)
212212
echo '<h3>Текущий заказ в БД:</h3>';
213213
var_dump($this->order);
214214
echo '<h3>Корзина для ФЗ-54:</h3>';
215+
var_dump($orderBundle);
215216
var_dump(json_decode($orderBundle));
216217
print '</pre>';
217218
}
@@ -255,9 +256,11 @@ private function normalize($purchases)
255256
$discount_sum = ($items_total_price * $this->order->discount) / 100;
256257

257258
foreach ($purchases as $key => $item) {
258-
$coefficient = ($item->amount * $item->price) * 100 / $items_total_price;
259-
$coefficient_discount = round((($discount_sum * $coefficient) / 100) / $item->amount, 2);
260-
$corrected_purchases[$key] -= $coefficient_discount;
259+
$corrected_purchases[$key] -= $this->coefficient_price($item->amount, $item->price, $discount_sum, $items_total_price);
260+
261+
if ($this->debug) {
262+
echo 'Цена за item с учетом процентной скидки: ' . $corrected_purchases[$key] . '<br>';
263+
}
261264
}
262265
}
263266

@@ -268,9 +271,11 @@ private function normalize($purchases)
268271
if ($this->order->coupon_discount > 0) {
269272
foreach ($purchases as $key => $item) {
270273
// Вычислим процентное соотношение item price * amount от общей суммы заказа
271-
$coefficient = ($item->amount * $item->price) * 100 / $items_total_price;
272-
$coefficient_discount = round((($this->order->coupon_discount) * $coefficient) / 100 / $item->amount, 2);
273-
$corrected_purchases[$key] -= $coefficient_discount;
274+
$corrected_purchases[$key] -= $this->coefficient_price($item->amount, $item->price, $this->order->coupon_discount, $items_total_price);
275+
276+
if ($this->debug) {
277+
echo 'Цена за item с учетом скидки по купону: ' . $corrected_purchases[$key] . '<br>';
278+
}
274279
}
275280
}
276281

@@ -281,9 +286,11 @@ private function normalize($purchases)
281286
*/
282287
if ($this->payment_settings['sbr_delivery'] == 'include_item' AND !$this->order->separate_delivery) {
283288
foreach ($purchases as $key => $item) {
284-
$coefficient = ($item->amount * $item->price) * 100 / $items_total_price;
285-
$coefficient_delivery = round(($this->order->delivery_price * $coefficient) / 100 / $item->amount, 2);
286-
$corrected_purchases[$key] += $coefficient_delivery;
289+
$corrected_purchases[$key] += $this->coefficient_price($item->amount, $item->price, $this->order->delivery_price, $items_total_price);
290+
291+
if ($this->debug) {
292+
echo 'Цена за item с учетом доставки: ' . $corrected_purchases[$key] . '<br>';
293+
}
287294
}
288295
}
289296

@@ -298,6 +305,12 @@ private function normalize($purchases)
298305
$all_sum += $item->price * $item->amount;
299306
}
300307

308+
// Если доставка как отдельная позиция
309+
if($this->payment_settings['sbr_delivery'] == 'item' && $this->order->delivery_price && $this->order->delivery_price > 0 && !$this->order->separate_delivery) {
310+
$all_sum += $this->order->delivery_price;
311+
}
312+
313+
// Корректируем
301314
if ($this->order->total_price != $all_sum) {
302315
$all_sum_diff = $this->order->total_price - $all_sum;
303316
$all_sum_diff = round($all_sum_diff, 2);
@@ -364,6 +377,20 @@ private function normalize($purchases)
364377
private function convert_price($price)
365378
{
366379
// return $this->money->convert($price, $this->payment_method->currency_id, false) * 100;
367-
return $result = round($price, 2) * 100;
380+
return round($price, 2) * 100;
381+
}
382+
383+
/**
384+
* Считаем коэффициент
385+
*
386+
* @param $item_amount
387+
* @param $item_price
388+
* @param $sum
389+
* @param $items_total_price
390+
* @return false|float
391+
*/
392+
private function coefficient_price($item_amount, $item_price, $sum, $items_total_price) {
393+
$coefficient = ($item_amount * $item_price) * 100 / $items_total_price;
394+
return ceil(round((($sum * $coefficient) / 100) / $item_amount, 2));
368395
}
369396
}

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
v 1.6.4 - 05.06.2020
2+
* (bugfix) - Фикс ошибки `Несоответствие между [orderBundle.cartItems.item.itemPrice] и [orderBundle.cartItems.item.itemAmount]`. Пофиксил через ceil валюты.
3+
* (upd) - частичный рефакторинг
4+
* (bugfix) - Если доставка была отдельной позицией в чеке, заказ не продолжался
5+
16
v 1.6.3 - 29.04.2020
27
* (add) Добавлена опция `sbr_order_status`. В неё нужно устанавливать статус заказа, если вы хотите что бы после оплаты у заказа менялся статус.
38
* (add) Добавлена опция `sbr_css_checkout_button`. Создана для установки css классов на кнопку `checkout_button` "перейти к оплате".

settings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<module>
33
<name>
4-
Сбербанк Эквайринг v1.6.3
4+
Сбербанк Эквайринг v 1.6.4
55
</name>
66
<settings>
77
<variable>sbr_login</variable>

0 commit comments

Comments
 (0)