Merge pull request #5119 from colemanw/CRM-15789
[civicrm-core.git] / api / v3 / examples / LineItem / Create.php
1 <?php
2 /**
3 * Test Generated example of using line_item create API.
4 *
5 *
6 * @return array
7 * API result array
8 */
9 function line_item_create_example() {
10 $params = array(
11 'price_field_value_id' => 1,
12 'price_field_id' => 1,
13 'entity_table' => 'civicrm_contribution',
14 'entity_id' => 1,
15 'qty' => 1,
16 'unit_price' => 50,
17 'line_total' => 50,
18 'debug' => 1,
19 );
20
21 try{
22 $result = civicrm_api3('line_item', 'create', $params);
23 }
24 catch (CiviCRM_API3_Exception $e) {
25 // Handle error here.
26 $errorMessage = $e->getMessage();
27 $errorCode = $e->getErrorCode();
28 $errorData = $e->getExtraParams();
29 return array(
30 'error' => $errorMessage,
31 'error_code' => $errorCode,
32 'error_data' => $errorData,
33 );
34 }
35
36 return $result;
37 }
38
39 /**
40 * Function returns array of result expected from previous function.
41 *
42 * @return array
43 * API result array
44 */
45 function line_item_create_expectedresult() {
46
47 $expectedResult = array(
48 'is_error' => 0,
49 'version' => 3,
50 'count' => 1,
51 'id' => 2,
52 'values' => array(
53 '2' => array(
54 'id' => '2',
55 'entity_table' => 'civicrm_contribution',
56 'entity_id' => '1',
57 'contribution_id' => '',
58 'price_field_id' => '1',
59 'label' => 'line item',
60 'qty' => '1',
61 'unit_price' => '50',
62 'line_total' => '50',
63 'participant_count' => '',
64 'price_field_value_id' => '1',
65 'financial_type_id' => '',
66 'deductible_amount' => '',
67 'tax_amount' => '',
68 ),
69 ),
70 );
71
72 return $expectedResult;
73 }
74
75 /**
76 * This example has been generated from the API test suite.
77 * The test that created it is called
78 * testCreateLineItem
79 * and can be found in
80 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/LineItemTest.php
81 *
82 * You can see the outcome of the API tests at
83 * https://test.civicrm.org/job/CiviCRM-master-git/
84 *
85 * To Learn about the API read
86 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
87 *
88 * Browse the api on your own site with the api explorer
89 * http://MYSITE.ORG/path/to/civicrm/api
90 *
91 * Read more about testing here
92 * http://wiki.civicrm.org/confluence/display/CRM/Testing
93 *
94 * API Standards documentation:
95 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
96 */