Merge pull request #5035 from TeNNoX/master
[civicrm-core.git] / api / v3 / examples / ContributionRecur / Create.php
1 <?php
2 /**
3 * @file
4 * Test Generated API Example.
5 * See bottom of this file for more detail.
6 */
7
8 /**
9 * Test Generated example of using contribution_recur create API.
10 *
11 *
12 * @return array
13 * API result array
14 */
15 function contribution_recur_create_example() {
16 $params = array(
17 'contact_id' => 3,
18 'installments' => '12',
19 'frequency_interval' => '1',
20 'amount' => '500',
21 'contribution_status_id' => 1,
22 'start_date' => '2012-01-01 00:00:00',
23 'currency' => 'USD',
24 'frequency_unit' => 'day',
25 );
26
27 try{
28 $result = civicrm_api3('contribution_recur', 'create', $params);
29 }
30 catch (CiviCRM_API3_Exception $e) {
31 // Handle error here.
32 $errorMessage = $e->getMessage();
33 $errorCode = $e->getErrorCode();
34 $errorData = $e->getExtraParams();
35 return array(
36 'error' => $errorMessage,
37 'error_code' => $errorCode,
38 'error_data' => $errorData,
39 );
40 }
41
42 return $result;
43 }
44
45 /**
46 * Function returns array of result expected from previous function.
47 *
48 * @return array
49 * API result array
50 */
51 function contribution_recur_create_expectedresult() {
52
53 $expectedResult = array(
54 'is_error' => 0,
55 'version' => 3,
56 'count' => 1,
57 'id' => 1,
58 'values' => array(
59 '1' => array(
60 'id' => '1',
61 'contact_id' => '3',
62 'amount' => '500',
63 'currency' => 'USD',
64 'frequency_unit' => 'day',
65 'frequency_interval' => '1',
66 'installments' => '12',
67 'start_date' => '2013-07-29 00:00:00',
68 'create_date' => '20120130621222105',
69 'modified_date' => '',
70 'cancel_date' => '',
71 'end_date' => '',
72 'processor_id' => '',
73 'trxn_id' => '',
74 'invoice_id' => '',
75 'contribution_status_id' => '1',
76 'is_test' => '',
77 'cycle_day' => '',
78 'next_sched_contribution_date' => '',
79 'failure_count' => '',
80 'failure_retry_date' => '',
81 'auto_renew' => '',
82 'payment_processor_id' => '',
83 'financial_type_id' => '',
84 'payment_instrument_id' => '',
85 'campaign_id' => '',
86 'is_email_receipt' => '',
87 ),
88 ),
89 );
90
91 return $expectedResult;
92 }
93
94 /**
95 * This example has been generated from the API test suite.
96 * The test that created it is called
97 * testCreateContributionRecur
98 * and can be found in
99 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionRecurTest.php
100 *
101 * You can see the outcome of the API tests at
102 * https://test.civicrm.org/job/CiviCRM-master-git/
103 *
104 * To Learn about the API read
105 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
106 *
107 * Browse the api on your own site with the api explorer
108 * http://MYSITE.ORG/path/to/civicrm/api/explorer
109 *
110 * Read more about testing here
111 * http://wiki.civicrm.org/confluence/display/CRM/Testing
112 *
113 * API Standards documentation:
114 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
115 */