3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * Trait for setting up orders for tests.
17 trait CRMTraits_Financial_OrderTrait
{
19 use \Civi\Test\Api3TestTrait
;
22 * Create a pending membership from a recurring order.
24 * @throws \CRM_Core_Exception
26 public function createRepeatMembershipOrder() {
27 $this->createExtraneousContribution();
28 $this->ids
['contact'][0] = $this->individualCreate();
29 $this->ids
['membership_type'][0] = $this->membershipTypeCreate();
31 $contributionRecur = $this->callAPISuccess('ContributionRecur', 'create', array_merge([
32 'contact_id' => $this->_contactID
,
36 'frequency_unit' => 'Month',
37 'frequency_interval' => 1,
38 'invoice_id' => $this->_invoiceID
,
39 'contribution_status_id' => 2,
40 'payment_processor_id' => $this->_paymentProcessorID
,
41 // processor provided ID - use contact ID as proxy.
42 'processor_id' => $this->_contactID
,
45 $orderID = $this->callAPISuccess('Order', 'create', [
46 'total_amount' => '200',
47 'financial_type_id' => 'Donation',
48 'contact_id' => $this->_contactID
,
49 'contribution_page_id' => $this->_contributionPageID
,
50 'payment_processor_id' => $this->_paymentProcessorID
,
52 'receive_date' => '2019-07-25 07:34:23',
53 'skipCleanMoney' => TRUE,
54 'contribution_recur_id' => $contributionRecur['id'],
58 'contact_id' => $this->ids
['contact'][0],
59 'membership_type_id' => $this->ids
['membership_type'][0],
60 'contribution_recur_id' => $contributionRecur['id'],
61 'source' => 'Payment',
69 'financial_type_id' => 1,
70 'entity_table' => 'civicrm_membership',
71 'price_field_id' => $this->callAPISuccess('price_field', 'getvalue', [
73 'label' => 'Membership Amount',
74 'options' => ['limit' => 1, 'sort' => 'id DESC'],
76 'price_field_value_id' => $this->callAPISuccess('price_field_value', 'getvalue', [
79 'options' => ['limit' => 1, 'sort' => 'id DESC'],
87 $this->ids
['ContributionRecur'][0] = $contributionRecur['id'];
88 $this->ids
['Contribution'][0] = $orderID;
92 * Create an order with more than one membership.
94 * @throws \CRM_Core_Exception
96 protected function createMultipleMembershipOrder() {
97 $this->createExtraneousContribution();
98 $this->ids
['contact'][0] = $this->individualCreate();
99 $this->ids
['contact'][1] = $this->individualCreate();
100 $this->ids
['membership_type'][0] = $this->membershipTypeCreate();
101 $this->ids
['membership_type'][1] = $this->membershipTypeCreate(['name' => 'Type 2']);
102 $priceFieldID = $this->callAPISuccessGetValue('price_field', [
104 'label' => 'Membership Amount',
105 'options' => ['limit' => 1, 'sort' => 'id DESC'],
107 $generalPriceFieldValueID = $this->callAPISuccessGetValue('price_field_value', [
109 'label' => 'General',
110 'options' => ['limit' => 1, 'sort' => 'id DESC'],
113 $orderID = $this->callAPISuccess('Order', 'create', [
114 'total_amount' => 400,
115 'financial_type_id' => 'Member Dues',
116 'contact_id' => $this->_contactID
,
118 'payment_instrument_id' => 'Check',
119 'receive_date' => '2019-07-25 07:34:23',
123 'contact_id' => $this->ids
['contact'][0],
124 'membership_type_id' => $this->ids
['membership_type'][0],
125 'source' => 'Payment',
129 'label' => 'General',
133 'financial_type_id' => 1,
134 'entity_table' => 'civicrm_membership',
135 'price_field_id' => $priceFieldID,
136 'price_field_value_id' => $generalPriceFieldValueID,
142 'contact_id' => $this->ids
['contact'][1],
143 'membership_type_id' => $this->ids
['membership_type'][0],
144 'source' => 'Payment',
148 'label' => 'General',
152 'financial_type_id' => 1,
153 'entity_table' => 'civicrm_membership',
154 'price_field_id' => $priceFieldID,
155 'price_field_value_id' => $generalPriceFieldValueID,
162 $this->ids
['Contribution'][0] = $orderID;
166 * Create an order for an event.
168 * @param array $orderParams
170 * @throws \CRM_Core_Exception
172 protected function createEventOrder($orderParams = []) {
173 $this->ids
['Contribution'][0] = $this->callAPISuccess('Order', 'create', array_merge($this->getParticipantOrderParams(), $orderParams))['id'];
174 $this->ids
['Participant'][0] = $this->callAPISuccessGetValue('ParticipantPayment', ['return' => 'participant_id', 'contribution_id' => $this->ids
['Contribution'][0]]);
178 * Create an extraneous contribution to throw off any 'number one bugs'.
180 * Ie this means our real data starts from 2 & we won't hit 'pretend passes'
181 * just because the number 1 is used for multiple entities.
183 protected function createExtraneousContribution() {
184 $this->contributionCreate([
185 'contact_id' => $this->individualCreate(),
187 'financial_type_id' => 1,
188 'invoice_id' => 'abcd',
190 'receive_date' => '2019-07-25 07:34:23',