Skip to content

Commit

Permalink
Remove usage of deprecated function from paypal
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwire authored and eileenmcnaughton committed May 21, 2018
1 parent 7f874ed commit f220bea
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
9 changes: 9 additions & 0 deletions CRM/Core/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ abstract class CRM_Core_Payment {
*/
protected $cancelUrl;

/**
* Processor type label.
*
* (Deprecated parameter but used in some messages).
*
* @var string
*/
public $_processorName;

/**
* The profile configured to show on the billing form.
*
Expand Down
42 changes: 23 additions & 19 deletions CRM/Core/Payment/PayPalImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function isPayPalType($typeName) {
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
protected function supportsBackOffice() {
if ($this->_processorName == ts('PayPal Pro')) {
if ($this->isPayPalType($this::PAYPAL_PRO)) {
return TRUE;
}
return FALSE;
Expand All @@ -129,7 +129,7 @@ protected function supportsBackOffice() {
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
protected function supportsPreApproval() {
if ($this->_processorName == ts('PayPal Express') || $this->_processorName == ts('PayPal Pro')) {
if ($this->isPayPalType($this::PAYPAL_EXPRESS) || $this->isPayPalType($this::PAYPAL_PRO)) {
return TRUE;
}
return FALSE;
Expand All @@ -147,13 +147,13 @@ protected function supportsPreApproval() {
public function buildForm(&$form) {
if ($this->supportsPreApproval()) {
$this->addPaypalExpressCode($form);
if ($this->_processorName == ts('PayPal Express')) {
if ($this->isPayPalType($this::PAYPAL_EXPRESS)) {
CRM_Core_Region::instance('billing-block-post')->add(array(
'template' => 'CRM/Financial/Form/PaypalExpress.tpl',
'name' => 'paypal_express',
));
}
if ($this->_processorName == ts('PayPal Pro')) {
if ($this->isPayPalType($this::PAYPAL_PRO)) {
CRM_Core_Region::instance('billing-block-pre')->add(array(
'template' => 'CRM/Financial/Form/PaypalPro.tpl',
));
Expand Down Expand Up @@ -226,7 +226,7 @@ protected function supportsRecurContributionsForPledges() {
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public function validatePaymentInstrument($values, &$errors) {
if ($this->_paymentProcessor['payment_processor_type'] == 'PayPal' && !$this->isPaypalExpress($values)) {
if ($this->isPayPalType($this::PAYPAL_PRO) && !$this->isPaypalExpress($values)) {
CRM_Core_Payment_Form::validateCreditCard($values, $errors, $this->_paymentProcessor['id']);
CRM_Core_Form::validateMandatoryFields($this->getMandatoryFields(), $values, $errors);
}
Expand Down Expand Up @@ -505,9 +505,7 @@ public function initialize(&$args, $method) {
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public function doPayment(&$params, $component = 'contribute') {
if ($this->_paymentProcessor['payment_processor_type'] == 'PayPal_Express'
|| ($this->_paymentProcessor['payment_processor_type'] == 'PayPal' && !empty($params['token']))
) {
if ($this->isPayPalType($this::PAYPAL_EXPRESS) || ($this->isPayPalType($this::PAYPAL_PRO) && !empty($params['token']))) {
$this->_component = $component;
return $this->doExpressCheckout($params);

Expand Down Expand Up @@ -648,9 +646,8 @@ public function doQuery($params) {
*/
public function checkConfig() {
$error = array();
$paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(FALSE, NULL, 'name');

if ($this->_paymentProcessor['payment_processor_type_id'] != CRM_Utils_Array::key('PayPal_Standard', $paymentProcessorType)) {
if (!$this->isPayPalType($this::PAYPAL_STANDARD)) {
if (empty($this->_paymentProcessor['signature'])) {
$error[] = ts('Signature is not set in the Administer » System Settings » Payment Processors.');
}
Expand All @@ -676,7 +673,7 @@ public function checkConfig() {
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public function cancelSubscriptionURL() {
if ($this->_paymentProcessor['payment_processor_type'] == 'PayPal_Standard') {
if ($this->isPayPalType($this::PAYPAL_STANDARD)) {
return "{$this->_paymentProcessor['url_site']}cgi-bin/webscr?cmd=_subscr-find&alias=" . urlencode($this->_paymentProcessor['user_name']);
}
else {
Expand All @@ -691,9 +688,10 @@ public function cancelSubscriptionURL() {
* Method to check for.
*
* @return bool
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public function isSupported($method) {
if ($this->_paymentProcessor['payment_processor_type'] != 'PayPal') {
if (!$this->isPayPalType($this::PAYPAL_PRO)) {
// since subscription methods like cancelSubscription or updateBilling is not yet implemented / supported
// by standard or express.
return FALSE;
Expand All @@ -706,9 +704,10 @@ public function isSupported($method) {
*
* @return bool
* Should the form button by suppressed?
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public function isSuppressSubmitButtons() {
if ($this->_paymentProcessor['payment_processor_type'] == 'PayPal_Express') {
if ($this->isPayPalType($this::PAYPAL_EXPRESS)) {
return TRUE;
}
return FALSE;
Expand All @@ -719,9 +718,10 @@ public function isSuppressSubmitButtons() {
* @param array $params
*
* @return array|bool|object
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public function cancelSubscription(&$message = '', $params = array()) {
if ($this->_paymentProcessor['payment_processor_type'] == 'PayPal') {
if ($this->isPayPalType($this::PAYPAL_PRO)) {
$args = array();
$this->initialize($args, 'ManageRecurringPaymentsProfileStatus');

Expand All @@ -741,6 +741,9 @@ public function cancelSubscription(&$message = '', $params = array()) {

/**
* Process incoming notification.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
static public function handlePaymentNotification() {
$params = array_merge($_GET, $_REQUEST);
Expand Down Expand Up @@ -787,7 +790,7 @@ static public function handlePaymentNotification() {
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public function updateSubscriptionBillingInfo(&$message = '', $params = array()) {
if ($this->_paymentProcessor['payment_processor_type'] == 'PayPal') {
if ($this->isPayPalType($this::PAYPAL_PRO)) {
$config = CRM_Core_Config::singleton();
$args = array();
$this->initialize($args, 'UpdateRecurringPaymentsProfile');
Expand Down Expand Up @@ -823,9 +826,10 @@ public function updateSubscriptionBillingInfo(&$message = '', $params = array())
* @param array $params
*
* @return array|bool|object
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public function changeSubscriptionAmount(&$message = '', $params = array()) {
if ($this->_paymentProcessor['payment_processor_type'] == 'PayPal') {
if ($this->isPayPalType($this::PAYPAL_PRO)) {
$config = CRM_Core_Config::singleton();
$args = array();
$this->initialize($args, 'UpdateRecurringPaymentsProfile');
Expand Down Expand Up @@ -1139,10 +1143,10 @@ public static function deformat($str) {
* Get array of fields that should be displayed on the payment form.
*
* @return array
* @throws CiviCRM_API3_Exception
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public function getPaymentFormFields() {
if ($this->_processorName == ts('PayPal Pro')) {
if ($this->isPayPalType($this::PAYPAL_PRO)) {
return $this->getCreditCardFormFields();
}
else {
Expand Down Expand Up @@ -1177,7 +1181,7 @@ protected function mapPaypalParamsToCivicrmParams($fieldMap, $paypalParams) {
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
protected function isPaypalExpress($params) {
if ($this->_processorName == ts('PayPal Express')) {
if ($this->isPayPalType($this::PAYPAL_EXPRESS)) {
return TRUE;
}

Expand Down

0 comments on commit f220bea

Please sign in to comment.