Commit | Line | Data |
---|---|---|
e3fceb1a | 1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
2fe49090 | 4 | | CiviCRM version 5 | |
e3fceb1a | 5 | +--------------------------------------------------------------------+ |
f299f7db | 6 | | Copyright CiviCRM LLC (c) 2004-2020 | |
e3fceb1a | 7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * Test APIv3 civicrm_contribute_* functions | |
30 | * | |
31 | * @package CiviCRM_APIv3 | |
32 | * @subpackage API_Contribution | |
33 | * @group headless | |
34 | */ | |
35 | class CRM_Contribute_Form_Contribution_ConfirmTest extends CiviUnitTestCase { | |
36 | ||
37 | /** | |
38 | * Clean up DB. | |
39 | */ | |
40 | public function tearDown() { | |
41 | $this->quickCleanUpFinancialEntities(); | |
42 | } | |
43 | ||
44 | /** | |
45 | * CRM-21200: Test that making online payment for pending contribution doesn't overwite the contribution details | |
46 | */ | |
47 | public function testPaynowPayment() { | |
48 | $contactID = $this->individualCreate(); | |
9099cab3 | 49 | $paymentProcessorID = $this->paymentProcessorCreate(['payment_processor_type_id' => 'Dummy']); |
e3fceb1a | 50 | |
51 | // create a contribution page which is later used to make pay-later contribution | |
9099cab3 | 52 | $result = $this->callAPISuccess('ContributionPage', 'create', [ |
e3fceb1a | 53 | 'title' => 'Test Contribution Page', |
54 | 'financial_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Campaign Contribution'), | |
55 | 'currency' => 'USD', | |
56 | 'financial_account_id' => 1, | |
57 | 'payment_processor' => $paymentProcessorID, | |
58 | 'is_active' => 1, | |
59 | 'is_allow_other_amount' => 1, | |
60 | 'min_amount' => 20, | |
61 | 'max_amount' => 2000, | |
9099cab3 | 62 | ]); |
e3fceb1a | 63 | $contributionPageID1 = $result['id']; |
64 | // create pending contribution | |
9099cab3 | 65 | $contribution = $this->callAPISuccess('Contribution', 'create', [ |
e3fceb1a | 66 | 'contact_id' => $contactID, |
67 | 'financial_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Campaign Contribution'), | |
68 | 'currency' => 'USD', | |
69 | 'total_amount' => 100.00, | |
70 | 'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'), | |
71 | 'contribution_page_id' => $contributionPageID1, | |
72 | 'source' => 'backoffice pending contribution', | |
9099cab3 | 73 | ]); |
e3fceb1a | 74 | |
75 | // create a contribution page which is later used to make online payment for pending contribution | |
9099cab3 | 76 | $result = $this->callAPISuccess('ContributionPage', 'create', [ |
e3fceb1a | 77 | 'title' => 'Test Contribution Page', |
78 | 'financial_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', 'Campaign Contribution'), | |
79 | 'currency' => 'USD', | |
80 | 'financial_account_id' => 1, | |
81 | 'payment_processor' => $paymentProcessorID, | |
82 | 'is_active' => 1, | |
83 | 'is_allow_other_amount' => 1, | |
84 | 'min_amount' => 10, | |
85 | 'max_amount' => 1000, | |
9099cab3 | 86 | ]); |
e3fceb1a | 87 | $form = new CRM_Contribute_Form_Contribution_Confirm(); |
88 | $contributionPageID2 = $result['id']; | |
89 | $form->_id = $contributionPageID2; | |
90 | $form->_values = $result['values'][$contributionPageID2]; | |
9099cab3 | 91 | $form->_paymentProcessor = [ |
e3fceb1a | 92 | 'id' => $paymentProcessorID, |
93 | 'billing_mode' => CRM_Core_Payment::BILLING_MODE_FORM, | |
94 | 'object' => Civi\Payment\System::singleton()->getById($paymentProcessorID), | |
95 | 'is_recur' => FALSE, | |
96 | 'payment_instrument_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Credit card'), | |
9099cab3 CW |
97 | ]; |
98 | $form->_params = [ | |
e3fceb1a | 99 | 'qfKey' => 'donotcare', |
100 | 'contribution_id' => $contribution['id'], | |
101 | 'credit_card_number' => 4111111111111111, | |
102 | 'cvv2' => 234, | |
9099cab3 | 103 | 'credit_card_exp_date' => [ |
e3fceb1a | 104 | 'M' => 2, |
105 | 'Y' => 2021, | |
9099cab3 | 106 | ], |
e3fceb1a | 107 | 'credit_card_type' => 'Visa', |
108 | 'email-5' => 'test@test.com', | |
109 | 'total_amount' => 100.00, | |
110 | 'payment_processor_id' => $paymentProcessorID, | |
111 | 'amount' => 100, | |
112 | 'tax_amount' => 0.00, | |
113 | 'year' => 2021, | |
114 | 'month' => 2, | |
115 | 'currencyID' => 'USD', | |
116 | 'is_pay_later' => 0, | |
117 | 'invoiceID' => '6e443672a9bb2198cc12f076aed70e7a', | |
118 | 'is_quick_config' => 1, | |
119 | 'description' => $contribution['values'][$contribution['id']]['source'], | |
120 | 'skipLineItem' => 0, | |
9099cab3 | 121 | ]; |
e3fceb1a | 122 | |
248a226e | 123 | $processConfirmResult = CRM_Contribute_BAO_Contribution_Utils::processConfirm($form, |
e3fceb1a | 124 | $form->_params, |
125 | $contactID, | |
126 | $form->_values['financial_type_id'], | |
127 | 0, FALSE | |
128 | ); | |
248a226e MW |
129 | |
130 | // Make sure that certain parameters are set on return from processConfirm | |
131 | $this->assertEquals($form->_values['financial_type_id'], $processConfirmResult['financial_type_id']); | |
132 | ||
e3fceb1a | 133 | // Based on the processed contribution, complete transaction which update the contribution status based on payment result. |
248a226e | 134 | if (!empty($processConfirmResult['contribution'])) { |
9099cab3 | 135 | $this->callAPISuccess('contribution', 'completetransaction', [ |
248a226e | 136 | 'id' => $processConfirmResult['contribution']->id, |
e3fceb1a | 137 | 'trxn_date' => date('Y-m-d'), |
138 | 'payment_processor_id' => $paymentProcessorID, | |
9099cab3 | 139 | ]); |
e3fceb1a | 140 | } |
141 | ||
9099cab3 | 142 | $contribution = $this->callAPISuccessGetSingle('Contribution', [ |
e3fceb1a | 143 | 'id' => $form->_params['contribution_id'], |
9099cab3 | 144 | 'return' => [ |
e3fceb1a | 145 | 'contribution_page_id', |
146 | 'contribution_status', | |
147 | 'contribution_source', | |
9099cab3 CW |
148 | ], |
149 | ]); | |
e3fceb1a | 150 | |
151 | // check that contribution page ID isn't changed | |
152 | $this->assertEquals($contributionPageID1, $contribution['contribution_page_id']); | |
153 | // check that paid later information is present in contribution's source | |
154 | $this->assertRegExp("/Paid later via page ID: $contributionPageID2/", $contribution['contribution_source']); | |
155 | // check that contribution status is changed to 'Completed' from 'Pending' | |
156 | $this->assertEquals('Completed', $contribution['contribution_status']); | |
157 | } | |
158 | ||
159 | } |