From 29cb47246bec662663cbbb3e1fb66c458b98f6d8 Mon Sep 17 00:00:00 2001 From: jitendrapurohit Date: Tue, 30 Aug 2016 11:37:17 +0530 Subject: [PATCH] CRM-19262 - Fix offline Pay Now Functionality --- CRM/Contribute/Form/Contribution.php | 17 +++++-- .../CRM/Contribute/Form/Contribution.tpl | 18 ++++++-- .../UpdatePendingContributionTest.php | 46 +++++++++++++++++-- 3 files changed, 69 insertions(+), 12 deletions(-) diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 10f86a29ad..78af5f2fbf 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -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) { diff --git a/templates/CRM/Contribute/Form/Contribution.tpl b/templates/CRM/Contribute/Form/Contribution.tpl index 7a7ac14457..12ba439831 100644 --- a/templates/CRM/Contribute/Form/Contribution.tpl +++ b/templates/CRM/Contribute/Form/Contribution.tpl @@ -41,7 +41,7 @@ {if $contributionMode}
{if $contactId} - {ts 1=$displayName 2=$contributionMode|upper}Use this form to submit a new contribution on behalf of %1. A + {ts 1=$displayName 2=$contributionMode|upper}Use this form to {if $contribID} edit {else} submit a new {/if} contribution on behalf of %1. A %2 transaction will be submitted using the selected payment processor.{/ts} {else} {ts 1=$displayName 2=$contributionMode|upper}Use this form to submit a new contribution. A %2 transaction will be submitted using the selected payment processor.{/ts} @@ -86,6 +86,12 @@ {ts}(test){/ts} {/if} {help id="id-financial_type"} + + {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} + » {ts}Pay Now{/ts} + {/if} + {if $action eq 2 and $lineItem and !$defaultContribution} @@ -111,7 +117,7 @@ - {if $buildRecurBlock} + {if $buildRecurBlock && !$contribID} @@ -152,7 +158,7 @@ {* 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} {$form.is_email_receipt.label} @@ -173,14 +179,16 @@ {/if} - {if !$contributionMode} + {if !$contributionMode || $contribID} {$form.contribution_status_id.label} {$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} + {/if} + {if !$contributionMode} {* Cancellation / Refunded fields are hidden unless contribution status is set to Cancelled or Refunded*}   @@ -213,7 +221,7 @@ {/if} - {if $form.revenue_recognition_date} + {if $form.revenue_recognition_date && !$contribID} {$form.revenue_recognition_date.label} {$form.revenue_recognition_date.html} diff --git a/tests/phpunit/WebTest/Contribute/UpdatePendingContributionTest.php b/tests/phpunit/WebTest/Contribute/UpdatePendingContributionTest.php index 3dcac2b548..edaee81c30 100644 --- a/tests/phpunit/WebTest/Contribute/UpdatePendingContributionTest.php +++ b/tests/phpunit/WebTest/Contribute/UpdatePendingContributionTest.php @@ -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'], ); -- 2.25.1