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