From d23fc66143f69cbba5e8ddc1e6d02eb407f333f1 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Fri, 7 Apr 2023 15:35:16 +0200 Subject: [PATCH 1/2] Ignore incomplete payments --- src/Concerns/HandlesPaymentFailures.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Concerns/HandlesPaymentFailures.php b/src/Concerns/HandlesPaymentFailures.php index c364bd9c..c1c38252 100644 --- a/src/Concerns/HandlesPaymentFailures.php +++ b/src/Concerns/HandlesPaymentFailures.php @@ -10,6 +10,13 @@ trait HandlesPaymentFailures { + /** + * Indicates if incomplete payments should be confirmed automatically. + * + * @var bool + */ + protected $confirmIncompletePayment = true; + /** * The options to be used when confirming a payment intent. * @@ -30,7 +37,7 @@ trait HandlesPaymentFailures */ public function handlePaymentFailure(Subscription $subscription, $paymentMethod = null) { - if ($subscription->hasIncompletePayment()) { + if ($this->confirmIncompletePayment && $subscription->hasIncompletePayment()) { try { $subscription->latestPayment()->validate(); } catch (IncompletePayment $e) { @@ -69,9 +76,22 @@ public function handlePaymentFailure(Subscription $subscription, $paymentMethod } } + $this->confirmIncompletePayment = true; $this->paymentConfirmationOptions = []; } + /** + * Prevent automatic confirmation of incomplete payments. + * + * @return $this + */ + public function ignoreIncompletePayment() + { + $this->confirmIncompletePayment = false; + + return $this; + } + /** * Specify the options to be used when confirming a payment intent. * From d4b43bf4806107a6ab28cf93a9630cddd6e4d51d Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 7 Apr 2023 08:45:12 -0500 Subject: [PATCH 2/2] Update HandlesPaymentFailures.php --- src/Concerns/HandlesPaymentFailures.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Concerns/HandlesPaymentFailures.php b/src/Concerns/HandlesPaymentFailures.php index c1c38252..4618f633 100644 --- a/src/Concerns/HandlesPaymentFailures.php +++ b/src/Concerns/HandlesPaymentFailures.php @@ -85,7 +85,7 @@ public function handlePaymentFailure(Subscription $subscription, $paymentMethod * * @return $this */ - public function ignoreIncompletePayment() + public function ignoreIncompletePayments() { $this->confirmIncompletePayment = false;