Merge branch 4.5 into master
[civicrm-core.git] / api / v3 / examples / ContributionRecur / Create.php
CommitLineData
6a488035 1<?php
fb32de45 2/**
50fb255d 3 * @file
4 * Test Generated API Example.
5 * See bottom of this file for more detail.
6a488035 6 */
6a488035 7
50fb255d 8/**
9 * Test Generated example of using contribution_recur create API.
10 *
11 *
12 * @return array
13 * API result array
14 */
15function 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 );
6a488035 26
50fb255d 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;
6a488035
TO
43}
44
fb32de45 45/**
50fb255d 46 * Function returns array of result expected from previous function.
47 *
48 * @return array
49 * API result array
6a488035 50 */
50fb255d 51function contribution_recur_create_expectedresult() {
6a488035 52
edb0d67a 53 $expectedResult = array(
50fb255d 54 'is_error' => 0,
55 'version' => 3,
56 'count' => 1,
57 'id' => 1,
58 'values' => array(
edb0d67a 59 '1' => array(
50fb255d 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 ),
6a488035 88 ),
50fb255d 89 );
6a488035 90
fb32de45 91 return $expectedResult;
6a488035
TO
92}
93
50fb255d 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
69d79249 99* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionRecurTest.php
6a488035
TO
100*
101* You can see the outcome of the API tests at
69d79249 102* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
103*
104* To Learn about the API read
69d79249 105* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 106*
69d79249
E
107* Browse the api on your own site with the api explorer
108* http://MYSITE.ORG/path/to/civicrm/api/explorer
6a488035
TO
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
b259a4ab 115*/