Skip to content

Commit

Permalink
Merge pull request #94 from rarus/task#67375-fix-money-currency
Browse files Browse the repository at this point in the history
fix: passing currency string
  • Loading branch information
artsapiens authored Feb 19, 2025
2 parents 33d342f + 4dbf017 commit 1ae0a75
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 23 deletions.
12 changes: 6 additions & 6 deletions src/Rarus/BonusServer/Cards/DTO/Balance/Fabric.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public static function initFromServerResponse(Currency $currency, array $arBalan
$moneyParser = new DecimalMoneyParser(new ISOCurrencies());

return (new Balance())
->setAvailable($moneyParser->parse((string)$arBalanceInfo['balance_available'], $currency->getCode()))
->setTotal($moneyParser->parse((string)$arBalanceInfo['balance'], $currency->getCode()));
->setAvailable($moneyParser->parse((string)$arBalanceInfo['balance_available'], $currency))
->setTotal($moneyParser->parse((string)$arBalanceInfo['balance'], $currency));
}

/**
Expand All @@ -49,9 +49,9 @@ public static function initPaymentBalanceFromServerResponse(Currency $currency,

$paymentBalance
->setCardLevelId(new LevelId((string)$arPaymentBalance['card_level_id']))
->setAvailableBalance($moneyParser->parse((string)$arPaymentBalance['balance_available'], $currency->getCode()));
->setAvailableBalance($moneyParser->parse((string)$arPaymentBalance['balance_available'], $currency));

$paymentBalance->setPaymentBalance($moneyParser->parse((string)$arPaymentBalance['max_payment'], $currency->getCode()));
$paymentBalance->setPaymentBalance($moneyParser->parse((string)$arPaymentBalance['max_payment'], $currency));

if ($arPaymentBalance['master_card_id'] !== '') {
$paymentBalance->setMastercardId(new Cards\DTO\CardId((string)$arPaymentBalance['master_card_id']));
Expand All @@ -74,10 +74,10 @@ public static function initPaymentBalanceFromServerResponse(Currency $currency,
$paymentDistribution = new Cards\DTO\PaymentDistribution\PaymentDistribution(
$item['line_number'],
new ArticleId($item['article']),
$moneyParser->parse((string)$item['summ'], $currency->getCode()),
$moneyParser->parse((string)$item['summ'], $currency),
(float)$item['max_payment_percent'],
(float)$item['max_payment_sum'],
$moneyParser->parse((string)$item['payment_sum'], $currency->getCode())
$moneyParser->parse((string)$item['payment_sum'], $currency)
);
$paymentDistributionCollection->attach($paymentDistribution);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rarus/BonusServer/Cards/DTO/Fabric.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function initCardFromServerResponse(array $arCard, \Money\Currency
$card->setCardLevelId(new LevelId((string)$arCard['card_level_id']));
}
if (key_exists('accum_sale_amount', $arCard)) {
$card->setAccumSaleAmount($moneyParser->parse((string)$arCard['accum_sale_amount'], $currency->getCode()));
$card->setAccumSaleAmount($moneyParser->parse((string)$arCard['accum_sale_amount'], $currency));
}
if (key_exists('date_last_transaction', $arCard) && $arCard['date_last_transaction'] !== 0) {
$card->setDateLastTransaction(DateTimeParser::parseTimestampFromServerResponse((string)$arCard['date_last_transaction'], $dateTimeZone));
Expand Down
6 changes: 3 additions & 3 deletions src/Rarus/BonusServer/Cards/DTO/Level/Fabric.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function initFromServerResponse(array $arLevel, Currency $currency
->setLevelId(new LevelId((string)$arLevel['id']))
->setName((string)$arLevel['name'])
->setOrder((int)$arLevel['order'])
->setAccumulationAmountToNextLevel($moneyParser->parse((string)$arLevel['accum_level'], $currency->getCode()))
->setAccumulationAmountToNextLevel($moneyParser->parse((string)$arLevel['accum_level'], $currency))
->setResetAccumulationSumWhenUpgradeLevel((bool)$arLevel['reset_card_accum'])
->setMaxPaymentPercent((int)$arLevel['max_payment_percent'])
->setRestrictionRule(new RestrictionRule(
Expand All @@ -53,7 +53,7 @@ public static function initLevelDescriptionFromServerResponse(array $arLevelDesc
return (new LevelDescription())
->setLevelId(new LevelId($arLevelDescription['level_id']))
->setName($arLevelDescription['level_name'])
->setLevelUpAccumulationSum($moneyParser->parse((string)$arLevelDescription['accum_level'], $currency->getCode()))
->setCardAccumulationSum($moneyParser->parse((string)$arLevelDescription['accum_amount'], $currency->getCode()));
->setLevelUpAccumulationSum($moneyParser->parse((string)$arLevelDescription['accum_level'], $currency))
->setCardAccumulationSum($moneyParser->parse((string)$arLevelDescription['accum_amount'], $currency));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static function initFromServerResponse(Currency $currency, array $arTrans
$moneyParser = new DecimalMoneyParser(new ISOCurrencies());

return (new TransactionAmount())
->setTransactionSum($moneyParser->parse((string)$arTransactionAmount['sum'], $currency->getCode()))
->setTransactionSum($moneyParser->parse((string)$arTransactionAmount['sum'], $currency))
->setDate(DateTimeParser::parseTimestampFromServerResponse((string)$arTransactionAmount['date'], $dateTimeZone));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function initFromServerResponse(Currency $currency, array $discoun
->setLineNumber((int)$discountItem['line_number'])
->setDiscountId(new DiscountId((string)$discountItem['discount_id']))
->setTypeId((int)$discountItem['discount_type'])
->setSum($moneyParser->parse((string)$discountItem['discount_summ'], $currency->getCode()))
->setSum($moneyParser->parse((string)$discountItem['discount_summ'], $currency))
->setName((string)$discountItem['discount_name'])
->setValue((int)$discountItem['discount_value']);

Expand Down
6 changes: 3 additions & 3 deletions src/Rarus/BonusServer/Transactions/DTO/FinalScore/Fabric.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public static function initFinalScoreFromServerResponse(Currency $currency, arra
$moneyParser = new DecimalMoneyParser($currencies);

$score
->setBonusEarned($moneyParser->parse((string)$arResponse['bonus_earned'], $currency->getCode()))
->setBonusSpent($moneyParser->parse((string)$arResponse['bonus_spent'], $currency->getCode()))
->setBonusEarned($moneyParser->parse((string)$arResponse['bonus_earned'], $currency))
->setBonusSpent($moneyParser->parse((string)$arResponse['bonus_spent'], $currency))
->setSaleId((string)$arResponse['sale_id'])
->setDocId((string)$arResponse['doc_id'])
->setCardAccumulationAmount($moneyParser->parse((string)$arResponse['card_accum'], $currency->getCode()));
->setCardAccumulationAmount($moneyParser->parse((string)$arResponse['card_accum'], $currency));

return $score;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rarus/BonusServer/Transactions/DTO/Points/Fabric.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function initPointFromServerResponse(Currency $currency, array $ar

$point = new Point();
$point
->setSum($moneyParser->parse((string)$arPoint['sum'], $currency->getCode()))
->setSum($moneyParser->parse((string)$arPoint['sum'], $currency))
->setDateCreate(DateTimeParser::parseTimestampFromServerResponse((string)$arPoint['date'], $dateTimeZone));

if ($arPoint['active_from'] !== 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static function initPointTransactionFromServerResponse(Currency $currency
->setCardId(new CardId((string)$arPointTransaction['card_id']))
->setMastercardId(new CardId((string)$arPointTransaction['mastercard_id']))
->setTime(DateTimeParser::parseTimestampFromServerResponse((string)$arPointTransaction['time'], $dateTimeZone))
->setSum($moneyParser->parse((string)$arPointTransaction['sum'], $currency->getCode()))
->setSum($moneyParser->parse((string)$arPointTransaction['sum'], $currency))
->setType($arPointTransaction['type'] === 0 ? Type\Fabric::getRefund() : Type\Fabric::getSale())
->setAuthor((string)$arPointTransaction['author'])
->setDescription((string)$arPointTransaction['description'])
Expand Down
4 changes: 2 additions & 2 deletions src/Rarus/BonusServer/Transactions/DTO/Products/Fabric.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public static function initProductRowFromServerResponse(Currency $currency, arra
->setArticleId(new ArticleId((string)$arResponse['article_id']))
->setName((string)$arResponse['item_name'])
->setQuantity((int)$arResponse['quantity'])
->setPrice($moneyParser->parse((string)$arResponse['price'], $currency->getCode()))
->setDiscount($moneyParser->parse((string)$arResponse['discount'], $currency->getCode()));
->setPrice($moneyParser->parse((string)$arResponse['price'], $currency))
->setDiscount($moneyParser->parse((string)$arResponse['discount'], $currency));

return $productRow;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public static function initHistoryItemFromServerResponse(Currency $currency, arr
->setShopId(new ShopId((string)$arResponse['shop_id']))
->setCashRegisterId(new CashRegisterId((string)$arResponse['cashbox_id']))
->setChequeId(new ChequeId((string)$arResponse['check_number']))
->setSum($moneyParser->parse((string)$arResponse['summ'], $currency->getCode()))
->setSumWithDiscount($moneyParser->parse((string)$arResponse['summ_with_discount'], $currency->getCode()))
->setSum($moneyParser->parse((string)$arResponse['summ'], $currency))
->setSumWithDiscount($moneyParser->parse((string)$arResponse['summ_with_discount'], $currency))
->setBonusEarned((float)$arResponse['bonus_earned'])
->setBonusSpent((float)$arResponse['bonus_spent'])
->setType(Transactions\DTO\Type\Fabric::initFromServerResponse((string)$arResponse['operation']))
Expand Down
5 changes: 3 additions & 2 deletions src/Rarus/BonusServer/Users/DTO/Fabric.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ public static function createNewInstance(string $login, string $name, string $ph
if ($userId !== null) {
$user->setUserId($userId);
}
if ($status !== null) {
$user->setStatus($status);
if ($status === null) {
$status = Users\DTO\Status\Fabric::initDefaultStatusForNewUser();
}
$user->setStatus($status);

return $user;
}
Expand Down

0 comments on commit 1ae0a75

Please sign in to comment.