Merge pull request #5035 from TeNNoX/master
[civicrm-core.git] / api / v3 / examples / MembershipType / 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 membership_type create API.
10 *
11 *
12 * @return array
13 * API result array
14 */
15 function membership_type_create_example() {
16 $params = array(
17 'name' => '40+ Membership',
18 'description' => 'people above 40 are given health instructions',
19 'member_of_contact_id' => 13,
20 'financial_type_id' => 1,
21 'domain_id' => '1',
22 'minimum_fee' => '200',
23 'duration_unit' => 'month',
24 'duration_interval' => '10',
25 'period_type' => 'rolling',
26 'visibility' => 'public',
27 );
28
29 try{
30 $result = civicrm_api3('membership_type', 'create', $params);
31 }
32 catch (CiviCRM_API3_Exception $e) {
33 // Handle error here.
34 $errorMessage = $e->getMessage();
35 $errorCode = $e->getErrorCode();
36 $errorData = $e->getExtraParams();
37 return array(
38 'error' => $errorMessage,
39 'error_code' => $errorCode,
40 'error_data' => $errorData,
41 );
42 }
43
44 return $result;
45 }
46
47 /**
48 * Function returns array of result expected from previous function.
49 *
50 * @return array
51 * API result array
52 */
53 function membership_type_create_expectedresult() {
54
55 $expectedResult = array(
56 'is_error' => 0,
57 'version' => 3,
58 'count' => 1,
59 'id' => 2,
60 'values' => array(
61 '2' => array(
62 'id' => '2',
63 'domain_id' => '1',
64 'name' => '40+ Membership',
65 'description' => 'people above 40 are given health instructions',
66 'member_of_contact_id' => '13',
67 'financial_type_id' => '1',
68 'minimum_fee' => '200',
69 'duration_unit' => 'month',
70 'duration_interval' => '10',
71 'period_type' => 'rolling',
72 'fixed_period_start_day' => '',
73 'fixed_period_rollover_day' => '',
74 'relationship_type_id' => '',
75 'relationship_direction' => '',
76 'max_related' => '',
77 'visibility' => 'Public',
78 'weight' => '',
79 'receipt_text_signup' => '',
80 'receipt_text_renewal' => '',
81 'auto_renew' => '',
82 'is_active' => '',
83 'contribution_type_id' => '1',
84 ),
85 ),
86 );
87
88 return $expectedResult;
89 }
90
91 /**
92 * This example has been generated from the API test suite.
93 * The test that created it is called
94 * testCreate
95 * and can be found in
96 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/MembershipTypeTest.php
97 *
98 * You can see the outcome of the API tests at
99 * https://test.civicrm.org/job/CiviCRM-master-git/
100 *
101 * To Learn about the API read
102 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
103 *
104 * Browse the api on your own site with the api explorer
105 * http://MYSITE.ORG/path/to/civicrm/api/explorer
106 *
107 * Read more about testing here
108 * http://wiki.civicrm.org/confluence/display/CRM/Testing
109 *
110 * API Standards documentation:
111 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
112 */