Merge pull request #15526 from civicrm/5.19
[civicrm-core.git] / api / v3 / examples / Contribution / Create.ex.php
CommitLineData
6a488035 1<?php
50fb255d 2/**
a828d7b8 3 * Test Generated example demonstrating the Contribution.create API.
50fb255d 4 *
50fb255d 5 * @return array
6 * API result array
7 */
8function contribution_create_example() {
cf8f0fff 9 $params = [
f4e879d2 10 'contact_id' => 1,
50fb255d 11 'receive_date' => '20120511',
12 'total_amount' => '100',
13 'financial_type_id' => 1,
14 'contribution_page_id' => 1,
15 'trxn_id' => 12345,
1d8ee3d6 16 'is_pay_later' => 1,
50fb255d 17 'invoice_id' => 67890,
18 'source' => 'SSF',
19 'contribution_status_id' => 2,
cf8f0fff 20 ];
6a488035 21
50fb255d 22 try{
a828d7b8 23 $result = civicrm_api3('Contribution', 'create', $params);
50fb255d 24 }
25 catch (CiviCRM_API3_Exception $e) {
26 // Handle error here.
27 $errorMessage = $e->getMessage();
28 $errorCode = $e->getErrorCode();
29 $errorData = $e->getExtraParams();
cf8f0fff 30 return [
1d8ee3d6 31 'is_error' => 1,
32 'error_message' => $errorMessage,
50fb255d 33 'error_code' => $errorCode,
34 'error_data' => $errorData,
cf8f0fff 35 ];
50fb255d 36 }
37
38 return $result;
6a488035
TO
39}
40
fb32de45 41/**
50fb255d 42 * Function returns array of result expected from previous function.
43 *
44 * @return array
45 * API result array
6a488035 46 */
50fb255d 47function contribution_create_expectedresult() {
6a488035 48
cf8f0fff 49 $expectedResult = [
50fb255d 50 'is_error' => 0,
51 'version' => 3,
52 'count' => 1,
53 'id' => 1,
cf8f0fff
CW
54 'values' => [
55 '1' => [
50fb255d 56 'id' => '1',
f4e879d2 57 'contact_id' => '1',
50fb255d 58 'financial_type_id' => '1',
59 'contribution_page_id' => '1',
60 'payment_instrument_id' => '4',
61 'receive_date' => '20120511000000',
62 'non_deductible_amount' => '',
63 'total_amount' => '100',
1d8ee3d6 64 'fee_amount' => 0,
50fb255d 65 'net_amount' => '100',
66 'trxn_id' => '12345',
67 'invoice_id' => '67890',
8390b11b 68 'invoice_number' => '',
50fb255d 69 'currency' => 'USD',
70 'cancel_date' => '',
71 'cancel_reason' => '',
72 'receipt_date' => '',
73 'thankyou_date' => '',
74 'source' => 'SSF',
75 'amount_level' => '',
76 'contribution_recur_id' => '',
77 'is_test' => '',
1d8ee3d6 78 'is_pay_later' => '1',
50fb255d 79 'contribution_status_id' => '2',
80 'address_id' => '',
81 'check_number' => '',
82 'campaign_id' => '',
83 'creditnote_id' => '',
84 'tax_amount' => '',
ae27ec9f 85 'revenue_recognition_date' => '',
dc396835 86 'is_template' => '',
1d8ee3d6 87 'contribution_type_id' => '1',
cf8f0fff
CW
88 ],
89 ],
90 ];
6a488035 91
fb32de45 92 return $expectedResult;
6a488035
TO
93}
94
a828d7b8 95/*
50fb255d 96* This example has been generated from the API test suite.
1d8ee3d6 97* The test that created it is called "testCreateContributionPayLaterOnline"
a828d7b8 98* and can be found at:
1d8ee3d6 99* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionTest.php
6a488035
TO
100*
101* You can see the outcome of the API tests at
8390b11b 102* https://test.civicrm.org/job/CiviCRM-Core-Matrix/
6a488035
TO
103*
104* To Learn about the API read
8390b11b 105* https://docs.civicrm.org/dev/en/latest/api/
6a488035 106*
8390b11b
SL
107* Browse the API on your own site with the API Explorer. It is in the main
108* CiviCRM menu, under: Support > Development > API Explorer.
6a488035
TO
109*
110* Read more about testing here
8390b11b 111* https://docs.civicrm.org/dev/en/latest/testing/
6a488035
TO
112*
113* API Standards documentation:
8390b11b 114* https://docs.civicrm.org/dev/en/latest/framework/api-architecture/
b259a4ab 115*/