Skip to content

Commit

Permalink
Add handling for sagePay intolerance for empty card
Browse files Browse the repository at this point in the history
Hopefully thephpleague/omnipay-sagepay#158
will be merged but for now SagePay assumes that an empty card should be filtered out
  • Loading branch information
eileenmcnaughton committed Jan 10, 2021
1 parent 279badd commit bf1ad7e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 11 additions & 2 deletions CRM/Core/Payment/OmnipayMultiProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions Metadata/omnipay_Sagepay_Server.mgd.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' =>
[
Expand Down

0 comments on commit bf1ad7e

Please sign in to comment.