Merge pull request #5097 from PalanteJon/CRM-15917
[civicrm-core.git] / api / v3 / examples / Pledge / Create.php
1 <?php
2 /**
3 * Test Generated example of using pledge create API.
4 *
5 *
6 * @return array
7 * API result array
8 */
9 function pledge_create_example() {
10 $params = array(
11 'contact_id' => 11,
12 'pledge_create_date' => '20150115',
13 'start_date' => '20150115',
14 'scheduled_date' => '20150117',
15 'amount' => '100',
16 'pledge_status_id' => '2',
17 'pledge_financial_type_id' => '1',
18 'pledge_original_installment_amount' => 20,
19 'frequency_interval' => 5,
20 'frequency_unit' => 'year',
21 'frequency_day' => 15,
22 'installments' => 5,
23 'sequential' => 1,
24 );
25
26 try{
27 $result = civicrm_api3('pledge', 'create', $params);
28 }
29 catch (CiviCRM_API3_Exception $e) {
30 // Handle error here.
31 $errorMessage = $e->getMessage();
32 $errorCode = $e->getErrorCode();
33 $errorData = $e->getExtraParams();
34 return array(
35 'error' => $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 = array(
53 'is_error' => 0,
54 'version' => 3,
55 'count' => 1,
56 'id' => 1,
57 'values' => array(
58 '0' => array(
59 'id' => '1',
60 'contact_id' => '11',
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 ),
83 ),
84 );
85
86 return $expectedResult;
87 }
88
89 /**
90 * This example has been generated from the API test suite.
91 * The test that created it is called
92 * testCreatePledge
93 * and can be found in
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-master-git/
98 *
99 * To Learn about the API read
100 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
101 *
102 * Browse the api on your own site with the api explorer
103 * http://MYSITE.ORG/path/to/civicrm/api
104 *
105 * Read more about testing here
106 * http://wiki.civicrm.org/confluence/display/CRM/Testing
107 *
108 * API Standards documentation:
109 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
110 */