Changeset View
Changeset View
Standalone View
Standalone View
src/app/Providers/Payment/Mollie.php
Show First 20 Lines • Show All 220 Lines • ▼ Show 20 Lines | public function payment(Wallet $wallet, array $payment): ?array | ||||
// Create the payment in Mollie | // Create the payment in Mollie | ||||
$response = mollie()->payments()->create($request); | $response = mollie()->payments()->create($request); | ||||
// Store the payment reference in database | // Store the payment reference in database | ||||
$payment['status'] = $response->status; | $payment['status'] = $response->status; | ||||
$payment['id'] = $response->id; | $payment['id'] = $response->id; | ||||
self::storePayment($payment, $wallet->id); | $this->storePayment($payment, $wallet->id); | ||||
return [ | return [ | ||||
'id' => $payment['id'], | 'id' => $payment['id'], | ||||
'redirectUrl' => $response->getCheckoutUrl(), | 'redirectUrl' => $response->getCheckoutUrl(), | ||||
]; | ]; | ||||
} | } | ||||
/** | /** | ||||
* Update payment status (and balance). | * Update payment status (and balance). | ||||
* | * | ||||
* @return int HTTP response code | * @return int HTTP response code | ||||
vanmeeuwen: Typo. | |||||
*/ | */ | ||||
public function webhook(): int | public function webhook(): int | ||||
{ | { | ||||
$payment_id = \request()->input('id'); | $payment_id = \request()->input('id'); | ||||
if (empty($payment_id)) { | if (empty($payment_id)) { | ||||
return 200; | return 200; | ||||
} | } | ||||
Show All 14 Lines | public function webhook(): int | ||||
} | } | ||||
if ($mollie_payment->isPaid()) { | if ($mollie_payment->isPaid()) { | ||||
if (!$mollie_payment->hasRefunds() && !$mollie_payment->hasChargebacks()) { | if (!$mollie_payment->hasRefunds() && !$mollie_payment->hasChargebacks()) { | ||||
// The payment is paid and isn't refunded or charged back. | // The payment is paid and isn't refunded or charged back. | ||||
// Update the balance, if it wasn't already | // Update the balance, if it wasn't already | ||||
if ($payment->status != self::STATUS_PAID && $payment->amount > 0) { | if ($payment->status != self::STATUS_PAID && $payment->amount > 0) { | ||||
$payment->wallet->credit($payment->amount); | $payment->wallet->credit($payment->amount); | ||||
$notify = $payment->type == self::TYPE_RECURRING; | |||||
} | } | ||||
} elseif ($mollie_payment->hasRefunds()) { | } elseif ($mollie_payment->hasRefunds()) { | ||||
// The payment has been (partially) refunded. | // The payment has been (partially) refunded. | ||||
// The status of the payment is still "paid" | // The status of the payment is still "paid" | ||||
// TODO: Update balance | // TODO: Update balance | ||||
} elseif ($mollie_payment->hasChargebacks()) { | } elseif ($mollie_payment->hasChargebacks()) { | ||||
// The payment has been (partially) charged back. | // The payment has been (partially) charged back. | ||||
// The status of the payment is still "paid" | // The status of the payment is still "paid" | ||||
// TODO: Update balance | // TODO: Update balance | ||||
} | } | ||||
} elseif ($mollie_payment->isFailed()) { | } elseif ($mollie_payment->isFailed()) { | ||||
// Note: I didn't find a way to get any description of the problem with a payment | // Note: I didn't find a way to get any description of the problem with a payment | ||||
\Log::info(sprintf('Mollie payment failed (%s)', $payment->id)); | \Log::info(sprintf('Mollie payment failed (%s)', $payment->id)); | ||||
// Disable the mandate | |||||
if ($payment->type == self::TYPE_RECURRING) { | |||||
$notify = true; | |||||
$payment->wallet->setSetting('mandate_disabled', 1); | |||||
} | |||||
} | } | ||||
// This is a sanity check, just in case the payment provider api | // This is a sanity check, just in case the payment provider api | ||||
// sent us open -> paid -> open -> paid. So, we lock the payment after it's paid. | // sent us open -> paid -> open -> paid. So, we lock the payment after | ||||
if ($payment->status != self::STATUS_PAID) { | // recivied a "final" state. | ||||
$pending_states = [self::STATUS_OPEN, self::STATUS_PENDING, self::STATUS_AUTHORIZED]; | |||||
if (in_array($payment->status, $pending_states)) { | |||||
$payment->status = $mollie_payment->status; | $payment->status = $mollie_payment->status; | ||||
$payment->save(); | $payment->save(); | ||||
} | } | ||||
if (!empty($notify)) { | |||||
\App\Jobs\PaymentEmail::dispatch($payment); | |||||
} | |||||
return 200; | return 200; | ||||
} | } | ||||
/** | /** | ||||
* Get Mollie customer identifier for specified wallet. | * Get Mollie customer identifier for specified wallet. | ||||
* Create one if does not exist yet. | * Create one if does not exist yet. | ||||
* | * | ||||
* @param \App\Wallet $wallet The wallet | * @param \App\Wallet $wallet The wallet | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |
Typo.