Skip to content

Commit 277a76b

Browse files
Add support for entity metatdata
1 parent bedb96d commit 277a76b

File tree

2 files changed

+44
-12
lines changed

2 files changed

+44
-12
lines changed

CRM/Core/Payment/OmnipayMultiProcessor.php

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,11 @@ public function getBillingBlockFields() {
515515
* @return array
516516
*/
517517
public function getTransparentDirectDisplayFields() {
518+
$fields = $this->getProcessorTypeMetadata('transparent_redirect');
519+
if (isset ($fields['fields'])) {
520+
return $fields['fields'];
521+
}
522+
518523
$corePaymentFields = $this->getCorePaymentFields();
519524
$paymentFieldMappings = $this->getPaymentFieldMapping();
520525
foreach ($paymentFieldMappings as $fieldName => $fieldSpec) {
@@ -611,6 +616,10 @@ public function getBillingAddressFields($billingLocationID = NULL) {
611616
if (!$this->isTransparentRedirect()) {
612617
return parent::getBillingAddressFields($billingLocationID);
613618
}
619+
$fields = $this->getProcessorTypeMetadata('transparent_redirect');
620+
if (isset ($fields['billing_fields'])) {
621+
return $fields['billing_fields'];
622+
}
614623
$billingFields = array(
615624
'first_name' => 'billing_first_name',
616625
'middle_name' => 'billing_middle_name',
@@ -872,17 +881,7 @@ protected function supportsFutureRecurStartDate() {
872881
* @return bool
873882
*/
874883
protected function supportsPreApproval() {
875-
$entities = array();
876-
omnipaymultiprocessor_civicrm_managed($entities);
877-
foreach ($entities as $entity) {
878-
if ($entity['entity'] === 'payment_processor_type') {
879-
if (
880-
$entity['params']['name'] === $this->_paymentProcessor['payment_processor_type']
881-
&& !empty($entity['params']['supports_preapproval'])) {
882-
return TRUE;
883-
}
884-
}
885-
}
884+
$this->getProcessorTypeMetadata('supports_preapproval');
886885
return FALSE;
887886
}
888887

@@ -1029,5 +1028,38 @@ protected function purgeSensitiveDataFromSession() {
10291028
return array($key, $values);
10301029
}
10311030

1031+
/**
1032+
* @return array
1033+
*/
1034+
protected function getEntitiesMetadata() {
1035+
$entities = array();
1036+
omnipaymultiprocessor_civicrm_managed($entities);
1037+
return $entities;
1038+
}
1039+
1040+
/**
1041+
* Get metadata for a processor entity.
1042+
*
1043+
* @param string $parameter
1044+
*
1045+
* @return mixed
1046+
*/
1047+
protected function getProcessorTypeMetadata($parameter) {
1048+
$entities = $this->getEntitiesMetadata();
1049+
foreach ($entities as $entity) {
1050+
if ($entity['entity'] === 'payment_processor_type') {
1051+
if (!isset($this->_paymentProcessor['payment_processor_type'])) {
1052+
$this->_paymentProcessor['payment_processor_type'] = civicrm_api3('PaymentProcessorType', 'getvalue', array('id' => $this->_paymentProcessor['payment_processor_type_id'], 'return' => 'name'));
1053+
}
1054+
if (
1055+
$entity['params']['name'] === $this->_paymentProcessor['payment_processor_type']
1056+
&& isset($entity['metadata'][$parameter])) {
1057+
return $entity['metadata'][$parameter];
1058+
}
1059+
}
1060+
}
1061+
return FALSE;
1062+
}
1063+
10321064
}
10331065

CRM/Core/Payment/processors.mgd.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@
423423
'url_api_default' => 'https://secure.authorize.net/gateway/transact.dll',
424424
'billing_mode' => 1,
425425
'payment_type' => 1,
426-
'supports_preapproval' => 1,
427426
),
427+
'metadata' => array('supports_preapproval' => 1),
428428
),
429429
);

0 commit comments

Comments
 (0)