X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FPayment%2FPayPalImpl.php;h=f16370d206ef723c8e969e5ebe487488a018cc6d;hb=a0dffd4e0feb5de25faaeaa52c1e2e2d6fecb941;hp=54f59b1c7aa0683ecbf1c9c04e99b98f72d6b887;hpb=f7ecb545980361fe246e0fa00b80110efcb39628;p=civicrm-core.git diff --git a/CRM/Core/Payment/PayPalImpl.php b/CRM/Core/Payment/PayPalImpl.php index 54f59b1c7a..f16370d206 100644 --- a/CRM/Core/Payment/PayPalImpl.php +++ b/CRM/Core/Payment/PayPalImpl.php @@ -488,17 +488,14 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { $this->_component = $component; if ($this->isPayPalType($this::PAYPAL_EXPRESS) || ($this->isPayPalType($this::PAYPAL_PRO) && !empty($params['token']))) { return $this->doExpressCheckout($params); - } - - $statuses = CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id', 'validate'); + $result = $this->setStatusPaymentPending([]); // If we have a $0 amount, skip call to processor and set payment_status to Completed. // Conceivably a processor might override this - perhaps for setting up a token - but we don't // have an example of that at the mome. if ($params['amount'] == 0) { - $result['payment_status_id'] = array_search('Completed', $statuses); - $result['payment_status'] = 'Completed'; + $result = $this->setStatusPaymentCompleted($result); return $result; } @@ -510,13 +507,10 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { $result = $this->doPaymentPayPalButton($params, $component); if (is_array($result) && !isset($result['payment_status_id'])) { if (!empty($params['is_recur'])) { - // See comment block. - $result['payment_status_id'] = array_search('Pending', $statuses); - $result['payment_status'] = 'Pending'; + $result = $this->setStatusPaymentPending($result); } else { - $result['payment_status_id'] = array_search('Completed', $statuses); - $result['payment_status'] = 'Completed'; + $result = $this->setStatusPaymentCompleted($result); } } } @@ -551,6 +545,8 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { public function doPaymentPayPalButton(&$params, $component = 'contribute') { $args = []; + $result = $this->setStatusPaymentPending([]); + $this->initialize($args, 'DoDirectPayment'); $args['paymentAction'] = 'Sale'; @@ -602,20 +598,26 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { // Allow further manipulation of the arguments via custom hooks .. CRM_Utils_Hook::alterPaymentProcessorParams($this, $params, $args); - $result = $this->invokeAPI($args); + $apiResult = $this->invokeAPI($args); $params['recurr_profile_id'] = NULL; if (CRM_Utils_Array::value('is_recur', $params) == 1) { - $params['recurr_profile_id'] = $result['profileid']; + $params['recurr_profile_id'] = $apiResult['profileid']; } /* Success */ + $result = $this->setStatusPaymentCompleted($result); + $doQueryParams = [ + 'gross_amount' => $apiResult['amt'] ?? NULL, + 'trxn_id' => $apiResult['transactionid'] ?? NULL, + 'is_recur' => $params['is_recur'] ?? FALSE, + ]; + $params = array_merge($params, $this->doQuery($doQueryParams)); - $params['trxn_id'] = $result['transactionid'] ?? NULL; - $params['gross_amount'] = $result['amt'] ?? NULL; - $params = array_merge($params, $this->doQuery($params)); - return $params; + $result['fee_amount'] = $params['fee_amount'] ?? 0; + $result['trxn_id'] = $apiResult['transactionid'] ?? NULL; + return $result; } /** @@ -695,7 +697,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { * Get url for users to manage this recurring contribution for this processor. * * @param int $entityID - * @param null $entity + * @param string|null $entity * @param string $action * * @return string|null @@ -796,6 +798,11 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { $paypalIPN = new CRM_Core_Payment_PayPalProIPN($params); break; + case 'PayPal_Express': + // "PayPal - Express" + $paypalIPN = new CRM_Core_Payment_PayPalProIPN($params); + break; + case 'PayPal_Standard': // "PayPal - Website Payments Standard" $paypalIPN = new CRM_Core_Payment_PayPalIPN($params);