remove print icon
[civicrm-core.git] / api / v3 / examples / Pledge / Create.ex.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 = [
10 'contact_id' => 12,
11 'pledge_create_date' => '20190820',
12 'start_date' => '20190820',
13 'scheduled_date' => '20190822',
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 [
34 'is_error' => 1,
35 'error_message' => $errorMessage,
36 'error_code' => $errorCode,
37 'error_data' => $errorData,
38 ];
39 }
40
41 return $result;
42 }
43
44 /**
45 * Function returns array of result expected from previous function.
46 *
47 * @return array
48 * API result array
49 */
50 function pledge_create_expectedresult() {
51
52 $expectedResult = [
53 'is_error' => 0,
54 'version' => 3,
55 'count' => 1,
56 'id' => 1,
57 'values' => [
58 '0' => [
59 'id' => '1',
60 'contact_id' => '12',
61 'financial_type_id' => '1',
62 'contribution_page_id' => '',
63 'amount' => '100',
64 'original_installment_amount' => '20',
65 'currency' => 'USD',
66 'frequency_unit' => 'year',
67 'frequency_interval' => '5',
68 'frequency_day' => '15',
69 'installments' => '5',
70 'start_date' => '2013-07-29 00:00:00',
71 'create_date' => '20120130621222105',
72 'acknowledge_date' => '',
73 'modified_date' => '',
74 'cancel_date' => '',
75 'end_date' => '',
76 'max_reminders' => '',
77 'initial_reminder_day' => '',
78 'additional_reminder_day' => '',
79 'status_id' => '2',
80 'is_test' => '',
81 'campaign_id' => '',
82 'contribution_type_id' => '1',
83 ],
84 ],
85 ];
86
87 return $expectedResult;
88 }
89
90 /*
91 * This example has been generated from the API test suite.
92 * The test that created it is called "testCreatePledge"
93 * and can be found at:
94 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/PledgeTest.php
95 *
96 * You can see the outcome of the API tests at
97 * https://test.civicrm.org/job/CiviCRM-Core-Matrix/
98 *
99 * To Learn about the API read
100 * https://docs.civicrm.org/dev/en/latest/api/
101 *
102 * Browse the API on your own site with the API Explorer. It is in the main
103 * CiviCRM menu, under: Support > Development > API Explorer.
104 *
105 * Read more about testing here
106 * https://docs.civicrm.org/dev/en/latest/testing/
107 *
108 * API Standards documentation:
109 * https://docs.civicrm.org/dev/en/latest/framework/api-architecture/
110 */