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