From 7126b55c40731f394977c48c8ea45eee27d98e40 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 4 May 2015 21:28:28 +1200 Subject: [PATCH] CRM-16357 (Backoffice contribution Form) reducing dependence on in processCreditCard --- CRM/Contribute/Form/Contribution.php | 26 +++++++++++-------- .../CRM/Contribute/Form/ContributionTest.php | 25 ++++++++++++++++++ 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 9bd51827e8..8d624a625f 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -1031,9 +1031,12 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP * @param array $submittedValues * @param array $lineItem * + * @param int $contactID + * Contact ID + * * @return bool|\CRM_Contribute_DAO_Contribution */ - protected function processCreditCard($submittedValues, $lineItem) { + protected function processCreditCard($submittedValues, $lineItem, $contactID) { $contribution = FALSE; $isTest = ($this->_mode == 'test') ? 1 : 0; @@ -1060,7 +1063,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP if ($this->_context == 'standalone' && !empty($submittedValues['is_email_receipt'])) { list($this->userDisplayName, $this->userEmail - ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID); + ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); $this->assign('displayName', $this->userDisplayName); } @@ -1092,10 +1095,10 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP unset($params['source']); } CRM_Contact_BAO_Contact::createProfileContact($params, $fields, - $this->_contactID, + $contactID, NULL, NULL, CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', - $this->_contactID, + $contactID, 'contact_type' ) ); @@ -1149,7 +1152,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP // all the payment processors expect the name and address to be in the // so we copy stuff over to first_name etc. $paymentParams = $this->_params; - $paymentParams['contactID'] = $this->_contactID; + $paymentParams['contactID'] = $contactID; CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE); $financialType = new CRM_Financial_DAO_FinancialType(); @@ -1180,7 +1183,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $contribution = CRM_Contribute_Form_Contribution_Confirm::processContribution($this, $this->_params, NULL, - $this->_contactID, + $contactID, $financialType, TRUE, FALSE, @@ -1203,7 +1206,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $message = ts("Payment Processor Error message") . $e->getMessage(); $this->cleanupDBAfterPaymentFailure($paymentParams, $message); // Set the contribution mode. - $urlParams = "action=add&cid={$this->_contactID}"; + $urlParams = "action=add&cid={$contactID}"; if ($this->_mode) { $urlParams .= "&mode={$this->_mode}"; } @@ -1259,22 +1262,23 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $this->_id, 'Contribution' ); + if (empty($paymentParams['is_recur'])) { $contribution = CRM_Contribute_Form_Contribution_Confirm::processContribution($this, $this->_params, $result, - $this->_contactID, + $contactID, $financialType, FALSE, FALSE, $isTest, - $this->_lineItem + $lineItem ); } // Send receipt mail. if ($contribution->id && !empty($this->_params['is_email_receipt'])) { $this->_params['trxn_id'] = CRM_Utils_Array::value('trxn_id', $result); - $this->_params['contact_id'] = $this->_contactID; + $this->_params['contact_id'] = $contactID; $this->_params['contribution_id'] = $contribution->id; if (CRM_Contribute_Form_AdditionalInfo::emailReceipt($this, $this->_params, TRUE)) { $this->statusMessage[] = ts('A receipt has been emailed to the contributor.'); @@ -1614,7 +1618,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP unset($formValues[$key]); } } - $contribution = $this->processCreditCard($formValues, $lineItem); + $contribution = $this->processCreditCard($formValues, $lineItem, $this->_contactID); foreach ($paramsSetByPaymentProcessingSubsystem as $key) { $formValues[$key] = $contribution->$key; } diff --git a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php index 3074235cbd..4266266907 100644 --- a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php @@ -182,6 +182,31 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase { $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1); } + /** + * Test the submit function on the contribution page. + */ + public function testSubmitCreditCardInvalidExpiry() { + $form = new CRM_Contribute_Form_Contribution(); + $form->testSubmit(array( + 'total_amount' => 50, + 'financial_type_id' => 1, + 'receive_date' => '04/21/2015', + 'receive_date_time' => '11:27PM', + 'contact_id' => $this->_individualId, + 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments), + 'payment_processor_id' => $this->paymentProcessor->id, + 'credit_card_exp_date' => array('M' => 5, 'Y' => 2012), + 'credit_card_number' => '411111111111111', + ), CRM_Core_Action::ADD, + 'live'); + $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1); + $lineItem = $this->callAPISuccessGetSingle('line_item', array()); + $this->assertEquals('50.00', $lineItem['unit_price']); + $this->assertEquals('50.00', $lineItem['line_total']); + $this->assertEquals(1, $lineItem['qty']); + $this->assertEquals(1, $lineItem['financial_type_id']); + } + /** * Test the submit function on the contribution page. */ -- 2.25.1