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