Merge pull request #1051 from yashodha/hooks
[civicrm-core.git] / api / v3 / examples / Contribution / CreateWithNestedLineItems.php
1 <?php
2
3 /*
4 Create Contribution with Nested Line Items
5 */
6 function contribution_create_example(){
7 $params = array(
8 'contact_id' => 1,
9 'receive_date' => '20120511',
10 'total_amount' => '100',
11 'financial_type_id' => 1,
12 'payment_instrument_id' => 1,
13 'non_deductible_amount' => '10',
14 'fee_amount' => '50',
15 'net_amount' => '90',
16 'trxn_id' => 12345,
17 'invoice_id' => 67890,
18 'source' => 'SSF',
19 'contribution_status_id' => 1,
20 'version' => 3,
21 'skipLineItem' => 1,
22 'api.line_item.create' => array(
23 '0' => array(
24 'price_field_id' => 1,
25 'qty' => 2,
26 'line_total' => '20',
27 'unit_price' => '10',
28 ),
29 '1' => array(
30 'price_field_id' => 1,
31 'qty' => 1,
32 'line_total' => '80',
33 'unit_price' => '80',
34 ),
35 ),
36 );
37
38 $result = civicrm_api( 'contribution','create',$params );
39
40 return $result;
41 }
42
43 /*
44 * Function returns array of result expected from previous function
45 */
46 function contribution_create_expectedresult(){
47
48 $expectedResult = array(
49 'is_error' => 0,
50 'version' => 3,
51 'count' => 1,
52 'id' => 1,
53 'values' => array(
54 '1' => array(
55 'id' => '1',
56 'contact_id' => '1',
57 'financial_type_id' => '1',
58 'contribution_page_id' => '',
59 'payment_instrument_id' => '1',
60 'receive_date' => '20120511000000',
61 'non_deductible_amount' => '10',
62 'total_amount' => '100',
63 'fee_amount' => '50',
64 'net_amount' => '90',
65 'trxn_id' => '12345',
66 'invoice_id' => '67890',
67 'currency' => 'USD',
68 'cancel_date' => '',
69 'cancel_reason' => '',
70 'receipt_date' => '',
71 'thankyou_date' => '',
72 'source' => 'SSF',
73 'amount_level' => '',
74 'contribution_recur_id' => '',
75 'honor_contact_id' => '',
76 'is_test' => '',
77 'is_pay_later' => '',
78 'contribution_status_id' => '1',
79 'honor_type_id' => '',
80 'address_id' => '',
81 'check_number' => 'null',
82 'campaign_id' => '',
83 'contribution_type_id' => '1',
84 'api.line_item.create' => array(
85 '0' => array(
86 'is_error' => 0,
87 'version' => 3,
88 'count' => 1,
89 'id' => 1,
90 'values' => array(
91 '0' => array(
92 'id' => '1',
93 'entity_table' => 'civicrm_contribution',
94 'entity_id' => '1',
95 'price_field_id' => '1',
96 'label' => 'line item',
97 'qty' => '2',
98 'unit_price' => '10',
99 'line_total' => '20',
100 'participant_count' => '',
101 'price_field_value_id' => '',
102 'financial_type_id' => '',
103 'deductible_amount' => '',
104 ),
105 ),
106 ),
107 '1' => array(
108 'is_error' => 0,
109 'version' => 3,
110 'count' => 1,
111 'id' => 2,
112 'values' => array(
113 '0' => array(
114 'id' => '2',
115 'entity_table' => 'civicrm_contribution',
116 'entity_id' => '1',
117 'price_field_id' => '1',
118 'label' => 'line item',
119 'qty' => '1',
120 'unit_price' => '80',
121 'line_total' => '80',
122 'participant_count' => '',
123 'price_field_value_id' => '',
124 'financial_type_id' => '',
125 'deductible_amount' => '',
126 ),
127 ),
128 ),
129 ),
130 ),
131 ),
132 );
133
134 return $expectedResult ;
135 }
136
137
138 /*
139 * This example has been generated from the API test suite. The test that created it is called
140 *
141 * testCreateContributionChainedLineItems and can be found in
142 * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ContributionTest.php
143 *
144 * You can see the outcome of the API tests at
145 * http://tests.dev.civicrm.org/trunk/results-api_v3
146 *
147 * To Learn about the API read
148 * http://book.civicrm.org/developer/current/techniques/api/
149 *
150 * and review the wiki at
151 * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
152 *
153 * Read more about testing here
154 * http://wiki.civicrm.org/confluence/display/CRM/Testing
155 *
156 * API Standards documentation:
157 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
158 */