Commit 926a43f6 authored by mattwire's avatar mattwire
Browse files

Add function processZeroAmountPayment to check/handle a zero amount payment

parent 8d8a0b83
......@@ -424,6 +424,32 @@ trait CRM_Core_Payment_MJWTrait {
return $this->paymentProcessorSubscriptionID;
}
/**
* In some cases a payment is still submitted via the payment processor with zero amount.
* See eg. https://lab.civicrm.org/extensions/stripe/-/issues/256.
* When you have a 0 membership option and a confirmation page.
* This function should be called in doPayment() before beginDoPayment()
*
* @param \Civi\Payment\PropertyBag $propertyBag
*
* @return array|false
*/
protected function processZeroAmountPayment(\Civi\Payment\PropertyBag $propertyBag) {
// 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->getAmount() == 0) {
return [
'payment_status_id' => CRM_Core_PseudoConstant::getKey(
'CRM_Contribute_BAO_Contribution',
'contribution_status_id', 'Completed'
)
];
}
else {
return FALSE;
}
}
/**
* @param \Civi\Payment\PropertyBag $propertyBag
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment