Merge pull request #13908 from eileenmcnaughton/report_filter
[civicrm-core.git] / api / v3 / examples / Contribution / ContributionCreateWithSoftCreditDefaults.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() {
11 $params = array(
1d8ee3d6 12 'contact_id' => 26,
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,
1d8ee3d6 21 'soft_credit_to' => 27,
50fb255d 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();
32 return array(
1d8ee3d6 33 'is_error' => 1,
34 'error_message' => $errorMessage,
50fb255d 35 'error_code' => $errorCode,
36 'error_data' => $errorData,
37 );
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
DG
50
51 $expectedResult = array(
50fb255d 52 'is_error' => 0,
53 'version' => 3,
54 'count' => 1,
55 'id' => 1,
56 'values' => array(
6a516bd6 57 '1' => array(
50fb255d 58 'id' => '1',
1d8ee3d6 59 'contact_id' => '26',
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' => '',
70 'currency' => 'USD',
71 'cancel_date' => '',
72 'cancel_reason' => '',
73 'receipt_date' => '',
74 'thankyou_date' => '',
75 'source' => 'SSF',
76 'amount_level' => '',
77 'contribution_recur_id' => '',
78 'is_test' => '',
79 'is_pay_later' => '',
80 'contribution_status_id' => '1',
81 'address_id' => '',
82 'check_number' => '',
83 'campaign_id' => '',
84 'creditnote_id' => '',
85 'tax_amount' => '',
1d8ee3d6 86 'revenue_recognition_date' => '',
50fb255d 87 'contribution_type_id' => '1',
88 ),
6a516bd6 89 ),
50fb255d 90 );
6a516bd6
DG
91
92 return $expectedResult;
93}
94
a828d7b8 95/*
50fb255d 96* This example has been generated from the API test suite.
a828d7b8
CW
97* The test that created it is called "testCreateContributionWithSoftCreditDefaults"
98* and can be found at:
6a516bd6
DG
99* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionTest.php
100*
101* You can see the outcome of the API tests at
102* https://test.civicrm.org/job/CiviCRM-master-git/
103*
104* To Learn about the API read
105* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
106*
107* Browse the api on your own site with the api explorer
41d4d31f 108* http://MYSITE.ORG/path/to/civicrm/api
6a516bd6
DG
109*
110* Read more about testing here
111* http://wiki.civicrm.org/confluence/display/CRM/Testing
112*
113* API Standards documentation:
114* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
115*/