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