From e74d340e75953fa59ad41e8dd3dc6a62fbac5b57 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 11 Jan 2021 00:06:27 +1300 Subject: [PATCH] Add handling for sagePay intolerance for empty card Hopefully https://github.com/thephpleague/omnipay-sagepay/pull/158 will be merged but for now SagePay assumes that an empty card should be filtered out --- CRM/Core/Payment/OmnipayMultiProcessor.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/CRM/Core/Payment/OmnipayMultiProcessor.php b/CRM/Core/Payment/OmnipayMultiProcessor.php index 3b6d8bd11..d568114ac 100644 --- a/CRM/Core/Payment/OmnipayMultiProcessor.php +++ b/CRM/Core/Payment/OmnipayMultiProcessor.php @@ -462,7 +462,7 @@ private function camelFieldName($fieldName) { * * @param array $params * - * @return array + * @return array|null */ private function getCreditCardObjectParams($params) { $billingID = $locationTypes = CRM_Core_BAO_LocationType::getBilling(); @@ -516,6 +516,10 @@ private function getCreditCardObjectParams($params) { } } } + if (empty(array_filter($cardFields)) && !$this->getProcessorTypeMetadata('is_pass_null_for_empty_card')) { + // sagepay hack - see https://github.com/thephpleague/omnipay-sagepay/issues/157#issuecomment-757448484 + return NULL; + } return $cardFields; } @@ -578,7 +582,12 @@ protected function getCreditCardOptions(array $params): array { $creditCardOptions = array_merge($creditCardOptions, $this->getProcessorPassThroughFields()); CRM_Utils_Hook::alterPaymentProcessorParams($this, $params, $creditCardOptions); - $creditCardOptions['card'] = array_merge($creditCardOptions['card'], $this->getSensitiveCreditCardObjectOptions($params)); + // This really is a hack just for sagepay. I meant to filter all + // empty but other processors expect it to be an object. Test cover exists. + // https://github.com/thephpleague/omnipay-sagepay/pull/158 + if (!empty($creditCardOptions['card'])) { + $creditCardOptions['card'] = array_merge($creditCardOptions['card'], $this->getSensitiveCreditCardObjectOptions($params)); + } return $creditCardOptions; }