updated examples
[civicrm-core.git] / api / v3 / examples / ContributionRecurCreate.php
CommitLineData
6a488035 1<?php
fb32de45 2/**
3 * Test Generated example of using contribution_recur create API
4 * *
6a488035
TO
5 */
6function contribution_recur_create_example(){
edb0d67a 7$params = array(
6a488035
TO
8 'contact_id' => 3,
9 'installments' => '12',
10 'frequency_interval' => '1',
11 'amount' => '500',
12 'contribution_status_id' => 1,
13 'start_date' => '2012-01-01 00:00:00',
14 'currency' => 'USD',
15 'frequency_unit' => 'day',
16);
17
fb32de45 18try{
19 $result = civicrm_api3('contribution_recur', 'create', $params);
20}
21catch (CiviCRM_API3_Exception $e) {
22 // handle error here
23 $errorMessage = $e->getMessage();
24 $errorCode = $e->getErrorCode();
25 $errorData = $e->getExtraParams();
26 return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
27}
6a488035 28
fb32de45 29return $result;
6a488035
TO
30}
31
fb32de45 32/**
6a488035
TO
33 * Function returns array of result expected from previous function
34 */
35function contribution_recur_create_expectedresult(){
36
edb0d67a 37 $expectedResult = array(
6a488035
TO
38 'is_error' => 0,
39 'version' => 3,
40 'count' => 1,
41 'id' => 1,
edb0d67a 42 'values' => array(
43 '1' => array(
6a488035
TO
44 'id' => '1',
45 'contact_id' => '3',
46 'amount' => '500',
47 'currency' => 'USD',
48 'frequency_unit' => 'day',
49 'frequency_interval' => '1',
50 'installments' => '12',
9f1b81e0 51 'start_date' => '2013-07-29 00:00:00',
fb32de45 52 'create_date' => '20120130621222105',
9f1b81e0 53 'modified_date' => '',
6a488035
TO
54 'cancel_date' => '',
55 'end_date' => '',
56 'processor_id' => '',
57 'trxn_id' => '',
58 'invoice_id' => '',
59 'contribution_status_id' => '1',
60 'is_test' => '',
61 'cycle_day' => '',
797b807e 62 'next_sched_contribution_date' => '',
6a488035
TO
63 'failure_count' => '',
64 'failure_retry_date' => '',
65 'auto_renew' => '',
66 'payment_processor_id' => '',
67 'financial_type_id' => '',
68 'payment_instrument_id' => '',
69 'campaign_id' => '',
70 'is_email_receipt' => '',
71 ),
72 ),
73);
74
fb32de45 75 return $expectedResult;
6a488035
TO
76}
77
78
79/*
80* This example has been generated from the API test suite. The test that created it is called
81*
82* testCreateContributionRecur and can be found in
83* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ContributionRecurTest.php
84*
85* You can see the outcome of the API tests at
86* http://tests.dev.civicrm.org/trunk/results-api_v3
87*
88* To Learn about the API read
89* http://book.civicrm.org/developer/current/techniques/api/
90*
91* and review the wiki at
92* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
93*
94* Read more about testing here
95* http://wiki.civicrm.org/confluence/display/CRM/Testing
96*
97* API Standards documentation:
98* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 99*/