Short array syntax - auto-convert api dir
[civicrm-core.git] / api / v3 / examples / Contribution / Get.php
CommitLineData
6a488035 1<?php
50fb255d 2/**
a828d7b8 3 * Test Generated example demonstrating the Contribution.get API.
50fb255d 4 *
50fb255d 5 * @return array
6 * API result array
7 */
8function contribution_get_example() {
cf8f0fff 9 $params = [
50fb255d 10 'contribution_id' => 1,
cf8f0fff 11 ];
6a488035 12
50fb255d 13 try{
a828d7b8 14 $result = civicrm_api3('Contribution', 'get', $params);
50fb255d 15 }
16 catch (CiviCRM_API3_Exception $e) {
17 // Handle error here.
18 $errorMessage = $e->getMessage();
19 $errorCode = $e->getErrorCode();
20 $errorData = $e->getExtraParams();
cf8f0fff 21 return [
1d8ee3d6 22 'is_error' => 1,
23 'error_message' => $errorMessage,
50fb255d 24 'error_code' => $errorCode,
25 'error_data' => $errorData,
cf8f0fff 26 ];
50fb255d 27 }
28
29 return $result;
6a488035
TO
30}
31
fb32de45 32/**
50fb255d 33 * Function returns array of result expected from previous function.
34 *
35 * @return array
36 * API result array
6a488035 37 */
50fb255d 38function contribution_get_expectedresult() {
6a488035 39
cf8f0fff 40 $expectedResult = [
50fb255d 41 'is_error' => 0,
42 'version' => 3,
43 'count' => 1,
44 'id' => 1,
cf8f0fff
CW
45 'values' => [
46 '1' => [
1d8ee3d6 47 'contact_id' => '3',
50fb255d 48 'contact_type' => 'Individual',
49 'contact_sub_type' => '',
50 'sort_name' => 'Anderson, Anthony',
51 'display_name' => 'Mr. Anthony Anderson II',
52 'contribution_id' => '1',
53 'currency' => 'USD',
54 'receive_date' => '2010-01-20 00:00:00',
55 'non_deductible_amount' => '10.00',
56 'total_amount' => '100.00',
57 'fee_amount' => '5.00',
58 'net_amount' => '95.00',
59 'trxn_id' => '23456',
60 'invoice_id' => '78910',
61 'cancel_date' => '',
62 'cancel_reason' => '',
63 'receipt_date' => '',
64 'thankyou_date' => '',
65 'contribution_source' => 'SSF',
66 'amount_level' => '',
1d8ee3d6 67 'contribution_recur_id' => '',
50fb255d 68 'is_test' => 0,
69 'is_pay_later' => 0,
70 'contribution_status_id' => '1',
1d8ee3d6 71 'contribution_check_number' => '',
50fb255d 72 'contribution_campaign_id' => '',
73 'financial_type_id' => '1',
74 'financial_type' => 'Donation',
50fb255d 75 'product_id' => '',
76 'product_name' => '',
77 'sku' => '',
78 'contribution_product_id' => '',
79 'product_option' => '',
80 'fulfilled_date' => '',
81 'contribution_start_date' => '',
82 'contribution_end_date' => '',
50fb255d 83 'financial_account_id' => '1',
84 'accounting_code' => '4200',
1d8ee3d6 85 'campaign_id' => '',
86 'contribution_campaign_title' => '',
50fb255d 87 'contribution_note' => '',
88 'contribution_batch' => '',
89 'contribution_status' => 'Completed',
5c49fee0
CW
90 'payment_instrument' => 'Check',
91 'payment_instrument_id' => '4',
92 'instrument_id' => '4',
1d8ee3d6 93 'check_number' => '',
50fb255d 94 'id' => '1',
95 'contribution_type_id' => '1',
cf8f0fff
CW
96 ],
97 ],
98 ];
6a488035 99
fb32de45 100 return $expectedResult;
6a488035
TO
101}
102
a828d7b8 103/*
50fb255d 104* This example has been generated from the API test suite.
1d8ee3d6 105* The test that created it is called "testGetContribution"
a828d7b8 106* and can be found at:
69d79249 107* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionTest.php
6a488035
TO
108*
109* You can see the outcome of the API tests at
69d79249 110* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
111*
112* To Learn about the API read
69d79249 113* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 114*
69d79249 115* Browse the api on your own site with the api explorer
41d4d31f 116* http://MYSITE.ORG/path/to/civicrm/api
6a488035
TO
117*
118* Read more about testing here
119* http://wiki.civicrm.org/confluence/display/CRM/Testing
120*
121* API Standards documentation:
122* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 123*/