Commit | Line | Data |
---|---|---|
4f53d6f2 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the ContributionSoft.create API. |
50fb255d | 4 | * |
50fb255d | 5 | * @return array |
6 | * API result array | |
7 | */ | |
8 | function contribution_soft_create_example() { | |
cf8f0fff | 9 | $params = [ |
50fb255d | 10 | 'contribution_id' => 6, |
11 | 'contact_id' => 19, | |
12 | 'amount' => '10', | |
13 | 'currency' => 'USD', | |
14 | 'soft_credit_type_id' => 5, | |
cf8f0fff | 15 | ]; |
4f53d6f2 | 16 | |
50fb255d | 17 | try{ |
a828d7b8 | 18 | $result = civicrm_api3('ContributionSoft', 'create', $params); |
50fb255d | 19 | } |
20 | catch (CiviCRM_API3_Exception $e) { | |
21 | // Handle error here. | |
22 | $errorMessage = $e->getMessage(); | |
23 | $errorCode = $e->getErrorCode(); | |
24 | $errorData = $e->getExtraParams(); | |
cf8f0fff | 25 | return [ |
5be22f39 | 26 | 'is_error' => 1, |
27 | 'error_message' => $errorMessage, | |
50fb255d | 28 | 'error_code' => $errorCode, |
29 | 'error_data' => $errorData, | |
cf8f0fff | 30 | ]; |
50fb255d | 31 | } |
32 | ||
33 | return $result; | |
4f53d6f2 | 34 | } |
35 | ||
fb32de45 | 36 | /** |
50fb255d | 37 | * Function returns array of result expected from previous function. |
38 | * | |
39 | * @return array | |
40 | * API result array | |
4f53d6f2 | 41 | */ |
50fb255d | 42 | function contribution_soft_create_expectedresult() { |
4f53d6f2 | 43 | |
cf8f0fff | 44 | $expectedResult = [ |
50fb255d | 45 | 'is_error' => 0, |
46 | 'version' => 3, | |
47 | 'count' => 1, | |
48 | 'id' => 5, | |
cf8f0fff CW |
49 | 'values' => [ |
50 | '5' => [ | |
50fb255d | 51 | 'id' => '5', |
52 | 'contribution_id' => '6', | |
53 | 'contact_id' => '19', | |
54 | 'amount' => '10', | |
55 | 'currency' => 'USD', | |
56 | 'pcp_id' => '', | |
57 | 'pcp_display_in_roll' => '', | |
58 | 'pcp_roll_nickname' => '', | |
59 | 'pcp_personal_note' => '', | |
60 | 'soft_credit_type_id' => '5', | |
cf8f0fff CW |
61 | ], |
62 | ], | |
63 | ]; | |
4f53d6f2 | 64 | |
fb32de45 | 65 | return $expectedResult; |
4f53d6f2 | 66 | } |
67 | ||
a828d7b8 | 68 | /* |
50fb255d | 69 | * This example has been generated from the API test suite. |
a828d7b8 CW |
70 | * The test that created it is called "testCreateContributionSoft" |
71 | * and can be found at: | |
69d79249 | 72 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionSoftTest.php |
4f53d6f2 | 73 | * |
74 | * You can see the outcome of the API tests at | |
8390b11b | 75 | * https://test.civicrm.org/job/CiviCRM-Core-Matrix/ |
4f53d6f2 | 76 | * |
77 | * To Learn about the API read | |
8390b11b | 78 | * https://docs.civicrm.org/dev/en/latest/api/ |
4f53d6f2 | 79 | * |
8390b11b SL |
80 | * Browse the API on your own site with the API Explorer. It is in the main |
81 | * CiviCRM menu, under: Support > Development > API Explorer. | |
4f53d6f2 | 82 | * |
83 | * Read more about testing here | |
8390b11b | 84 | * https://docs.civicrm.org/dev/en/latest/testing/ |
4f53d6f2 | 85 | * |
86 | * API Standards documentation: | |
8390b11b | 87 | * https://docs.civicrm.org/dev/en/latest/framework/api-architecture/ |
b259a4ab | 88 | */ |