Skip to content

Commit 3ae382d

Browse files
committed
new refund-by-product
1 parent fe38c37 commit 3ae382d

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

src/Refund.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class Refund implements RefundInterface, JsonSerializable, TransactionInterface
3232
/** @var MarketplaceSubmerchant[] */
3333
private array $marketplaceSubmerchants = [];
3434

35+
/** @var Product[] Массив продуктов */
36+
private array $products;
37+
38+
private bool $skipCheckSkuAmount = false;
39+
3540
/**
3641
* @inheritDoc
3742
*/
@@ -129,6 +134,53 @@ public function getCurrency(): string
129134
return $this->currency;
130135
}
131136

137+
/**
138+
* @return bool
139+
*/
140+
public function isSkipCheckSkuAmount(): bool
141+
{
142+
return $this->skipCheckSkuAmount;
143+
}
144+
145+
/**
146+
* @param bool $skipCheckSkuAmount
147+
*/
148+
public function setSkipCheckSkuAmount(bool $skipCheckSkuAmount): self
149+
{
150+
$this->skipCheckSkuAmount = $skipCheckSkuAmount;
151+
152+
return $this;
153+
}
154+
155+
/** @inheritDoc */
156+
public function addProduct(ProductInterface $product) : self
157+
{
158+
$this->products[] = $product;
159+
160+
return $this;
161+
}
162+
163+
/** @inheritDoc */
164+
public function getProducts(): array
165+
{
166+
return $this->products;
167+
}
168+
169+
/** @inheritDoc */
170+
public function getProductsArray(): array
171+
{
172+
$productsArray = [];
173+
foreach ($this->getProducts() as $product) {
174+
$productsArray[] = [
175+
'sku' => $product->getSku(),
176+
'quantity' => $product->getQuantity(),
177+
'amount' => $product->getAmount(),
178+
];
179+
}
180+
181+
return $productsArray;
182+
}
183+
132184
/**
133185
* @inheritDoc
134186
* @throws PaymentException
@@ -154,6 +206,14 @@ public function jsonSerialize()
154206
'currency' => $this->getCurrency()
155207
];
156208

209+
if ($this->skipCheckSkuAmount) {
210+
$requestData ['skipCheckSkuAmount'] = true;
211+
}
212+
213+
if (count($this->products) > 0) {
214+
$requestData['products'] = $this->getProductsArray();
215+
}
216+
157217
if (count($this->marketplaceSubmerchants) > 0) {
158218
foreach ($this->marketplaceSubmerchants as $marketplaceSubmerchant) {
159219
$requestData['marketplaceV1'][] = (object) [

0 commit comments

Comments
 (0)