Merge pull request #4947 from eileenmcnaughton/examples
[civicrm-core.git] / api / v3 / examples / ContributionSoft / 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 contribution_soft create API.
10 *
11 *
12 * @return array
13 * API result array
14 */
15 function contribution_soft_create_example() {
16 $params = array(
17 'contribution_id' => 6,
18 'contact_id' => 19,
19 'amount' => '10',
20 'currency' => 'USD',
21 'soft_credit_type_id' => 5,
22 );
23
24 try{
25 $result = civicrm_api3('contribution_soft', 'create', $params);
26 }
27 catch (CiviCRM_API3_Exception $e) {
28 // Handle error here.
29 $errorMessage = $e->getMessage();
30 $errorCode = $e->getErrorCode();
31 $errorData = $e->getExtraParams();
32 return array(
33 'error' => $errorMessage,
34 'error_code' => $errorCode,
35 'error_data' => $errorData,
36 );
37 }
38
39 return $result;
40 }
41
42 /**
43 * Function returns array of result expected from previous function.
44 *
45 * @return array
46 * API result array
47 */
48 function contribution_soft_create_expectedresult() {
49
50 $expectedResult = array(
51 'is_error' => 0,
52 'version' => 3,
53 'count' => 1,
54 'id' => 5,
55 'values' => array(
56 '5' => array(
57 'id' => '5',
58 'contribution_id' => '6',
59 'contact_id' => '19',
60 'amount' => '10',
61 'currency' => 'USD',
62 'pcp_id' => '',
63 'pcp_display_in_roll' => '',
64 'pcp_roll_nickname' => '',
65 'pcp_personal_note' => '',
66 'soft_credit_type_id' => '5',
67 ),
68 ),
69 );
70
71 return $expectedResult;
72 }
73
74 /**
75 * This example has been generated from the API test suite.
76 * The test that created it is called
77 * testCreateContributionSoft
78 * and can be found in
79 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionSoftTest.php
80 *
81 * You can see the outcome of the API tests at
82 * https://test.civicrm.org/job/CiviCRM-master-git/
83 *
84 * To Learn about the API read
85 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
86 *
87 * Browse the api on your own site with the api explorer
88 * http://MYSITE.ORG/path/to/civicrm/api/explorer
89 *
90 * Read more about testing here
91 * http://wiki.civicrm.org/confluence/display/CRM/Testing
92 *
93 * API Standards documentation:
94 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
95 */