updated examples
[civicrm-core.git] / api / v3 / examples / LineItemCreate.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
68* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/LineItemTest.php
69*
70* You can see the outcome of the API tests at
71* http://tests.dev.civicrm.org/trunk/results-api_v3
72*
73* To Learn about the API read
74* http://book.civicrm.org/developer/current/techniques/api/
75*
76* and review the wiki at
77* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
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*/