From 91f727de930c7f51b522d3397348f7883b431bb0 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak <pradpnayak@gmail.com> Date: Mon, 16 Nov 2020 13:42:38 +0000 Subject: [PATCH] do not call payment processor when payment amount is 0 --- CRM/Core/Payment/Stripe.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CRM/Core/Payment/Stripe.php b/CRM/Core/Payment/Stripe.php index 4f3a3339..d54049d3 100644 --- a/CRM/Core/Payment/Stripe.php +++ b/CRM/Core/Payment/Stripe.php @@ -480,6 +480,19 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment { * @throws \Civi\Payment\Exception\PaymentProcessorException */ public function doPayment(&$propertyBag, $component = 'contribute') { + + // If we have a $0 amount, skip call to processor and set payment_status to Completed. + // https://github.com/civicrm/civicrm-core/blob/master/CRM/Core/Payment.php#L1362 + if ($propertyBag['amount'] == 0) { + $result = [ + 'payment_status_id' => CRM_Core_PseudoConstant::getKey( + 'CRM_Contribute_BAO_Contribution', + 'contribution_status_id', 'Completed' + ) + ]; + return $result; + } + /* @var \Civi\Payment\PropertyBag $propertyBag */ $propertyBag = \Civi\Payment\PropertyBag::cast($propertyBag); $propertyBag = $this->beginDoPayment($propertyBag); -- GitLab