CRM-19958 Fix invalid name of variable subtype
[civicrm-core.git] / api / v3 / examples / Pledge / Create.php
1 <?php
2 /**
3 * Test Generated example demonstrating the Pledge.create API.
4 *
5 * @return array
6 * API result array
7 */
8 function pledge_create_example() {
9 $params = array(
10 'contact_id' => 11,
11 'pledge_create_date' => '20150222',
12 'start_date' => '20150222',
13 'scheduled_date' => '20150224',
14 'amount' => '100',
15 'pledge_status_id' => '2',
16 'pledge_financial_type_id' => '1',
17 'pledge_original_installment_amount' => 20,
18 'frequency_interval' => 5,
19 'frequency_unit' => 'year',
20 'frequency_day' => 15,
21 'installments' => 5,
22 'sequential' => 1,
23 );
24
25 try{
26 $result = civicrm_api3('Pledge', 'create', $params);
27 }
28 catch (CiviCRM_API3_Exception $e) {
29 // Handle error here.
30 $errorMessage = $e->getMessage();
31 $errorCode = $e->getErrorCode();
32 $errorData = $e->getExtraParams();
33 return array(
34 'error' => $errorMessage,
35 'error_code' => $errorCode,
36 'error_data' => $errorData,
37 );
38 }
39
40 return $result;
41 }
42
43 /**
44 * Function returns array of result expected from previous function.
45 *
46 * @return array
47 * API result array
48 */
49 function pledge_create_expectedresult() {
50
51 $expectedResult = array(
52 'is_error' => 0,
53 'version' => 3,
54 'count' => 1,
55 'id' => 1,
56 'values' => array(
57 '0' => array(
58 'id' => '1',
59 'contact_id' => '11',
60 'financial_type_id' => '1',
61 'contribution_page_id' => '',
62 'amount' => '100',
63 'original_installment_amount' => '20',
64 'currency' => 'USD',
65 'frequency_unit' => 'year',
66 'frequency_interval' => '5',
67 'frequency_day' => '15',
68 'installments' => '5',
69 'start_date' => '2013-07-29 00:00:00',
70 'create_date' => '20120130621222105',
71 'acknowledge_date' => '',
72 'modified_date' => '',
73 'cancel_date' => '',
74 'end_date' => '',
75 'max_reminders' => '',
76 'initial_reminder_day' => '',
77 'additional_reminder_day' => '',
78 'status_id' => '2',
79 'is_test' => '',
80 'campaign_id' => '',
81 ),
82 ),
83 );
84
85 return $expectedResult;
86 }
87
88 /*
89 * This example has been generated from the API test suite.
90 * The test that created it is called "testCreatePledge"
91 * and can be found at:
92 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/PledgeTest.php
93 *
94 * You can see the outcome of the API tests at
95 * https://test.civicrm.org/job/CiviCRM-master-git/
96 *
97 * To Learn about the API read
98 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
99 *
100 * Browse the api on your own site with the api explorer
101 * http://MYSITE.ORG/path/to/civicrm/api
102 *
103 * Read more about testing here
104 * http://wiki.civicrm.org/confluence/display/CRM/Testing
105 *
106 * API Standards documentation:
107 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
108 */