From bf1ad7ec30a1bdd9bd2ef81a8d4d9db34247e635 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 +++++++++++-- Metadata/omnipay_Sagepay_Server.mgd.php | 3 +++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CRM/Core/Payment/OmnipayMultiProcessor.php b/CRM/Core/Payment/OmnipayMultiProcessor.php index 3b6d8bd11..2dbb72f00 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; } diff --git a/Metadata/omnipay_Sagepay_Server.mgd.php b/Metadata/omnipay_Sagepay_Server.mgd.php index 59efaefe3..1f863bca4 100644 --- a/Metadata/omnipay_Sagepay_Server.mgd.php +++ b/Metadata/omnipay_Sagepay_Server.mgd.php @@ -74,6 +74,9 @@ 'ipn_processing_delay' => 0, // See https://github.com/thephpleague/omnipay-sagepay/pull/154 'pass_through_fields' => ['billingForShipping' => 1], + // Hopefully temporary fix. + // https://github.com/thephpleague/omnipay-sagepay/pull/158 + 'is_pass_null_for_empty_card' => TRUE, ], 'params' => [