Ian province abbreviation patch - issue 724
[civicrm-core.git] / api / v3 / examples / Contribution / CreateWithNestedLineItems.php
CommitLineData
6a488035 1<?php
50fb255d 2/**
a828d7b8 3 * Test Generated example demonstrating the Contribution.create API.
50fb255d 4 *
5c49fee0 5 * Create Contribution with Nested Line Items.
50fb255d 6 *
7 * @return array
8 * API result array
9 */
10function contribution_create_example() {
11 $params = array(
a828d7b8 12 'contact_id' => 1,
50fb255d 13 'receive_date' => '20120511',
a828d7b8
CW
14 'total_amount' => '400',
15 'financial_type_id' => 7,
50fb255d 16 'trxn_id' => 12345,
17 'invoice_id' => 67890,
18 'source' => 'SSF',
19 'contribution_status_id' => 1,
20 'skipLineItem' => 1,
21 'api.line_item.create' => array(
53ca8fd7 22 '0' => array(
a828d7b8
CW
23 'price_field_id' => array(
24 '0' => 3,
25 ),
26 'qty' => 1,
27 'line_total' => '100',
28 'unit_price' => '100',
29 'financial_type_id' => 7,
50fb255d 30 ),
53ca8fd7 31 '1' => array(
a828d7b8
CW
32 'price_field_id' => array(
33 '0' => 3,
34 ),
50fb255d 35 'qty' => 1,
a828d7b8
CW
36 'line_total' => '300',
37 'unit_price' => '300',
38 'financial_type_id' => 8,
50fb255d 39 ),
6a488035 40 ),
50fb255d 41 );
6a488035 42
50fb255d 43 try{
a828d7b8 44 $result = civicrm_api3('Contribution', 'create', $params);
50fb255d 45 }
46 catch (CiviCRM_API3_Exception $e) {
47 // Handle error here.
48 $errorMessage = $e->getMessage();
49 $errorCode = $e->getErrorCode();
50 $errorData = $e->getExtraParams();
51 return array(
52 'error' => $errorMessage,
53 'error_code' => $errorCode,
54 'error_data' => $errorData,
55 );
56 }
6a488035 57
50fb255d 58 return $result;
6a488035
TO
59}
60
fb32de45 61/**
50fb255d 62 * Function returns array of result expected from previous function.
63 *
64 * @return array
65 * API result array
6a488035 66 */
50fb255d 67function contribution_create_expectedresult() {
6a488035 68
53ca8fd7 69 $expectedResult = array(
50fb255d 70 'is_error' => 0,
71 'version' => 3,
72 'count' => 1,
73 'id' => 1,
74 'values' => array(
53ca8fd7 75 '1' => array(
50fb255d 76 'id' => '1',
a828d7b8
CW
77 'contact_id' => '1',
78 'financial_type_id' => '7',
50fb255d 79 'contribution_page_id' => '',
a828d7b8 80 'payment_instrument_id' => '4',
50fb255d 81 'receive_date' => '20120511000000',
a828d7b8
CW
82 'non_deductible_amount' => '',
83 'total_amount' => '435',
84 'fee_amount' => 0,
85 'net_amount' => '435',
50fb255d 86 'trxn_id' => '12345',
87 'invoice_id' => '67890',
88 'currency' => 'USD',
89 'cancel_date' => '',
90 'cancel_reason' => '',
91 'receipt_date' => '',
92 'thankyou_date' => '',
93 'source' => 'SSF',
94 'amount_level' => '',
95 'contribution_recur_id' => '',
96 'is_test' => '',
97 'is_pay_later' => '',
98 'contribution_status_id' => '1',
99 'address_id' => '',
100 'check_number' => '',
101 'campaign_id' => '',
102 'creditnote_id' => '',
a828d7b8
CW
103 'tax_amount' => '35',
104 'contribution_type_id' => '7',
50fb255d 105 'api.line_item.create' => array(
106 '0' => array(
107 'is_error' => 0,
108 'version' => 3,
109 'count' => 1,
110 'id' => 1,
111 'values' => array(
112 '0' => array(
113 'id' => '1',
114 'entity_table' => 'civicrm_contribution',
115 'entity_id' => '1',
116 'contribution_id' => '1',
a828d7b8
CW
117 'price_field_id' => array(
118 '0' => '3',
119 ),
50fb255d 120 'label' => 'line item',
a828d7b8
CW
121 'qty' => '1',
122 'unit_price' => '100',
123 'line_total' => '100',
50fb255d 124 'participant_count' => '',
125 'price_field_value_id' => '',
a828d7b8 126 'financial_type_id' => '7',
50fb255d 127 'deductible_amount' => '',
a828d7b8 128 'tax_amount' => '20',
50fb255d 129 ),
130 ),
131 ),
132 '1' => array(
133 'is_error' => 0,
134 'version' => 3,
135 'count' => 1,
136 'id' => 2,
137 'values' => array(
53ca8fd7 138 '0' => array(
50fb255d 139 'id' => '2',
140 'entity_table' => 'civicrm_contribution',
141 'entity_id' => '1',
142 'contribution_id' => '1',
a828d7b8
CW
143 'price_field_id' => array(
144 '0' => '3',
145 ),
50fb255d 146 'label' => 'line item',
147 'qty' => '1',
a828d7b8
CW
148 'unit_price' => '300',
149 'line_total' => '300',
50fb255d 150 'participant_count' => '',
151 'price_field_value_id' => '',
a828d7b8 152 'financial_type_id' => '8',
50fb255d 153 'deductible_amount' => '',
a828d7b8 154 'tax_amount' => '15',
50fb255d 155 ),
6a488035 156 ),
50fb255d 157 ),
6a488035 158 ),
50fb255d 159 ),
6a488035 160 ),
50fb255d 161 );
6a488035 162
fb32de45 163 return $expectedResult;
6a488035
TO
164}
165
a828d7b8 166/*
50fb255d 167* This example has been generated from the API test suite.
a828d7b8
CW
168* The test that created it is called "testCreateContributionChainedLineItems"
169* and can be found at:
170* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/TaxContributionPageTest.php
6a488035
TO
171*
172* You can see the outcome of the API tests at
69d79249 173* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
174*
175* To Learn about the API read
69d79249 176* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 177*
69d79249 178* Browse the api on your own site with the api explorer
41d4d31f 179* http://MYSITE.ORG/path/to/civicrm/api
6a488035
TO
180*
181* Read more about testing here
182* http://wiki.civicrm.org/confluence/display/CRM/Testing
183*
184* API Standards documentation:
185* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 186*/