Allow payment processor to determine the text around 'continue'
authoreileen <emcnaughton@wikimedia.org>
Fri, 8 Mar 2019 00:35:06 +0000 (13:35 +1300)
committereileen <emcnaughton@wikimedia.org>
Thu, 21 Mar 2019 23:04:48 +0000 (12:04 +1300)
This text traditionally depends on the outdated payment processor 'mode' concept. Since the 'right' text depends
on what the payment processor plans to do moving it out to the processor classes makes sense

We could also do the same with 'button'

CRM/Contribute/Form/Contribution/Confirm.php
CRM/Contribute/Form/ContributionBase.php
CRM/Core/Payment.php
CRM/Core/Payment/Manual.php
templates/CRM/Contribute/Form/Contribution/Confirm.tpl

index 0afaf65fb15f0474e19f5ff333af5a008951f0c6..dcf82c4b27f07b2171dc68c6354fccda5a7dc6ce 100644 (file)
@@ -598,6 +598,15 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
       $contribButton = ts('Make Contribution');
     }
     $this->assign('button', $contribButton);
+
+    $this->assign('continueText',
+      $this->getPaymentProcessorObject()->getText('contributionPageContinueText', [
+        'is_payment_to_existing' => !empty($this->_ccid),
+        'amount' => $this->_amount,
+        ]
+      )
+    );
+
     $this->addButtons(array(
         array(
           'type' => 'next',
index f8b6f1a1467bcfbe24134c9c86b1e0d08ae8eb3c..c8e488f34b92f7dc88c706c41bdbeec87ff70fdf 100644 (file)
@@ -1390,4 +1390,17 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
     }
   }
 
+
+  /**
+   * Get the payment processor object for the submission, returning the manual one for offline payments.
+   *
+   * @return CRM_Core_Payment
+   */
+  protected function getPaymentProcessorObject() {
+    if (!empty($this->_paymentProcessor)) {
+      return $this->_paymentProcessor['object'];
+    }
+    return new CRM_Core_Payment_Manual();
+  }
+
 }
index f21aeec500e7d852d10fb43023ad815a11089e0a..fb465033e8a5faef76189755b7a13d3f774522f1 100644 (file)
@@ -522,9 +522,23 @@ abstract class CRM_Core_Payment {
             $gotText .= ' ' . ts('You will receive an email receipt for each recurring contribution.');
           }
         }
-        break;
+        return $gotText;
+
+      case 'contributionPageContinueText':
+        if ($params['amount'] <= 0) {
+          return ts('To complete this transaction, click the <strong>Continue</strong> button below.');
+        }
+        if ($this->_paymentProcessor['billing_mode'] == 4) {
+          return ts('Click the <strong>Continue</strong> button to go to %1, where you will select your payment method and complete the contribution.', [$this->_paymentProcessor['payment_processor_type']]);
+        }
+        if ($params['is_payment_to_existing']) {
+          return ts('To complete this transaction, click the <strong>Make Payment</strong> button below.');
+        }
+        return ts('To complete your contribution, click the <strong>Continue</strong> button below.');
+
     }
-    return $gotText;
+    CRM_Core_Error::deprecatedFunctionWarning('Calls to getText must use a supported method');
+    return '';
   }
 
   /**
index f31524474f5e01b08e42dc5347de1b233ffd2bca..8798f5cce91ba237a12a6191a2f099e6c401e601 100644 (file)
@@ -231,4 +231,30 @@ class CRM_Core_Payment_Manual extends CRM_Core_Payment {
     return TRUE;
   }
 
+  /**
+   * Get help text information (help, description, etc.) about this payment,
+   * to display to the user.
+   *
+   * @param string $context
+   *   Context of the text.
+   *   Only explicitly supported contexts are handled without error.
+   *   Currently supported:
+   *   - contributionPageRecurringHelp (params: is_recur_installments, is_email_receipt)
+   *
+   * @param array $params
+   *   Parameters for the field, context specific.
+   *
+   * @return string
+   */
+  public function getText($context, $params) {
+    switch ($context) {
+      case 'contributionPageContinueText':
+        if ($params['amount'] <= 0) {
+          return ts('To complete this transaction, click the <strong>Continue</strong> button below.');
+        }
+        return ts('To complete your contribution, click the <strong>Continue</strong> button below.');
+
+    }
+  }
+
 }
index bb48dddede924dfd68ddf04f2f0f428d6399955b..b9f3e1fbc4c762e0d50cf3069c2dc0a86ca17e5f 100644 (file)
 
 <div class="crm-contribution-page-id-{$contributionPageID} crm-block crm-contribution-confirm-form-block">
   <div class="help">
-    <p>{ts}Please verify the information below carefully. Click<strong>Go Back</strong>if you need to make changes.{/ts}
-      {if $contributeMode EQ 'notify' and ! $is_pay_later}
-        {ts 1=$paymentProcessor.name 2=$button}Click the
-          <strong>%2</strong>
-          button to go to %1, where you will select your payment method and complete the contribution.{/ts}
-      {elseif ! $is_monetary or $amount LE 0.0 or $is_pay_later}
-        {ts 1=$button}To complete this transaction, click the<strong>%1</strong>button below.{/ts}
-      {else}
-        {ts 1=$button}To complete your contribution, click the<strong>%1</strong>button below.{/ts}
-      {/if}
+    <p>{ts}Please verify the information below carefully. Click <strong>Go Back</strong> if you need to make changes.{/ts}
+      {$continueText}
     </p>
   </div>
   <div id="crm-submit-buttons" class="crm-submit-buttons">