CRM-16555 introduce separated payment form as snippet
authorEileen McNaughton <eileen@fuzion.co.nz>
Wed, 27 May 2015 21:53:18 +0000 (09:53 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Wed, 27 May 2015 22:16:19 +0000 (10:16 +1200)
The point of this is to allow the payment form to be disambiguated from the contribution & event forms - allowing it to be called from elsewhere

CRM/Core/xml/Menu/payment.xml [new file with mode: 0644]
CRM/Financial/BAO/PaymentProcessor.php
CRM/Financial/Form/Payment.php [new file with mode: 0644]
templates/CRM/Core/BillingBlock.tpl
templates/CRM/Core/BillingBlockWrapper.tpl [moved from templates/CRM/Core/paypalexpress.tpl with 73% similarity]
templates/CRM/Financial/Form/Payment.tpl [new file with mode: 0644]
templates/CRM/Financial/Form/PaypalExpress.tpl [new file with mode: 0644]
templates/CRM/Financial/Form/PaypalPro.tpl [new file with mode: 0644]

diff --git a/CRM/Core/xml/Menu/payment.xml b/CRM/Core/xml/Menu/payment.xml
new file mode 100644 (file)
index 0000000..1d5d58e
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="iso-8859-1" ?>
+
+<menu>
+  <item>
+    <path>civicrm/payment/form</path>
+    <access_callback>1</access_callback>
+    <page_callback>CRM_Financial_Form_Payment</page_callback>
+    <is_public>true</is_public>
+    <weight>0</weight>
+  </item>
+</menu>
index d43def24b54b845aed0d937c2cf1bb3cefea436f..cbe6c24114978bdcbd9605be3bd3b9a828e6b140 100644 (file)
@@ -183,7 +183,7 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces
    * @return array
    *   associated array with payment processor related fields
    */
-  public static function getPayment($paymentProcessorID, $mode) {
+  public static function getPayment($paymentProcessorID, $mode = 'based_on_id') {
     if (!$paymentProcessorID) {
       CRM_Core_Error::fatal(ts('Invalid value passed to getPayment function'));
     }
diff --git a/CRM/Financial/Form/Payment.php b/CRM/Financial/Form/Payment.php
new file mode 100644 (file)
index 0000000..9d8ad34
--- /dev/null
@@ -0,0 +1,73 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.6                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2015
+ * $Id$
+ *
+ */
+class CRM_Financial_Form_Payment extends CRM_Core_Form {
+  /**
+   * Set variables up before form is built.
+   *
+   * @return void
+   */
+  public function preProcess() {
+    parent::preProcess();
+    $this->_paymentProcessorID = CRM_Utils_Request::retrieve('processor_id', 'Integer', CRM_Core_DAO::$_nullObject,
+      TRUE);
+
+    $this->assignBillingType();
+
+    // @todo - round about way to load it - just load as an object using civi\payment\system::getByProcessor
+    $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($this->_paymentProcessorID, 'unused');
+    CRM_Core_Payment_ProcessorForm::preProcess($this);
+
+    //@todo - figure out how to deal with payment express.
+    //get payPal express id and make it available to template
+    //$payPalExpressId = ($values['payment_processor_type'] == 'PayPal_Express') ? $values['id'] : 0;
+    // $this->assign('payPalExpressId', $payPalExpressId);
+
+    // Add JS to show icons for the accepted credit cards
+
+    $creditCardTypes = CRM_Core_Payment_Form::getCreditCardCSSNames();
+    CRM_Core_Resources::singleton()
+      ->addScriptFile('civicrm', 'templates/CRM/Core/BillingBlock.js', 10)
+      // workaround for CRM-13634
+      // ->addSetting(array('config' => array('creditCardTypes' => $creditCardTypes)));
+      ->addScript('CRM.config.creditCardTypes = ' . json_encode($creditCardTypes) . ';');
+
+    $this->assign('paymentProcessorID', $this->_paymentProcessorID);
+  }
+
+  public function buildQuickForm() {
+    CRM_Core_Payment_ProcessorForm::buildQuickForm($this);
+  }
+
+}
index abf23e86f688c0941f448761d21503eedd9af1de..78d5d05e188e1c2c2f5e4e3f7d1248b2b047d373 100644 (file)
       <legend>
         {$paymentTypeLabel}
       </legend>
-      {if $form.$expressButtonName}
-        {include file= "CRM/Core/paypalexpress.tpl"}
-      {/if}
+      {crmRegion name="billing-block-pre"}
+        {* todo move this region assignment to paypal processor *}
+        {include file= "CRM/Financial/PaypalPro.tpl"}
+      {/crmRegion}
       <div class="crm-section billing_mode-section {$paymentTypeName}_info-section">
         {foreach from=$paymentFields item=paymentField}
           <div class="crm-section {$form.$paymentField.name}-section">
     {/literal}
   </script>
 {/if}
-
 {/crmRegion}
+
+{if $is_monetary}
+  {crmRegion name="billing-block-post"}
+    {* Payment processors sometimes need to append something to the end of the billing block. We create a region for
+       clarity  - the plan is to move to assigning this through the payment processor to this region *}
+    {include file= "CRM/Financial/PaypalExpress.tpl"}
+  {/crmRegion}
+{/if}
similarity index 73%
rename from templates/CRM/Core/paypalexpress.tpl
rename to templates/CRM/Core/BillingBlockWrapper.tpl
index b0b4b0c3baeebc5c0ccb9c64df9bee72e9b793a4..274c62801d37cfad08bdd7ed7eaca1244572b725 100644 (file)
  +--------------------------------------------------------------------+
 *}
 
-<div class="crm-section no-label paypal_button_info-section">
-  <div class="content description">
-    {ts}If you have a PayPal account, you can click the PayPal button to continue. Otherwise, fill in the credit card and billing information on this form and click <strong>Continue</strong> at the bottom of the page.{/ts}
-  </div>
-</div>
-<div class="crm-section no-label {$form.$expressButtonName.name}-section">
-  <div class="content description">
-    {$form.$expressButtonName.html}
-    <div class="description">Save time. Checkout securely. Pay without sharing your financial information.</div>
-  </div>
+{* wrapper for the billing block including the div to make the block swappable & the js to make that happen
+This allows the billing block to change when the card type changes *}
+<div id="billing-payment-block">
+  {include file="CRM/Core/BillingBlock.tpl"}
 </div>
diff --git a/templates/CRM/Financial/Form/Payment.tpl b/templates/CRM/Financial/Form/Payment.tpl
new file mode 100644 (file)
index 0000000..e78ae8f
--- /dev/null
@@ -0,0 +1,27 @@
+{*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.6                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*}
+
+{include file="CRM/Core/BillingBlockWrapper.tpl"}
diff --git a/templates/CRM/Financial/Form/PaypalExpress.tpl b/templates/CRM/Financial/Form/PaypalExpress.tpl
new file mode 100644 (file)
index 0000000..9e90449
--- /dev/null
@@ -0,0 +1,47 @@
+{*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.6                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*}
+{if $paymentProcessor.payment_processor_type EQ 'PayPal_Express'}
+  <div id="paypalExpress">
+    {assign var=expressButtonName value='_qf_Main_upload_express'}
+    <fieldset class="crm-group paypal_checkout-group">
+      <legend>{ts}Checkout with PayPal{/ts}</legend>
+      <div class="section">
+        <div class="crm-section paypalButtonInfo-section">
+          <div class="content">
+            <span class="description">{ts}Click the PayPal button to continue.{/ts}</span>
+          </div>
+          <div class="clear"></div>
+        </div>
+        <div class="crm-section {$expressButtonName}-section">
+          <div class="content">
+            {$form.$expressButtonName.html} <span class="description">Checkout securely. Pay without sharing your financial information. </span>
+          </div>
+          <div class="clear"></div>
+        </div>
+      </div>
+    </fieldset>
+  </div>
+{/if}
diff --git a/templates/CRM/Financial/Form/PaypalPro.tpl b/templates/CRM/Financial/Form/PaypalPro.tpl
new file mode 100644 (file)
index 0000000..472e5b1
--- /dev/null
@@ -0,0 +1,38 @@
+{*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.6                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*}
+{if $form.$expressButtonName}
+  <div class="crm-section no-label paypal_button_info-section">
+    <div class="content description">
+      {ts}If you have a PayPal account, you can click the PayPal button to continue. Otherwise, fill in the credit card and billing information on this form and click <strong>Continue</strong> at the bottom of the page.{/ts}
+    </div>
+  </div>
+  <div class="crm-section no-label {$form.$expressButtonName.name}-section">
+    <div class="content description">
+      {$form.$expressButtonName.html}
+      <div class="description">Save time. Checkout securely. Pay without sharing your financial information.</div>
+    </div>
+  </div>
+{/if}