From 58466af14e29371c6367e71095fbc8b0c376fa30 Mon Sep 17 00:00:00 2001 From: jitendrapurohit Date: Thu, 1 Sep 2016 15:22:09 +0530 Subject: [PATCH] CRM-19263 - Online Pay Now Fix --- CRM/Admin/Form/Preferences/Contribute.php | 4 +- CRM/Contribute/BAO/Contribution/Utils.php | 1 + CRM/Contribute/Form/Contribution/Confirm.php | 5 + CRM/Contribute/Form/Contribution/Main.php | 93 ++++-- CRM/Contribute/Page/UserDashboard.php | 2 + .../CRM/Contribute/Form/Contribution/Main.tpl | 296 ++++++++++-------- .../CRM/Contribute/Page/UserDashboard.tpl | 14 +- .../phpunit/CiviTest/CiviSeleniumTestCase.php | 116 +++++++ .../WebTest/Contribute/AddPricesetTest.php | 116 ------- .../Contribute/OnlineContributionTest.php | 193 ++++++++++++ 10 files changed, 567 insertions(+), 273 deletions(-) diff --git a/CRM/Admin/Form/Preferences/Contribute.php b/CRM/Admin/Form/Preferences/Contribute.php index 3d484f7541..d8a1030388 100644 --- a/CRM/Admin/Form/Preferences/Contribute.php +++ b/CRM/Admin/Form/Preferences/Contribute.php @@ -248,7 +248,9 @@ class CRM_Admin_Form_Preferences_Contribute extends CRM_Admin_Form_Preferences { else { $setting = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($values['user_dashboard_options'], 1, -1)); $invoiceKey = array_search($setKey, $setting); - unset($setting[$invoiceKey]); + if (!empty($invoiceKey)) { + unset($setting[$invoiceKey]); + } $settingName = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_values($setting)) . CRM_Core_DAO::VALUE_SEPARATOR; diff --git a/CRM/Contribute/BAO/Contribution/Utils.php b/CRM/Contribute/BAO/Contribution/Utils.php index 89fbfa3495..2bd2b0881f 100644 --- a/CRM/Contribute/BAO/Contribution/Utils.php +++ b/CRM/Contribute/BAO/Contribution/Utils.php @@ -92,6 +92,7 @@ class CRM_Contribute_BAO_Contribution_Utils { if ($isPaymentTransaction) { $contributionParams = array( + 'id' => CRM_Utils_Array::value('contribution_id', $paymentParams), 'contact_id' => $contactID, 'line_item' => $lineItems, 'is_test' => $isTest, diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 7b2f88e2da..2cc2edc77f 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -186,6 +186,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr // lineItem isn't set until Register postProcess $this->_lineItem = $this->get('lineItem'); + $this->_ccid = $this->get('ccid'); $this->_paymentProcessor = $this->get('paymentProcessor'); $this->_params = $this->controller->exportValues('Main'); $this->_params['ip_address'] = CRM_Utils_System::ipAddress(); @@ -1939,6 +1940,10 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr if (isset($this->_params['payment_processor_id']) && $this->_params['payment_processor_id'] === 0) { $this->_params['is_pay_later'] = $isPayLater = TRUE; } + + if (!empty($this->_ccid)) { + $this->_params['contribution_id'] = $this->_ccid; + } // add a description field at the very beginning $this->_params['description'] = ts('Online Contribution') . ': ' . (($this->_pcpInfo['title']) ? $this->_pcpInfo['title'] : $this->_values['title']); diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index 9b9f4ad476..b3307f570c 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -62,11 +62,41 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu public function preProcess() { parent::preProcess(); + $this->_ccid = CRM_Utils_Request::retrieve('ccid', 'Positive', $this); $this->_paymentProcessors = $this->get('paymentProcessors'); $this->preProcessPaymentOptions(); + if (!empty($this->_ccid)) { + $payment = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_ccid, 'contribution'); + //bounce if the contribution is not pending. + if (empty($payment['balance'])) { + CRM_Core_Error::statusBounce(ts("Returning since contribution has already been handled.")); + } + if (!empty($payment['total'])) { + $this->_pendingAmount = $payment['total']; + $this->assign('pendingAmount', $this->_pendingAmount); + } + $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($this->_ccid); + foreach (array_keys($lineItems) as $id) { + $lineItems[$id]['id'] = $id; + } + $itemId = key($lineItems); + if ($itemId && !empty($lineItems[$itemId]['price_field_id'])) { + $this->_priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $lineItems[$itemId]['price_field_id'], 'price_set_id'); + } + + if (!empty($lineItems[$itemId]['price_field_id'])) { + $this->_lineItem[$this->_priceSetId] = $lineItems; + } + $isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config'); + $this->assign('lineItem', $this->_lineItem); + $this->assign('is_quick_config', $isQuickConfig); + $this->assign('priceSetID', $this->_priceSetId); + } + // Make the contributionPageID available to the template $this->assign('contributionPageID', $this->_id); + $this->assign('ccid', $this->_ccid); $this->assign('isShare', CRM_Utils_Array::value('is_share', $this->_values)); $this->assign('isConfirmEnabled', CRM_Utils_Array::value('is_confirm_enabled', $this->_values)); @@ -127,6 +157,9 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu $billingDefaults = $this->getProfileDefaults('Billing', $contactID); $this->_defaults = array_merge($this->_defaults, $billingDefaults); } + if (!empty($this->_ccid) && !empty($this->_pendingAmount)) { + $this->_defaults['total_amount'] = $this->_pendingAmount; + } /* * hack to simplify credit card entry for testing @@ -306,12 +339,23 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu } $this->applyFilter('__ALL__', 'trim'); - $this->add('text', "email-{$this->_bltID}", - ts('Email Address'), - array('size' => 30, 'maxlength' => 60, 'class' => 'email'), - TRUE - ); - $this->addRule("email-{$this->_bltID}", ts('Email is not valid.'), 'email'); + $hidePayLater = FALSE; + if (empty($this->_ccid)) { + $this->add('text', "email-{$this->_bltID}", + ts('Email Address'), + array('size' => 30, 'maxlength' => 60, 'class' => 'email'), + TRUE + ); + $this->addRule("email-{$this->_bltID}", ts('Email is not valid.'), 'email'); + } + else { + $this->addElement('hidden', "email-{$this->_bltID}", 1); + $this->add('text', 'total_amount', ts('Total Amount'), array('readonly' => TRUE), FALSE); + if (!empty($this->_paymentProcessors[0])) { + $hidePayLater = TRUE; + } + } + $this->assign('hidePayLater', $hidePayLater); $pps = array(); //@todo - this should be replaced by a check as to whether billing fields are set $onlinePaymentProcessorEnabled = FALSE; @@ -350,7 +394,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu //build pledge block. $this->_useForMember = 0; //don't build membership block when pledge_id is passed - if (empty($this->_values['pledge_id'])) { + if (empty($this->_values['pledge_id']) && empty($this->_ccid)) { $this->_separateMembershipPayment = FALSE; if (in_array('CiviMember', $config->enableComponents)) { $isTest = 0; @@ -381,7 +425,9 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu $this->add('hidden', 'priceSetId', $this->_priceSetId); // build price set form. $this->set('priceSetId', $this->_priceSetId); - CRM_Price_BAO_PriceSet::buildPriceSet($this); + if (empty($this->_ccid)) { + CRM_Price_BAO_PriceSet::buildPriceSet($this); + } if ($this->_values['is_monetary'] && $this->_values['is_recur'] && empty($this->_values['pledge_id']) ) { @@ -389,7 +435,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu } } - if ($this->_priceSetId) { + if ($this->_priceSetId && empty($this->_ccid)) { $is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config'); if ($is_quick_config) { $this->_useForMember = 0; @@ -398,12 +444,12 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu } //we allow premium for pledge during pledge creation only. - if (empty($this->_values['pledge_id'])) { + if (empty($this->_values['pledge_id']) && empty($this->_ccid)) { CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, TRUE); } //don't build pledge block when mid is passed - if (!$this->_mid) { + if (!$this->_mid && empty($this->_ccid)) { $config = CRM_Core_Config::singleton(); if (in_array('CiviPledge', $config->enableComponents) && !empty($this->_values['pledge_block_id'])) { CRM_Pledge_BAO_PledgeBlock::buildPledgeBlock($this); @@ -411,7 +457,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu } //to create an cms user - if (!$this->_contactID) { + if (!$this->_contactID && empty($this->_ccid)) { $createCMSUser = FALSE; if ($this->_values['custom_pre_id']) { @@ -441,7 +487,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu CRM_Core_BAO_CMSUser::buildForm($this, $profileID, TRUE); } } - if ($this->_pcpId) { + if ($this->_pcpId && empty($this->_ccid)) { if ($pcpSupporter = CRM_PCP_BAO_PCP::displayName($this->_pcpId)) { $pcp_supporter_text = ts('This contribution is being made thanks to the effort of %1, who supports our campaign.', array(1 => $pcpSupporter)); // Only tell people that can also create a PCP if the contribution page has a non-empty value in the "Create Personal Campaign Page link" field. @@ -468,7 +514,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu $this->add('textarea', 'pcp_personal_note', ts('Personal Note'), array('style' => 'height: 3em; width: 40em;')); } } - if (empty($this->_values['fee'])) { + if (empty($this->_values['fee']) && empty($this->_ccid)) { CRM_Core_Error::fatal(ts('This page does not have any price fields configured or you may not have permission for them. Please contact the site administrator for more details.')); } @@ -620,7 +666,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu } //check for atleast one pricefields should be selected - if (!empty($fields['priceSetId'])) { + if (!empty($fields['priceSetId']) && empty($self->_ccid)) { $priceField = new CRM_Price_DAO_PriceField(); $priceField->price_set_id = $fields['priceSetId']; $priceField->orderBy('weight'); @@ -737,7 +783,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu $errors["price_{$errorKey}"] = ts('Additional Contribution is required.'); } } - if (empty($check)) { + if (empty($check) && empty($self->_ccid)) { if ($self->_useForMember == 1 && $membershipIsActive) { $errors['_qf_default'] = ts('Select at least one option from Membership Type(s).'); } @@ -1048,8 +1094,14 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu } } } - // from here on down, $params['amount'] holds a monetary value (or null) rather than an option ID - $params['amount'] = self::computeAmount($params, $this->_values); + + if (!empty($this->_ccid) && !empty($this->_pendingAmount)) { + $params['amount'] = $this->_pendingAmount; + } + else { + // from here on down, $params['amount'] holds a monetary value (or null) rather than an option ID + $params['amount'] = self::computeAmount($params, $this->_values); + } $params['separate_amount'] = $params['amount']; $memFee = NULL; @@ -1099,7 +1151,10 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu $this->set('amount_level', CRM_Utils_Array::value('amount_level', $params)); } - if ($priceSetId = CRM_Utils_Array::value('priceSetId', $params)) { + if ($this->_ccid) { + $this->set('lineItem', $this->_lineItem); + } + elseif ($priceSetId = CRM_Utils_Array::value('priceSetId', $params)) { $lineItem = array(); $is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config'); if ($is_quick_config) { diff --git a/CRM/Contribute/Page/UserDashboard.php b/CRM/Contribute/Page/UserDashboard.php index 05f2b6dc99..bf4fb7387e 100644 --- a/CRM/Contribute/Page/UserDashboard.php +++ b/CRM/Contribute/Page/UserDashboard.php @@ -141,7 +141,9 @@ class CRM_Contribute_Page_UserDashboard extends CRM_Contact_Page_View_UserDashBo public function run() { $invoiceSettings = Civi::settings()->get('contribution_invoice_settings'); $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings); + $defaultInvoicePage = CRM_Utils_Array::value('default_invoice_page', $invoiceSettings); $this->assign('invoicing', $invoicing); + $this->assign('defaultInvoicePage', $defaultInvoicePage); parent::preProcess(); $this->listContribution(); } diff --git a/templates/CRM/Contribute/Form/Contribution/Main.tpl b/templates/CRM/Contribute/Form/Contribution/Main.tpl index 17a430dab5..3121b9da89 100644 --- a/templates/CRM/Contribute/Form/Contribution/Main.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Main.tpl @@ -24,7 +24,7 @@ +--------------------------------------------------------------------+ *} {* Callback snippet: On-behalf profile *} -{if $snippet and !empty($isOnBehalfCallback)} +{if $snippet and !empty($isOnBehalfCallback) and !$ccid}
{include file="CRM/Contribute/Form/Contribution/OnBehalfOf.tpl" context="front-end"}
@@ -70,7 +70,7 @@
- {if $contact_id} + {if $contact_id && !$ccid} @@ -84,17 +84,31 @@
{ts}You have a current Lifetime Membership which does not need to be renewed.{/ts}
{/if} - {if !empty($useForMember)} -
- {include file="CRM/Contribute/Form/Contribution/MembershipBlock.tpl" context="makeContribution"} -
+ {if !empty($useForMember) && !$ccid} +
+ {include file="CRM/Contribute/Form/Contribution/MembershipBlock.tpl" context="makeContribution"} +
+ {elseif !empty($ccid)} + {if $lineItem && $priceSetID && !$is_quick_config} +
+ {ts}Contribution Information{/ts} +
+ {assign var="totalAmount" value=$pendingAmount} + {include file="CRM/Price/Page/LineItem.tpl" context="Contribution"} {else} -
- {include file="CRM/Price/Form/PriceSet.tpl" extends="Contribution"} -
+
+ {$form.total_amount.label} + {$form.total_amount.html|crmMoney} +
+ {/if} + {else} +
+ {include file="CRM/Price/Form/PriceSet.tpl" extends="Contribution"} +
{/if} - {crmRegion name='contribution-main-pledge-block'} + {if !$ccid} + {crmRegion name='contribution-main-pledge-block'} {if $pledgeBlock} {if $is_pledge_payment}
@@ -102,151 +116,154 @@
{$form.pledge_amount.html}
- {else} -
-
 
-
- {$form.is_pledge.html}  - {if $is_pledge_interval} - {$form.pledge_frequency_interval.html}  + {else} +
+
 
+
+ {$form.is_pledge.html}  + {if $is_pledge_interval} + {$form.pledge_frequency_interval.html}  + {/if} + {$form.pledge_frequency_unit.html} {ts}for{/ts} {$form.pledge_installments.html} {ts}installments.{/ts} +
+
+ {if $start_date_editable} + {if $is_date} +
{$form.start_date.label}
{include file="CRM/common/jcalendar.tpl" elementName=start_date}
+ {else} +
{$form.start_date.label}
{$form.start_date.html}
+ {/if} + {else} +
{$form.start_date.label}
+
{$start_date_display|date_format}
{/if} - {$form.pledge_frequency_unit.html} {ts}for{/ts} {$form.pledge_installments.html} {ts}installments.{/ts} -
-
- {if $start_date_editable} - {if $is_date} -
{$form.start_date.label}
{include file="CRM/common/jcalendar.tpl" elementName=start_date}
- {else} -
{$form.start_date.label}
{$form.start_date.html}
- {/if} - {else} -
{$form.start_date.label}
-
{$start_date_display|date_format}
- {/if}
-
+
{/if} {/if} - {/crmRegion} - - {if $form.is_recur} -
-
 
-
- {$form.is_recur.html} {$form.is_recur.label} {ts}every{/ts} - {if $is_recur_interval} - {$form.frequency_interval.html} - {/if} - {if $one_frequency_unit} - {$frequency_unit} - {else} - {$form.frequency_unit.html} - {/if} - {if $is_recur_installments} - - {ts}for{/ts} {$form.installments.html} {$form.installments.label} - - {/if} -
- {ts}Your recurring contribution will be processed automatically.{/ts} - {if $is_recur_installments} - {ts}You can specify the number of installments, or you can leave the number of installments blank if you want to make an open-ended commitment. In either case, you can choose to cancel at any time.{/ts} + {/crmRegion} + + {if $form.is_recur} +
+
 
+
+ {$form.is_recur.html} {$form.is_recur.label} {ts}every{/ts} + {if $is_recur_interval} + {$form.frequency_interval.html} {/if} - {if $is_email_receipt} - {ts}You will receive an email receipt for each recurring contribution.{/ts} + {if $one_frequency_unit} + {$frequency_unit} + {else} + {$form.frequency_unit.html} {/if} + {if $is_recur_installments} + + {ts}for{/ts} {$form.installments.html} {$form.installments.label} + + {/if} +
+ {ts}Your recurring contribution will be processed automatically.{/ts} + {if $is_recur_installments} + {ts}You can specify the number of installments, or you can leave the number of installments blank if you want to make an open-ended commitment. In either case, you can choose to cancel at any time.{/ts} + {/if} + {if $is_email_receipt} + {ts}You will receive an email receipt for each recurring contribution.{/ts} + {/if} +
+
-
-
- {/if} - {if $pcpSupporterText} -
-
 
-
{$pcpSupporterText}
-
-
- {/if} - {assign var=n value=email-$bltID} -
-
{$form.$n.label}
-
- {$form.$n.html} + {/if} + {if $pcpSupporterText} +
+
 
+
{$pcpSupporterText}
+
+
+ {/if} + {assign var=n value=email-$bltID} +
+
{$form.$n.label}
+
+ {$form.$n.html} +
+
-
-
-
- {include file="CRM/Contribute/Form/Contribution/OnBehalfOf.tpl"} -
+
+ {include file="CRM/Contribute/Form/Contribution/OnBehalfOf.tpl"} +
- {* User account registration option. Displays if enabled for one of the profiles on this page. *} -
- {include file="CRM/common/CMSUser.tpl"} -
-
- {include file="CRM/Contribute/Form/Contribution/PremiumBlock.tpl" context="makeContribution"} -
+ {* User account registration option. Displays if enabled for one of the profiles on this page. *} +
+ {include file="CRM/common/CMSUser.tpl"} +
+
+ {include file="CRM/Contribute/Form/Contribution/PremiumBlock.tpl" context="makeContribution"} +
- {if $honoreeProfileFields|@count} -
- {crmRegion name="contribution-soft-credit-block"} - {$honor_block_title} -
- {$honor_block_text} -
- {if $form.soft_credit_type_id.html} -
-
- {$form.soft_credit_type_id.html} -
{ts}Select an option to reveal honoree information fields.{/ts}
-
+ {if $honoreeProfileFields|@count} +
+ {crmRegion name="contribution-soft-credit-block"} + {$honor_block_title} +
+ {$honor_block_text}
- {/if} - {/crmRegion} -
- {include file="CRM/UF/Form/Block.tpl" fields=$honoreeProfileFields mode=8 prefix='honor'} -
-
- {/if} + {if $form.soft_credit_type_id.html} +
+
+ {$form.soft_credit_type_id.html} +
{ts}Select an option to reveal honoree information fields.{/ts}
+
+
+ {/if} + {/crmRegion} +
+ {include file="CRM/UF/Form/Block.tpl" fields=$honoreeProfileFields mode=8 prefix='honor'} +
+
+ {/if} -
- {include file="CRM/UF/Form/Block.tpl" fields=$customPre} -
+
+ {include file="CRM/UF/Form/Block.tpl" fields=$customPre} +
- {if $isHonor} -
-
-
-
- {$form.pcp_display_in_roll.html}   - {$form.pcp_display_in_roll.label} + {if $isHonor} +
+
+
+
+ {$form.pcp_display_in_roll.html}   + {$form.pcp_display_in_roll.label} +
+
-
-
-
-
- {$form.pcp_is_anonymous.html} +
+
+ {$form.pcp_is_anonymous.html} +
+
-
-
-
-
{$form.pcp_roll_nickname.label}
-
{$form.pcp_roll_nickname.html} -
{ts}Enter the name you want listed with this contribution. You can use a nick name like 'The Jones Family' or 'Sarah and Sam'.{/ts}
+
+
{$form.pcp_roll_nickname.label}
+
{$form.pcp_roll_nickname.html} +
{ts}Enter the name you want listed with this contribution. You can use a nick name like 'The Jones Family' or 'Sarah and Sam'.{/ts}
+
+
-
-
-
-
{$form.pcp_personal_note.label}
-
- {$form.pcp_personal_note.html} -
{ts}Enter a message to accompany this contribution.{/ts}
+
+
{$form.pcp_personal_note.label}
+
+ {$form.pcp_personal_note.html} +
{ts}Enter a message to accompany this contribution.{/ts}
+
+
-
-
-
+
+ {/if} + + {* end of ccid loop *} {/if} {if $form.payment_processor_id.label} @@ -310,6 +327,10 @@ pcpAnonymous(); {/if} + {if $hidePayLater} + hidePayLater(); + {/if} + {literal} cj('input[name="soft_credit_type_id"]').on('change', function() { @@ -326,6 +347,11 @@ } } + function hidePayLater() { + cj('input:radio[name="payment_processor_id"][value=0]').hide(); + cj('input:radio[name="payment_processor_id"][value=0]').next('label').hide(); + } + cj('input[id="is_recur"]').on('change', function() { toggleRecur(); }); diff --git a/templates/CRM/Contribute/Page/UserDashboard.tpl b/templates/CRM/Contribute/Page/UserDashboard.tpl index c1f0465e75..ccff113cde 100644 --- a/templates/CRM/Contribute/Page/UserDashboard.tpl +++ b/templates/CRM/Contribute/Page/UserDashboard.tpl @@ -34,7 +34,10 @@ {ts}Receipt Sent{/ts} {ts}Status{/ts} {if $invoicing && $invoices} - + + {/if} + {if $invoicing && $defaultInvoicePage} + {/if} @@ -57,7 +60,7 @@ {assign var='contact_id' value=$row.contact_id} {assign var='urlParams' value="reset=1&id=$id&cid=$contact_id"} {if call_user_func(array('CRM_Core_Permission','check'), 'view my invoices') OR call_user_func(array('CRM_Core_Permission','check'), 'access CiviContribute')} - {if $row.contribution_status != 'Refunded' && $row.contribution_status != 'Cancelled' } @@ -69,6 +72,13 @@ {/if} {/if} + {if $defaultInvoicePage && $row.contribution_status == 'Pending (Pay Later)'} + + {assign var='id' value=$row.contribution_id} + {capture assign=payNowLink}{crmURL p='civicrm/contribute/transact' q="reset=1&id=`$defaultInvoicePage`&ccid=`$id`"}{/capture} + {ts}Pay Now{/ts} + + {/if} {/foreach} diff --git a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php index b166e1c6a1..349c63bccb 100644 --- a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php +++ b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php @@ -1961,6 +1961,122 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { $this->waitForElementPresent('link=Add Financial Account'); } + /** + * @param $setTitle + * @param $usedFor + * @param $setHelp + * @param null $financialType + */ + public function _testAddSet($setTitle, $usedFor, $setHelp, $financialType = NULL) { + $this->openCiviPage("admin/price", "reset=1&action=add", '_qf_Set_next-bottom'); + + // Enter Priceset fields (Title, Used For ...) + $this->type('title', $setTitle); + if ($usedFor == 'Event') { + $this->check('extends_1'); + } + elseif ($usedFor == 'Contribution') { + $this->check('extends_2'); + } + + if ($financialType) { + $this->select("financial_type_id", "label={$financialType}"); + } + $this->type('help_pre', $setHelp); + + $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.'); + $this->clickLink('_qf_Set_next-bottom'); + } + + /** + * @param $fields + * @param $validateString + * @param $financialType + * @param bool $dateSpecificFields + */ + public function _testAddPriceFields(&$fields, &$validateString, $financialType, $dateSpecificFields = FALSE) { + $validateStrings[] = $financialType; + $sid = $this->urlArg('sid'); + $this->openCiviPage('admin/price/field', "reset=1&action=add&sid=$sid", 'label'); + foreach ($fields as $label => $type) { + $validateStrings[] = $label; + + $this->type('label', $label); + $this->select('html_type', "value={$type}"); + + switch ($type) { + case 'Text': + $validateStrings[] = '525.00'; + $this->type('price', '525.00'); + if ($dateSpecificFields == TRUE) { + $this->webtestFillDateTime('active_on', '+1 week'); + } + else { + $this->check('is_required'); + } + break; + + case 'Select': + $options = array( + 1 => array( + 'label' => 'Chicken', + 'amount' => '30.00', + ), + 2 => array( + 'label' => 'Vegetarian', + 'amount' => '25.00', + ), + ); + $this->addMultipleChoiceOptions($options, $validateStrings); + if ($dateSpecificFields == TRUE) { + $this->webtestFillDateTime('expire_on', '-1 week'); + } + break; + + case 'Radio': + $options = array( + 1 => array( + 'label' => 'Yes', + 'amount' => '50.00', + ), + 2 => array( + 'label' => 'No', + 'amount' => '0', + ), + ); + $this->addMultipleChoiceOptions($options, $validateStrings); + $this->check('is_required'); + if ($dateSpecificFields == TRUE) { + $this->webtestFillDateTime('active_on', '-1 week'); + } + break; + + case 'CheckBox': + $options = array( + 1 => array( + 'label' => 'First Night', + 'amount' => '15.00', + ), + 2 => array( + 'label' => 'Second Night', + 'amount' => '15.00', + ), + ); + $this->addMultipleChoiceOptions($options, $validateStrings); + if ($dateSpecificFields == TRUE) { + $this->webtestFillDateTime('expire_on', '+1 week'); + } + break; + + default: + break; + } + $this->select('financial_type_id', "label={$financialType}"); + $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom', FALSE); + $this->waitForText('crm-notification-container', "Price Field '$label' has been saved."); + } + } + /** * Delete Financial Account. * @param $financialAccountTitle diff --git a/tests/phpunit/WebTest/Contribute/AddPricesetTest.php b/tests/phpunit/WebTest/Contribute/AddPricesetTest.php index 34f1d7ee0d..3d50933580 100644 --- a/tests/phpunit/WebTest/Contribute/AddPricesetTest.php +++ b/tests/phpunit/WebTest/Contribute/AddPricesetTest.php @@ -68,122 +68,6 @@ class WebTest_Contribute_AddPricesetTest extends CiviSeleniumTestCase { $this->_testVerifyPriceSet($validateStrings, $sid); } - /** - * @param $setTitle - * @param $usedFor - * @param $setHelp - * @param null $financialType - */ - public function _testAddSet($setTitle, $usedFor, $setHelp, $financialType = NULL) { - $this->openCiviPage("admin/price", "reset=1&action=add", '_qf_Set_next-bottom'); - - // Enter Priceset fields (Title, Used For ...) - $this->type('title', $setTitle); - if ($usedFor == 'Event') { - $this->check('extends_1'); - } - elseif ($usedFor == 'Contribution') { - $this->check('extends_2'); - } - - if ($financialType) { - $this->select("financial_type_id", "label={$financialType}"); - } - $this->type('help_pre', $setHelp); - - $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.'); - $this->clickLink('_qf_Set_next-bottom'); - } - - /** - * @param $fields - * @param $validateString - * @param $financialType - * @param bool $dateSpecificFields - */ - public function _testAddPriceFields(&$fields, &$validateString, $financialType, $dateSpecificFields = FALSE) { - $validateStrings[] = $financialType; - $sid = $this->urlArg('sid'); - $this->openCiviPage('admin/price/field', "reset=1&action=add&sid=$sid", 'label'); - foreach ($fields as $label => $type) { - $validateStrings[] = $label; - - $this->type('label', $label); - $this->select('html_type', "value={$type}"); - - switch ($type) { - case 'Text': - $validateStrings[] = '525.00'; - $this->type('price', '525.00'); - if ($dateSpecificFields == TRUE) { - $this->webtestFillDateTime('active_on', '+1 week'); - } - else { - $this->check('is_required'); - } - break; - - case 'Select': - $options = array( - 1 => array( - 'label' => 'Chicken', - 'amount' => '30.00', - ), - 2 => array( - 'label' => 'Vegetarian', - 'amount' => '25.00', - ), - ); - $this->addMultipleChoiceOptions($options, $validateStrings); - if ($dateSpecificFields == TRUE) { - $this->webtestFillDateTime('expire_on', '-1 week'); - } - break; - - case 'Radio': - $options = array( - 1 => array( - 'label' => 'Yes', - 'amount' => '50.00', - ), - 2 => array( - 'label' => 'No', - 'amount' => '0', - ), - ); - $this->addMultipleChoiceOptions($options, $validateStrings); - $this->check('is_required'); - if ($dateSpecificFields == TRUE) { - $this->webtestFillDateTime('active_on', '-1 week'); - } - break; - - case 'CheckBox': - $options = array( - 1 => array( - 'label' => 'First Night', - 'amount' => '15.00', - ), - 2 => array( - 'label' => 'Second Night', - 'amount' => '15.00', - ), - ); - $this->addMultipleChoiceOptions($options, $validateStrings); - if ($dateSpecificFields == TRUE) { - $this->webtestFillDateTime('expire_on', '+1 week'); - } - break; - - default: - break; - } - $this->select('financial_type_id', "label={$financialType}"); - $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom', FALSE); - $this->waitForText('crm-notification-container', "Price Field '$label' has been saved."); - } - } - /** * @return string */ diff --git a/tests/phpunit/WebTest/Contribute/OnlineContributionTest.php b/tests/phpunit/WebTest/Contribute/OnlineContributionTest.php index 59f40ca743..e52ffdcc1c 100644 --- a/tests/phpunit/WebTest/Contribute/OnlineContributionTest.php +++ b/tests/phpunit/WebTest/Contribute/OnlineContributionTest.php @@ -505,4 +505,197 @@ class WebTest_Contribute_OnlineContributionTest extends CiviSeleniumTestCase { $this->webtestVerifyTabularData($expected); } + public function testOnlineContributionWithPayNowLink() { + $this->webtestLogin(); + $pageId = 1; + $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", 'is_pay_later'); + $this->check('is_pay_later'); + $this->type('pay_later_text', "I will send payment by check"); + $this->fillRichTextField('pay_later_receipt', "I will send payment by check"); + $this->clickLink("_qf_Amount_upload_done-bottom"); + + //add financial type of account type expense + $financialType = 'Donation'; + $setTitle = 'Conference Fees - ' . substr(sha1(rand()), 0, 7); + $usedFor = 'Contribution'; + $setHelp = 'Select your conference options.'; + $this->_testAddSet($setTitle, $usedFor, $setHelp, $financialType); + $sid = $this->urlArg('sid'); + + $validateStrings = array(); + $fields = array( + 'Full Conference' => 'Text', + 'Meal Choice' => 'Select', + 'Pre-conference Meetup?' => 'Radio', + 'Evening Sessions' => 'CheckBox', + ); + + $this->_testAddPriceFields($fields, $validateStrings, $financialType); + + //Add profile Details + $firstName = 'Ma' . substr(sha1(rand()), 0, 4); + $lastName = 'An' . substr(sha1(rand()), 0, 7); + $name = $this->_testCreateUser($firstName, $lastName); + $this->openCiviPage("admin/synchUser", "reset=1", NULL); + $this->clickLink("_qf_CMSUser_next-bottom"); + + $this->openCiviPage("admin/setting/preferences/contribute", "reset=1", "deferred_revenue_enabled"); + $this->check('deferred_revenue_enabled'); + $this->waitForElementPresent('default_invoice_page'); + $this->select('default_invoice_page', "value=$pageId"); + $this->clickLink("_qf_Contribute_next-bottom"); + + $this->webtestLogin($name, "Test12345"); + $this->_testContributeWithPayLater($pageId, $firstName); + + $this->_testContributeWithPayNow($firstName); + + $this->openCiviPage("user", "reset=1"); + $this->assertFalse($this->isTextPresent("Pay Now")); + + $this->webtestLogin(); + + $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", 'price_set_id'); + $this->select('price_set_id', "value=9"); + $this->clickLink("_qf_Amount_upload_done-bottom"); + + $this->webtestLogin($name, "Test12345"); + + $this->_testContributeWithPayLater($pageId, $firstName, TRUE); + + $this->_testContributeWithPayNow($firstName, TRUE); + + $this->openCiviPage("user", "reset=1"); + $this->assertFalse($this->isTextPresent("Pay Now")); + + // Type search name in autocomplete. + $this->webtestLogin(); + $this->openCiviPage("civicrm/dashboard", "reset=1", 'sort_name_navigation'); + $this->click('sort_name_navigation'); + $this->type('css=input#sort_name_navigation', $firstName); + $this->typeKeys('css=input#sort_name_navigation', $firstName); + $this->waitForElementPresent("css=ul.ui-autocomplete li"); + $this->clickLink("css=ul.ui-autocomplete li", 'tab_contribute'); + + $this->click('css=li#tab_contribute a'); + $this->waitForElementPresent('link=Record Contribution (Check, Cash, EFT ...)'); + + $amountValues = array( + 1 => '$ 588.50', + 2 => '$ 98.50', + ); + foreach($amountValues as $row => $amount) { + $this->clickLink("xpath=//table[@class='selector row-highlight']/tbody/tr[{$row}]/td[8]/span//a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE); + + // View Contribution Record and test for expected values + $expected = array( + 'From' => "{$firstName} {$lastName}", + 'Financial Type' => $financialType, + 'Fee Amount' => '$ 1.50', + 'Net Amount' => $amount, + 'Received Into' => 'Payment Processor Account', + 'Payment Method' => 'Credit Card (Test Processor)', + 'Contribution Status' => 'Completed', + ); + $this->webtestVerifyTabularData($expected); + + $this->clickAjaxLink("xpath=//span[text()='Done']"); + } + } + + public function _testContributeWithPayNow($firstName, $priceSet = FALSE) { + //user dashboard + $this->openCiviPage("user", "reset=1"); + $this->waitForElementPresent("xpath=//a/span[contains(text(), 'Pay Now')]"); + $this->clickLink("xpath=//a/span[contains(text(), 'Pay Now')]"); + + if (empty($priceSet)) { + $this->waitForElementPresent("total_amount"); + $this->assertTrue($this->isElementPresent("xpath=//input[@id='total_amount'][@readonly=1][@value=100]")); + } + else { + $this->assertElementContainsText("xpath=//div[@class='header-dark']", "Contribution Information"); + $this->assertElementContainsText("xpath=//div[@class='crm-section no-label total_amount-section']", "Contribution Total: $ 590.00"); + } + + $this->assertFalse($this->isElementPresent("priceset")); + $this->assertFalse($this->isElementPresent("xpath=//div[@class='crm-public-form-item crm-section is_pledge-section']")); + $this->assertFalse($this->isElementPresent("xpath=//div[@class='crm-public-form-item crm-section premium_block-section']")); + $this->assertFalse($this->isElementPresent("xpath=//div[@class='crm-public-form-item crm-group custom_pre_profile-group']")); + $this->assertFalse($this->isElementPresent("xpath=//input[@id=email-5]")); + $this->assertTrue($this->isElementPresent("xpath=//input[@name='payment_processor_id'][@value=0][@style='display: none;']")); + $this->click("xpath=//input[@name='payment_processor_id'][@value=1]"); + $this->waitForAjaxContent(); + + $this->webtestAddCreditCardDetails(); + $this->webtestAddBillingDetails(); + $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom"); + + $this->clickLink("_qf_Confirm_next-bottom"); + $firstName = strtolower($firstName); + $emailText = "An email receipt has also been sent to {$firstName}@example.com"; + $this->waitForTextPresent($emailText); + + } + + public function _testContributeWithPayLater($pageId, $firstName, $priceSet = FALSE) { + $this->openCiviPage("contribute/transact", "reset=1&action=preview&id=$pageId", NULL); + $this->waitForElementPresent("email-5"); + + $this->type("email-5", $firstName . "@example.com"); + + if (empty($priceSet)) { + $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input"); + $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 100); + $this->typeKeys("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 100); + } + else { + $this->type("xpath=//input[@class='four crm-form-text required']", "1"); + $this->click("xpath=//input[@class='crm-form-radio']"); + $this->click("xpath=//input[@class='crm-form-checkbox']"); + } + + $this->waitForTextPresent("Payment Method"); + $payLaterText = "I will send payment by check"; + $this->click("xpath=//label[text() = '{$payLaterText}']/preceding-sibling::input[1]"); + + $this->waitForAjaxContent(); + $this->clickLink("_qf_Main_upload-bottom"); + $this->waitForElementPresent("xpath=//div[@class='bold pay_later_receipt-section']"); + + $payLaterInstructionsText = "I will send payment by check"; + $this->assertElementContainsText("xpath=//div[@class='bold pay_later_receipt-section']/p", $payLaterInstructionsText); + $this->clickLink("_qf_Confirm_next-bottom"); + + $this->waitForElementPresent("xpath=//div[@class='help']/div/p"); + $this->assertElementContainsText("xpath=//div[@class='help']/div/p", $payLaterInstructionsText); + } + + public function _testCreateUser($firstName, $lastName) { + $this->open($this->sboxPath . "admin/people/create"); + + $this->waitForElementPresent("edit-submit"); + + $name = "TestUser" . substr(sha1(rand()), 0, 4); + $this->type("edit-name", $name); + + $emailId = substr(sha1(rand()), 0, 7) . '@web.com'; + $this->type("edit-mail", $emailId); + $this->type("edit-pass-pass1", "Test12345"); + $this->type("edit-pass-pass2", "Test12345"); + + $this->type("first_name", $firstName); + $this->type("last_name", $lastName); + + //Address Details + $this->type("street_address-1", "902C El Camino Way SW"); + $this->type("city-1", "Dumfries"); + $this->type("postal_code-1", "1234"); + $this->select("state_province-1", "value=1019"); + + $this->click("edit-submit"); + $this->waitForPageToLoad($this->getTimeoutMsec()); + return $name; + } + } -- 2.25.1