Changeset View
Changeset View
Standalone View
Standalone View
src/app/Providers/PaymentProvider.php
Show First 20 Lines • Show All 229 Lines • ▼ Show 20 Lines | protected function storeRefund(Wallet $wallet, array $refund): void | ||||
// Preserve originally refunded amount | // Preserve originally refunded amount | ||||
$refund['currency_amount'] = $refund['amount'] * -1; | $refund['currency_amount'] = $refund['amount'] * -1; | ||||
// Convert amount to wallet currency | // Convert amount to wallet currency | ||||
// TODO We should possibly be using the same exchange rate as for the original payment? | // TODO We should possibly be using the same exchange rate as for the original payment? | ||||
$amount = $this->exchange($refund['amount'], $refund['currency'], $wallet->currency); | $amount = $this->exchange($refund['amount'], $refund['currency'], $wallet->currency); | ||||
$wallet->balance -= $amount; | $method = $refund['type'] == self::TYPE_CHARGEBACK ? 'chargeback' : 'refund'; | ||||
$wallet->save(); | |||||
if ($refund['type'] == self::TYPE_CHARGEBACK) { | $wallet->{$method}($amount, $refund['description'] ?? ''); | ||||
mollekopf: Rather call the actual method instead of assembling a string that is then invoked as a method… | |||||
$transaction_type = Transaction::WALLET_CHARGEBACK; | |||||
} else { | |||||
$transaction_type = Transaction::WALLET_REFUND; | |||||
} | |||||
Transaction::create([ | |||||
'object_id' => $wallet->id, | |||||
'object_type' => Wallet::class, | |||||
'type' => $transaction_type, | |||||
'amount' => $amount * -1, | |||||
'description' => $refund['description'] ?? '', | |||||
]); | |||||
$refund['status'] = self::STATUS_PAID; | $refund['status'] = self::STATUS_PAID; | ||||
$refund['amount'] = -1 * $amount; | $refund['amount'] = -1 * $amount; | ||||
// FIXME: Refunds/chargebacks are out of the reseller comissioning for now | // FIXME: Refunds/chargebacks are out of the reseller comissioning for now | ||||
$this->storePayment($refund, $wallet->id); | $this->storePayment($refund, $wallet->id); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 137 Lines • Show Last 20 Lines |
Rather call the actual method instead of assembling a string that is then invoked as a method, IMO.