Skip to content

Commit

Permalink
Merge pull request #32 from Mul-tiMedia/mollie-chargeback-amount
Browse files Browse the repository at this point in the history
Resolved problem with ChargebackReceived dispatching
  • Loading branch information
sandervanhooft authored Dec 16, 2021
2 parents 1dd0b88 + 2c9b2db commit 1b90e97
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Http/Controllers/AftercareWebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,18 @@ public function handleWebhook(Request $request)
if ($molliePayment && $molliePayment->hasChargebacks()) {
$localPayment = Payment::findByPaymentId($molliePayment->id);

if ($localPayment->amount_charged_back < mollie_object_to_money($molliePayment->amountChargedBack)->getAmount()) {
$localPayment->amount_charged_back = mollie_object_to_money($molliePayment->amountChargedBack)->getAmount();
$molliePaymentAmountChargedBackTotal = mollie_object_to_money($molliePayment->amountChargedBack);
$locallyKnownAmountChargedBack = $localPayment->getAmountChargedBack();

if ($locallyKnownAmountChargedBack->lessThan($molliePaymentAmountChargedBackTotal)) {
$localPayment->amount_charged_back = (int) $molliePaymentAmountChargedBackTotal->getAmount();
$localPayment->save();

Event::dispatch(new ChargebackReceived($localPayment, $molliePayment->amountChargedBack - $localPayment->amount_charged_back));
$amountChargedBackNow = $molliePaymentAmountChargedBackTotal->subtract(
$locallyKnownAmountChargedBack
);

Event::dispatch(new ChargebackReceived($localPayment, $amountChargedBackNow));
}
}

Expand Down

0 comments on commit 1b90e97

Please sign in to comment.