Merge branch 'rcsheets-docstring-cleanup'
[civicrm-core.git] / api / v3 / examples / LineItem / Create.php
CommitLineData
6a488035 1<?php
fb32de45 2/**
3 * Test Generated example of using line_item create API
4 * *
6a488035
TO
5 */
6function line_item_create_example(){
53ca8fd7 7$params = array(
6a488035
TO
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,
fb32de45 15 'debug' => 1,
6a488035
TO
16);
17
fb32de45 18try{
19 $result = civicrm_api3('line_item', 'create', $params);
20}
21catch (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}
6a488035 28
fb32de45 29return $result;
6a488035
TO
30}
31
fb32de45 32/**
6a488035
TO
33 * Function returns array of result expected from previous function
34 */
35function line_item_create_expectedresult(){
36
53ca8fd7 37 $expectedResult = array(
6a488035 38 'is_error' => 0,
6a488035
TO
39 'version' => 3,
40 'count' => 1,
41 'id' => 1,
53ca8fd7 42 'values' => array(
43 '1' => array(
6a488035
TO
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 ),
6a488035
TO
58);
59
fb32de45 60 return $expectedResult;
6a488035
TO
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
69d79249 68* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/LineItemTest.php
6a488035
TO
69*
70* You can see the outcome of the API tests at
69d79249 71* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
72*
73* To Learn about the API read
69d79249 74* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 75*
69d79249
E
76* Browse the api on your own site with the api explorer
77* http://MYSITE.ORG/path/to/civicrm/api/explorer
6a488035
TO
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
b259a4ab 84*/