update extamples
[civicrm-core.git] / api / v3 / examples / Contribution / CreateWithNestedLineItems.php
CommitLineData
6a488035
TO
1<?php
2
3/*
4 Create Contribution with Nested Line Items
5 */
6function contribution_create_example(){
53ca8fd7 7$params = array(
6a488035
TO
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,
53ca8fd7 22 'api.line_item.create' => array(
23 '0' => array(
6a488035
TO
24 'price_field_id' => 1,
25 'qty' => 2,
26 'line_total' => '20',
27 'unit_price' => '10',
28 ),
53ca8fd7 29 '1' => array(
6a488035
TO
30 'price_field_id' => 1,
31 'qty' => 1,
32 'line_total' => '80',
33 'unit_price' => '80',
34 ),
35 ),
59fe57f7 36 'debug' => 0,
6a488035
TO
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 */
47function contribution_create_expectedresult(){
48
53ca8fd7 49 $expectedResult = array(
6a488035
TO
50 'is_error' => 0,
51 'version' => 3,
52 'count' => 1,
53 'id' => 1,
53ca8fd7 54 'values' => array(
55 '1' => array(
6a488035
TO
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' => '',
502b3d42 84 'contribution_type_id' => '1',
53ca8fd7 85 'api.line_item.create' => array(
86 '0' => array(
6a488035
TO
87 'is_error' => 0,
88 'version' => 3,
89 'count' => 1,
90 'id' => 1,
53ca8fd7 91 'values' => array(
92 '0' => array(
6a488035
TO
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 ),
53ca8fd7 108 '1' => array(
6a488035
TO
109 'is_error' => 0,
110 'version' => 3,
111 'count' => 1,
112 'id' => 2,
53ca8fd7 113 'values' => array(
114 '0' => array(
6a488035
TO
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*/