Skip to content

Commit fae37a0

Browse files
Add handling for sagePay intolerance for empty card
Hopefully thephpleague/omnipay-sagepay#158 will be merged but for now SagePay assumes that an empty card should be filtered out
1 parent 279badd commit fae37a0

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

CRM/Core/Payment/OmnipayMultiProcessor.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ private function camelFieldName($fieldName) {
462462
*
463463
* @param array $params
464464
*
465-
* @return array
465+
* @return array|null
466466
*/
467467
private function getCreditCardObjectParams($params) {
468468
$billingID = $locationTypes = CRM_Core_BAO_LocationType::getBilling();
@@ -516,6 +516,10 @@ private function getCreditCardObjectParams($params) {
516516
}
517517
}
518518
}
519+
if (empty(array_filter($cardFields)) && $this->getProcessorTypeMetadata('is_pass_null_for_empty_card')) {
520+
// sagepay hack - see https://github.com/thephpleague/omnipay-sagepay/issues/157#issuecomment-757448484
521+
return NULL;
522+
}
519523
return $cardFields;
520524
}
521525

@@ -578,7 +582,12 @@ protected function getCreditCardOptions(array $params): array {
578582
$creditCardOptions = array_merge($creditCardOptions, $this->getProcessorPassThroughFields());
579583

580584
CRM_Utils_Hook::alterPaymentProcessorParams($this, $params, $creditCardOptions);
581-
$creditCardOptions['card'] = array_merge($creditCardOptions['card'], $this->getSensitiveCreditCardObjectOptions($params));
585+
// This really is a hack just for sagepay. I meant to filter all
586+
// empty but other processors expect it to be an object. Test cover exists.
587+
// https://github.com/thephpleague/omnipay-sagepay/pull/158
588+
if (!empty($creditCardOptions['card'])) {
589+
$creditCardOptions['card'] = array_merge($creditCardOptions['card'], $this->getSensitiveCreditCardObjectOptions($params));
590+
}
582591
return $creditCardOptions;
583592
}
584593

0 commit comments

Comments
 (0)