Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 45 additions & 47 deletions CRM/Core/Payment/OmnipayMultiProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
*/

use Omnipay\Omnipay;
use Omnipay\Common\AbstractGateway;
use Omnipay\Common\Exception\InvalidRequestException;
use CRM_Omnipaymultiprocessor_ExtensionUtil as E;
use GuzzleHttp\Middleware;
use GuzzleHttp\HandlerStack;
Expand Down Expand Up @@ -102,7 +100,7 @@ public function unserialize($data) {
/**
* Omnipay gateway.
*
* @var AbstractGateway
* @var \Omnipay\Common\AbstractGateway
*/
protected $gateway;

Expand Down Expand Up @@ -203,10 +201,10 @@ public function doPayment(&$params, $component = 'contribute') {
CRM_Core_Session::storeSessionObjects(FALSE);
if ($response->isTransparentRedirect()) {
$this->storeTransparentRedirectFormData($params['qfKey'], $response->getRedirectData() + [
'payment_processor_id' => $this->_paymentProcessor['id'],
'post_submit_url' => $response->getRedirectURL(),
'contact_id' => $params['contactID'],
]);
'payment_processor_id' => $this->_paymentProcessor['id'],
'post_submit_url' => $response->getRedirectURL(),
'contact_id' => $params['contactID'],
]);
$url = CRM_Utils_System::url('civicrm/payment/details', ['key' => $params['qfKey']]);
$this->log('success_redirect', ['url' => $url]);
CRM_Utils_System::redirect($url);
Expand Down Expand Up @@ -383,9 +381,9 @@ public function getProcessorFields(): array {
}
}
$processorFields = civicrm_api3('payment_processor_type', 'getsingle', [
'id' => $this->_paymentProcessor['payment_processor_type_id'],
'return' => $labelFields,
]
'id' => $this->_paymentProcessor['payment_processor_type_id'],
'return' => $labelFields,
]
);

foreach ($labelFields as $field => $label) {
Expand All @@ -401,7 +399,7 @@ public function getProcessorFields(): array {
*
* @return array mixed
*/
function getPreApprovalDetails($detail) {
public function getPreApprovalDetails($detail) {
return $detail;
}

Expand Down Expand Up @@ -627,7 +625,6 @@ public function getPaymentFormFields() {
return $this->_paymentProcessor['payment_type'] == 1 ? $this->getCreditCardFormFields() : $this->getDirectDebitFormFields();
}


/**
* Return an array of all the details about the fields potentially required for payment fields.
*
Expand Down Expand Up @@ -718,14 +715,14 @@ public function getTransparentDirectDisplayFields() {
*/
public function getBillingAddressFields($billingLocationID = NULL) {
$fields = $this->getProcessorTypeMetadata('fields');
if (isset ($fields['billing_fields'])) {
if (isset($fields['billing_fields'])) {
return $fields['billing_fields'];
}
if (!$this->isTransparentRedirect()) {
return parent::getBillingAddressFields($billingLocationID);
}
$fields = $this->getProcessorTypeMetadata('transparent_redirect');
if (isset ($fields['billing_fields'])) {
if (isset($fields['billing_fields'])) {
return $fields['billing_fields'];
}
$billingFields = [
Expand All @@ -734,12 +731,12 @@ public function getBillingAddressFields($billingLocationID = NULL) {
'last_name' => 'billing_last_name',
];
foreach ([
'street_address',
'city',
'state_province_id',
'postal_code',
'country_id',
] as $addressField) {
'street_address',
'city',
'state_province_id',
'postal_code',
'country_id',
] as $addressField) {
$billingFields[$addressField] = 'billing_' . $addressField . '-' . CRM_Core_BAO_LocationType::getBilling();
}
return $billingFields;
Expand Down Expand Up @@ -975,6 +972,7 @@ protected function redirectOrExit($outcome, $response = NULL) {

}
break;

case 'success':
$redirectUrl = $this->getStoredUrl('success');
break;
Expand Down Expand Up @@ -1002,10 +1000,10 @@ protected function redirectOrExit($outcome, $response = NULL) {
*/
protected function storePaymentToken($params, $contributionRecurID, $tokenReference) {
$tokenID = $this->savePaymentToken(array_merge($params, [
'payment_processor_id' => $params['processor_id'] ?? $params['payment_processor_id'],
'token' => $tokenReference,
'is_transactional' => FALSE,
]
'payment_processor_id' => $params['processor_id'] ?? $params['payment_processor_id'],
'token' => $tokenReference,
'is_transactional' => FALSE,
]
));
$contributionRecur = civicrm_api3('ContributionRecur', 'getsingle', ['id' => $contributionRecurID]);
civicrm_api3('contribution_recur', 'create', [
Expand Down Expand Up @@ -1083,7 +1081,7 @@ protected function supportsPreApproval() {
* @return bool
*/
protected function supportsCancelRecurring() {
return TRUE;
return $this->getProcessorTypeMetadata('supports_cancel_recurring', TRUE);
}

public function cancelSubscription() {
Expand Down Expand Up @@ -1175,15 +1173,15 @@ public function doPreApproval(&$params) {
$this->gateway = NULL;
CRM_Core_Session::storeSessionObjects(FALSE);
if ($response->isTransparentRedirect()) {
$this->storeTransparentRedirectFormData($params['qfKey'], $response->getRedirectData() + array(
'payment_processor_id' => $this->_paymentProcessor['id'],
'post_submit_url' => $response->getRedirectURL(),
'contact_id' => $params['contactID'],
));
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/payment/details', array('key' => $params['qfKey'])));
$this->storeTransparentRedirectFormData($params['qfKey'], $response->getRedirectData() + array(
'payment_processor_id' => $this->_paymentProcessor['id'],
'post_submit_url' => $response->getRedirectURL(),
'contact_id' => $params['contactID'],
));
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/payment/details', array('key' => $params['qfKey'])));
}
$response->redirect();
*/
*/
}
else {
$this->purgeSensitiveDataFromSession();
Expand Down Expand Up @@ -1308,10 +1306,10 @@ protected function purgeSensitiveDataFromSession() {
if (isset($key['values']) && is_array($key['values'])) {
foreach ($key['values'] as &$values) {
foreach ([
'credit_card_number',
'cvv2',
'credit_cate_type',
] as $fieldName) {
'credit_card_number',
'cvv2',
'credit_cate_type',
] as $fieldName) {
if (!empty($values[$fieldName])) {
$values[$fieldName] = '';
}
Expand Down Expand Up @@ -1345,7 +1343,7 @@ protected function getEntitiesMetadata() {
*
* @return mixed
*/
protected function getProcessorTypeMetadata($parameter) {
protected function getProcessorTypeMetadata($parameter, $default = FALSE) {
$entities = $this->getEntitiesMetadata();
foreach ($entities as $entity) {
if ($entity['entity'] === 'payment_processor_type') {
Expand All @@ -1359,7 +1357,7 @@ protected function getProcessorTypeMetadata($parameter) {
}
}
}
return FALSE;
return $default;
}

/**
Expand Down Expand Up @@ -1575,7 +1573,7 @@ public function log($type, $details) {
*/
public function getText($context, $params) {
switch ($context) {
case 'contributionPageContinueText' :
case 'contributionPageContinueText':
return ts('Click <strong>Continue</strong> to finalise your payment');
}
return parent::getText($context, $params);
Expand Down Expand Up @@ -1679,10 +1677,10 @@ protected function getContactID() {
return $this->propertyBag->getContactID();
}
return (int) Contribution::get(FALSE)
->addSelect('contact_id')
->addWhere('id', '=', $this->propertyBag->getContributionID())
->execute()
->first()['contact_id'];
->addSelect('contact_id')
->addWhere('id', '=', $this->propertyBag->getContributionID())
->execute()
->first()['contact_id'];
}

/**
Expand All @@ -1709,14 +1707,14 @@ protected function updatePaymentTokenWithAnyExtraData(string $trxnReference) {
if (is_array(json_decode($trxnReference, TRUE))) {
civicrm_api3('PaymentToken', 'create', [
'id' => $paymentToken['id'],
'token' => $trxnReference
'token' => $trxnReference,
]);
}
}
} catch (CiviCRM_API3_Exception $e) {
}
catch (CiviCRM_API3_Exception $e) {
$this->log('possible error saving token', ['error' => $e->getMessage()]);
}
}

}

1 change: 1 addition & 0 deletions Metadata/omnipay_PaypalRest.mgd.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
],
'metadata' => [
'suppress_submit_button' => 1,
'supports_cancel_recurring' => FALSE,
'supports_preapproval' => 1,
'payment_fields' => ['payment_token', 'PayerID', 'post_authorize'],
'pass_through_fields' => [
Expand Down