Merge pull request #13908 from eileenmcnaughton/report_filter
[civicrm-core.git] / api / v3 / examples / Pledge / Create.php
CommitLineData
6a488035 1<?php
50fb255d 2/**
a828d7b8 3 * Test Generated example demonstrating the Pledge.create API.
50fb255d 4 *
50fb255d 5 * @return array
6 * API result array
7 */
8function pledge_create_example() {
9 $params = array(
10 'contact_id' => 11,
1d8ee3d6 11 'pledge_create_date' => '20170207',
12 'start_date' => '20170207',
13 'scheduled_date' => '20170209',
50fb255d 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 );
6a488035 24
50fb255d 25 try{
a828d7b8 26 $result = civicrm_api3('Pledge', 'create', $params);
50fb255d 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(
1d8ee3d6 34 'is_error' => 1,
35 'error_message' => $errorMessage,
50fb255d 36 'error_code' => $errorCode,
37 'error_data' => $errorData,
38 );
39 }
40
41 return $result;
6a488035
TO
42}
43
fb32de45 44/**
50fb255d 45 * Function returns array of result expected from previous function.
46 *
47 * @return array
48 * API result array
6a488035 49 */
50fb255d 50function pledge_create_expectedresult() {
6a488035 51
53ca8fd7 52 $expectedResult = array(
50fb255d 53 'is_error' => 0,
54 'version' => 3,
55 'count' => 1,
56 'id' => 1,
57 'values' => array(
53ca8fd7 58 '0' => array(
50fb255d 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 ),
6a488035 83 ),
50fb255d 84 );
6a488035 85
fb32de45 86 return $expectedResult;
6a488035
TO
87}
88
a828d7b8 89/*
50fb255d 90* This example has been generated from the API test suite.
a828d7b8
CW
91* The test that created it is called "testCreatePledge"
92* and can be found at:
69d79249 93* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/PledgeTest.php
6a488035
TO
94*
95* You can see the outcome of the API tests at
69d79249 96* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
97*
98* To Learn about the API read
69d79249 99* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 100*
69d79249 101* Browse the api on your own site with the api explorer
41d4d31f 102* http://MYSITE.ORG/path/to/civicrm/api
6a488035
TO
103*
104* Read more about testing here
105* http://wiki.civicrm.org/confluence/display/CRM/Testing
106*
107* API Standards documentation:
108* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 109*/