Merge pull request #2540 from eileenmcnaughton/CRM-14235
[civicrm-core.git] / api / v3 / examples / Membership / Create.php
CommitLineData
6a488035 1<?php
fb32de45 2/**
3 * Test Generated example of using membership create API
4 * *
6a488035
TO
5 */
6function membership_create_example(){
53ca8fd7 7$params = array(
37eda84b 8 'contact_id' => 30,
9 'membership_type_id' => 48,
6a488035
TO
10 'join_date' => '2009-01-21',
11 'start_date' => '2009-01-21',
12 'end_date' => '2009-12-21',
13 'source' => 'Payment',
14 'is_override' => 1,
37eda84b 15 'status_id' => 31,
fb32de45 16 'custom_1' => 'custom string',
6a488035
TO
17);
18
fb32de45 19try{
20 $result = civicrm_api3('membership', 'create', $params);
21}
22catch (CiviCRM_API3_Exception $e) {
23 // handle error here
24 $errorMessage = $e->getMessage();
25 $errorCode = $e->getErrorCode();
26 $errorData = $e->getExtraParams();
27 return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
28}
6a488035 29
fb32de45 30return $result;
6a488035
TO
31}
32
fb32de45 33/**
6a488035
TO
34 * Function returns array of result expected from previous function
35 */
36function membership_create_expectedresult(){
37
53ca8fd7 38 $expectedResult = array(
6a488035
TO
39 'is_error' => 0,
40 'version' => 3,
41 'count' => 1,
42 'id' => 1,
53ca8fd7 43 'values' => array(
44 '1' => array(
6a488035 45 'id' => '1',
37eda84b 46 'contact_id' => '30',
47 'membership_type_id' => '48',
6a488035 48 'join_date' => '20090121000000',
9f1b81e0 49 'start_date' => '2013-07-29 00:00:00',
50 'end_date' => '2013-08-04 00:00:00',
6a488035 51 'source' => 'Payment',
37eda84b 52 'status_id' => '31',
6a488035
TO
53 'is_override' => '1',
54 'owner_membership_id' => '',
55 'max_related' => '',
37eda84b 56 'is_test' => 0,
6a488035
TO
57 'is_pay_later' => '',
58 'contribution_recur_id' => '',
59 'campaign_id' => '',
60 ),
61 ),
62);
63
fb32de45 64 return $expectedResult;
6a488035
TO
65}
66
67
68/*
69* This example has been generated from the API test suite. The test that created it is called
70*
71* testCreateWithCustom and can be found in
69d79249 72* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/MembershipTest.php
6a488035
TO
73*
74* You can see the outcome of the API tests at
69d79249 75* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
76*
77* To Learn about the API read
69d79249 78* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 79*
69d79249
E
80* Browse the api on your own site with the api explorer
81* http://MYSITE.ORG/path/to/civicrm/api/explorer
6a488035
TO
82*
83* Read more about testing here
84* http://wiki.civicrm.org/confluence/display/CRM/Testing
85*
86* API Standards documentation:
87* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 88*/