Merge pull request #10155 from totten/master-pdf-save2
[civicrm-core.git] / api / v3 / examples / ContributionRecur / Create.php
1 <?php
2 /**
3 * Test Generated example demonstrating the ContributionRecur.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('ContributionRecur', '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 'is_error' => 1,
30 'error_message' => $errorMessage,
31 'error_code' => $errorCode,
32 'error_data' => $errorData,
33 );
34 }
35
36 return $result;
37 }
38
39 /**
40 * Function returns array of result expected from previous function.
41 *
42 * @return array
43 * API result array
44 */
45 function contribution_recur_create_expectedresult() {
46
47 $expectedResult = array(
48 'is_error' => 0,
49 'version' => 3,
50 'count' => 1,
51 'id' => 1,
52 'values' => array(
53 '1' => array(
54 'id' => '1',
55 'contact_id' => '3',
56 'amount' => '500',
57 'currency' => 'USD',
58 'frequency_unit' => 'day',
59 'frequency_interval' => '1',
60 'installments' => '12',
61 'start_date' => '2013-07-29 00:00:00',
62 'create_date' => '20120130621222105',
63 'modified_date' => '2012-11-14 16:02:35',
64 'cancel_date' => '',
65 'end_date' => '',
66 'processor_id' => '',
67 'payment_token_id' => '',
68 'trxn_id' => '',
69 'invoice_id' => '',
70 'contribution_status_id' => '1',
71 'is_test' => '',
72 'cycle_day' => '',
73 'next_sched_contribution_date' => '',
74 'failure_count' => '',
75 'failure_retry_date' => '',
76 'auto_renew' => '',
77 'payment_processor_id' => '',
78 'financial_type_id' => '',
79 'payment_instrument_id' => '',
80 'campaign_id' => '',
81 'is_email_receipt' => '',
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 "testCreateContributionRecur"
92 * and can be found at:
93 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionRecurTest.php
94 *
95 * You can see the outcome of the API tests at
96 * https://test.civicrm.org/job/CiviCRM-master-git/
97 *
98 * To Learn about the API read
99 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
100 *
101 * Browse the api on your own site with the api explorer
102 * http://MYSITE.ORG/path/to/civicrm/api
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
109 */