Merge pull request #5180 from monishdeb/master
[civicrm-core.git] / api / v3 / examples / ContributionRecur / Create.php
1 <?php
2 /**
3 * Test Generated example of using contribution_recur create API.
4 *
5 * @return array
6 * API result array
7 */
8 function contribution_recur_create_example() {
9 $params = array(
10 'contact_id' => 3,
11 'installments' => '12',
12 'frequency_interval' => '1',
13 'amount' => '500',
14 'contribution_status_id' => 1,
15 'start_date' => '2012-01-01 00:00:00',
16 'currency' => 'USD',
17 'frequency_unit' => 'day',
18 );
19
20 try{
21 $result = civicrm_api3('contribution_recur', 'create', $params);
22 }
23 catch (CiviCRM_API3_Exception $e) {
24 // Handle error here.
25 $errorMessage = $e->getMessage();
26 $errorCode = $e->getErrorCode();
27 $errorData = $e->getExtraParams();
28 return array(
29 'error' => $errorMessage,
30 'error_code' => $errorCode,
31 'error_data' => $errorData,
32 );
33 }
34
35 return $result;
36 }
37
38 /**
39 * Function returns array of result expected from previous function.
40 *
41 * @return array
42 * API result array
43 */
44 function contribution_recur_create_expectedresult() {
45
46 $expectedResult = array(
47 'is_error' => 0,
48 'version' => 3,
49 'count' => 1,
50 'id' => 1,
51 'values' => array(
52 '1' => array(
53 'id' => '1',
54 'contact_id' => '3',
55 'amount' => '500',
56 'currency' => 'USD',
57 'frequency_unit' => 'day',
58 'frequency_interval' => '1',
59 'installments' => '12',
60 'start_date' => '2013-07-29 00:00:00',
61 'create_date' => '20120130621222105',
62 'modified_date' => '',
63 'cancel_date' => '',
64 'end_date' => '',
65 'processor_id' => '',
66 'trxn_id' => '',
67 'invoice_id' => '',
68 'contribution_status_id' => '1',
69 'is_test' => '',
70 'cycle_day' => '',
71 'next_sched_contribution_date' => '',
72 'failure_count' => '',
73 'failure_retry_date' => '',
74 'auto_renew' => '',
75 'payment_processor_id' => '',
76 'financial_type_id' => '',
77 'payment_instrument_id' => '',
78 'campaign_id' => '',
79 'is_email_receipt' => '',
80 ),
81 ),
82 );
83
84 return $expectedResult;
85 }
86
87 /**
88 * This example has been generated from the API test suite.
89 * The test that created it is called
90 * testCreateContributionRecur
91 * and can be found in
92 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionRecurTest.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 */