CRM-19262 - Fix offline Pay Now Functionality
authorjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Tue, 30 Aug 2016 06:07:17 +0000 (11:37 +0530)
committerjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Tue, 30 Aug 2016 08:44:10 +0000 (14:14 +0530)
CRM/Contribute/Form/Contribution.php
templates/CRM/Contribute/Form/Contribution.tpl
tests/phpunit/WebTest/Contribute/UpdatePendingContributionTest.php

index 10f86a29addc4f328a78d569600e0796db82ea37..78af5f2fbf72df3a59296163abfe786eb0e5152c 100644 (file)
@@ -289,7 +289,10 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
     $this->assign('lineItem', empty($this->_lineItems) ? FALSE : $this->_lineItems);
 
     // Set title
-    if ($this->_mode) {
+    if ($this->_mode && $this->_id) {
+      $this->setPageTitle(ts('Contribution (Pay Now)'));
+    }
+    elseif ($this->_mode) {
       $this->setPageTitle($this->_ppID ? ts('Credit Card Pledge Payment') : ts('Credit Card Contribution'));
     }
     else {
@@ -743,12 +746,19 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
       unset($status[CRM_Utils_Array::key('Chargeback', $statusName)]);
     }
 
-    $this->add('select', 'contribution_status_id',
+    $statusElement = $this->add('select', 'contribution_status_id',
       ts('Contribution Status'),
       $status,
       FALSE
     );
 
+    $currencyFreeze = FALSE;
+    if ($this->_mode && $this->_id && ($this->_action & CRM_Core_Action::UPDATE)) {
+      $statusElement->freeze();
+      $currencyFreeze = TRUE;
+      $attributes['total_amount']['readonly'] = TRUE;
+    }
+
     // CRM-16189, add Revenue Recognition Date
     if (CRM_Contribute_BAO_Contribution::checkContributeSettings('deferred_revenue_enabled')) {
       $this->add('date', 'revenue_recognition_date', ts('Revenue Recognition Date'), CRM_Core_SelectValues::date(NULL, 'M Y', NULL, 5));
@@ -824,7 +834,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
         }
       }
       $this->assign('hasPriceSets', $hasPriceSets);
-      $currencyFreeze = FALSE;
       if (!($this->_action & CRM_Core_Action::UPDATE)) {
         if ($this->_online || $this->_ppID) {
           $attributes['total_amount'] = array_merge($attributes['total_amount'], array(
@@ -1218,6 +1227,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
       $this->set('is_deductible', TRUE);
     }
     $contributionParams = array(
+      'id' => CRM_Utils_Array::value('contribution_id', $this->_params),
       'contact_id' => $contactID,
       'line_item' => $lineItem,
       'is_test' => $isTest,
@@ -1497,6 +1507,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
           $pId = $contributionDetails['participant'];
         }
       }
+      $this->_params['contribution_id'] = $this->_id;
     }
 
     if (!$priceSetId && !empty($submittedValues['total_amount']) && $this->_id) {
index 7a7ac144574ca99e284593596bfd75fd233017a9..12ba4398315ad15ceceab26c86fb1fe0259c419e 100644 (file)
@@ -41,7 +41,7 @@
   {if $contributionMode}
   <div class="help">
     {if $contactId}
-      {ts 1=$displayName 2=$contributionMode|upper}Use this form to submit a new contribution on behalf of %1. <strong>A
+      {ts 1=$displayName 2=$contributionMode|upper}Use this form to {if $contribID} edit {else} submit a new {/if} contribution on behalf of %1. <strong>A
         %2 transaction will be submitted</strong> using the selected payment processor.{/ts}
     {else}
       {ts 1=$displayName 2=$contributionMode|upper}Use this form to submit a new contribution. <strong>A %2 transaction will be submitted</strong> using the selected payment processor.{/ts}
         {ts}(test){/ts}
       {/if} {help id="id-financial_type"}
       </td>
+      <td>
+        {if $contactId && $contribID && $contributionMode EQ null && $contribution_status_id eq 2}
+          {capture assign=payNowLink}{crmURL p='civicrm/contact/view/contribution' q="reset=1&action=update&id=`$contribID`&cid=`$contactId`&context=`$context`&mode=live"}{/capture}
+          <a class="open-inline-noreturn action-item crm-hover-button" href="{$payNowLink}">&raquo; {ts}Pay Now{/ts}</a>
+        {/if}
+      </td>
     </tr>
     {if $action eq 2 and $lineItem and !$defaultContribution}
     <tr>
       </td>
     </tr>
 
-      {if $buildRecurBlock}
+      {if $buildRecurBlock && !$contribID}
       <tr id='recurringPaymentBlock' class='hiddenElement'>
         <td></td>
         <td>
   {* CRM-7362 --add campaign to contributions *}
   {include file="CRM/Campaign/Form/addCampaignToComponent.tpl" campaignTrClass="crm-contribution-form-block-campaign_id"}
 
-    {if $contributionMode}
+    {if $contributionMode && !$contribID}
     {if $email and $outBound_option != 2}
      <tr class="crm-contribution-form-block-is_email_receipt">
        <td class="label">{$form.is_email_receipt.label}</td>
       </td>
     </tr>
     {/if}
-    {if !$contributionMode}
+    {if !$contributionMode || $contribID}
       <tr class="crm-contribution-form-block-contribution_status_id">
         <td class="label">{$form.contribution_status_id.label}</td>
         <td>{$form.contribution_status_id.html}
         {if $contribution_status_id eq 2}{if $is_pay_later }: {ts}Pay Later{/ts} {else}: {ts}Incomplete Transaction{/ts}{/if}{/if}
         </td>
       </tr>
+    {/if}
 
+    {if !$contributionMode}
       {* Cancellation / Refunded fields are hidden unless contribution status is set to Cancelled or Refunded*}
       <tr id="cancelInfo" class="crm-contribution-form-block-cancelInfo">
         <td>&nbsp;</td>
         </td>
       </tr>
     {/if}
-    {if $form.revenue_recognition_date}
+    {if $form.revenue_recognition_date && !$contribID}
       <tr class="crm-contribution-form-block-revenue_recognition_date">
         <td class="label">{$form.revenue_recognition_date.label}</td>
         <td>{$form.revenue_recognition_date.html}</td>
index 3dcac2b54897c367773091580fc45051fac342eb..edaee81c30b4dd98dce1fd3ee52c2c6363ed0b20 100644 (file)
@@ -35,6 +35,46 @@ class WebTest_Contribute_UpdatePendingContributionTest extends CiviSeleniumTestC
     parent::setUp();
   }
 
+  public function testPayNowLink() {
+    $this->webtestLogin();
+
+    //Offline Pay Later Contribution
+    $contact = $this->_testOfflineContribution();
+    $this->openCiviPage("contact/view", "reset=1&cid={$contact['id']}", "css=li#tab_contribute a");
+    $this->click("css=li#tab_contribute a");
+    $this->waitForElementPresent("xpath=//table[@class='selector row-highlight']/tbody//tr/td[8]/span/a");
+
+    $this->clickPopupLink("xpath=//table[@class='selector row-highlight']/tbody//tr/td[8]/span/a[@title='Edit Contribution']");
+    $this->waitForElementPresent('financial_type_id');
+
+    $this->clickPopupLink("xpath=//a[contains(text(), 'Pay Now')]");
+    $this->assertElementContainsText("xpath=//span[@class='ui-dialog-title']", "Edit Contribution (Pay Now)");
+    $this->assertElementNotPresent("xpath=//select[@id='currency']");
+    $this->assertNotEditable('total_amount');
+    $this->assertElementNotPresent("xpath=//select[@id='contribution_status_id']");
+
+    $this->webtestAddCreditCardDetails();
+    $this->webtestAddBillingDetails();
+
+    $this->clickAjaxLink('_qf_Contribution_upload-bottom');
+    $this->waitForText('crm-notification-container', "The contribution record has been saved.");
+
+    $this->clickPopupLink("xpath=//table[@class='selector row-highlight']/tbody//tr/td[8]/span/a[@title='View Contribution']");
+
+    // View Contribution Record and test for expected values
+    $expected = array(
+      'From' => $contact['display_name'],
+      'Financial Type' => 'Donation',
+      'Total Amount' => '$ 100.00',
+      'Payment Method' => 'Credit Card (Test Processor)',
+      'Contribution Status' => 'Completed',
+      'Received Into' => 'Payment Processor Account',
+      'Net Amount' => '$ 98.50',
+      'Fee Amount' => '$ 1.50',
+    );
+    $this->webtestVerifyTabularData($expected);
+  }
+
   public function testUpdatePendingContribution() {
     $this->webtestLogin();
 
@@ -122,8 +162,6 @@ class WebTest_Contribute_UpdatePendingContributionTest extends CiviSeleniumTestC
 
     $this->type("note", "This is a test note.");
     $this->type("non_deductible_amount", "10");
-    $this->type("fee_amount", "0");
-    $this->type("net_amount", "0");
     $this->type("invoice_id", time());
     $this->webtestFillDate('thankyou_date');
 
@@ -151,7 +189,7 @@ class WebTest_Contribute_UpdatePendingContributionTest extends CiviSeleniumTestC
     // View Contribution Record and test for expected values
     $expected = array(
       'Financial Type' => 'Donation',
-      'Total Amount' => '100.00',
+      'Total Amount' => '100.00',
       'Contribution Status' => 'Pending',
       'Payment Method' => 'Check',
       'Check Number' => 'check #1041',
@@ -170,7 +208,7 @@ class WebTest_Contribute_UpdatePendingContributionTest extends CiviSeleniumTestC
     // verify soft credit details
     $expected = array(
       4 => 'Donation',
-      2 => '100.00',
+      2 => '100.00',
       6 => 'Pending',
       1 => $contact['display_name'],
     );