CRM-15988 - Update generated examples
[civicrm-core.git] / api / v3 / examples / Contribution / ContributionCreateWithNote.php
CommitLineData
6a488035 1<?php
50fb255d 2/**
a828d7b8 3 * Test Generated example demonstrating the Contribution.create API.
50fb255d 4 *
5c49fee0 5 * Demonstrates creating contribution with Note Entity.
50fb255d 6 *
7 * @return array
8 * API result array
9 */
10function contribution_create_example() {
11 $params = array(
5c49fee0 12 'contact_id' => 17,
50fb255d 13 'receive_date' => '2012-01-01',
14 'total_amount' => '100',
15 'financial_type_id' => 1,
16 'payment_instrument_id' => 1,
17 'non_deductible_amount' => '10',
18 'fee_amount' => '50',
19 'net_amount' => '90',
20 'trxn_id' => 12345,
21 'invoice_id' => 67890,
22 'source' => 'SSF',
23 'contribution_status_id' => 1,
24 'note' => 'my contribution note',
25 );
6a488035 26
50fb255d 27 try{
a828d7b8 28 $result = civicrm_api3('Contribution', 'create', $params);
50fb255d 29 }
30 catch (CiviCRM_API3_Exception $e) {
31 // Handle error here.
32 $errorMessage = $e->getMessage();
33 $errorCode = $e->getErrorCode();
34 $errorData = $e->getExtraParams();
35 return array(
36 'error' => $errorMessage,
37 'error_code' => $errorCode,
38 'error_data' => $errorData,
39 );
40 }
41
42 return $result;
6a488035
TO
43}
44
fb32de45 45/**
50fb255d 46 * Function returns array of result expected from previous function.
47 *
48 * @return array
49 * API result array
6a488035 50 */
50fb255d 51function contribution_create_expectedresult() {
6a488035 52
53ca8fd7 53 $expectedResult = array(
50fb255d 54 'is_error' => 0,
55 'version' => 3,
56 'count' => 1,
57 'id' => 1,
58 'values' => array(
53ca8fd7 59 '1' => array(
50fb255d 60 'id' => '1',
5c49fee0 61 'contact_id' => '17',
50fb255d 62 'financial_type_id' => '1',
63 'contribution_page_id' => '',
64 'payment_instrument_id' => '1',
65 'receive_date' => '20120101000000',
66 'non_deductible_amount' => '10',
67 'total_amount' => '100',
68 'fee_amount' => '50',
69 'net_amount' => '90',
70 'trxn_id' => '12345',
71 'invoice_id' => '67890',
72 'currency' => 'USD',
73 'cancel_date' => '',
74 'cancel_reason' => '',
75 'receipt_date' => '',
76 'thankyou_date' => '',
77 'source' => 'SSF',
78 'amount_level' => '',
79 'contribution_recur_id' => '',
80 'is_test' => '',
81 'is_pay_later' => '',
82 'contribution_status_id' => '1',
83 'address_id' => '',
84 'check_number' => '',
85 'campaign_id' => '',
86 'creditnote_id' => '',
87 'tax_amount' => '',
88 'contribution_type_id' => '1',
89 ),
6a488035 90 ),
50fb255d 91 );
6a488035 92
fb32de45 93 return $expectedResult;
6a488035
TO
94}
95
a828d7b8 96/*
50fb255d 97* This example has been generated from the API test suite.
a828d7b8
CW
98* The test that created it is called "testCreateContributionWithNote"
99* and can be found at:
69d79249 100* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionTest.php
6a488035
TO
101*
102* You can see the outcome of the API tests at
69d79249 103* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
104*
105* To Learn about the API read
69d79249 106* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 107*
69d79249 108* Browse the api on your own site with the api explorer
41d4d31f 109* http://MYSITE.ORG/path/to/civicrm/api
6a488035
TO
110*
111* Read more about testing here
112* http://wiki.civicrm.org/confluence/display/CRM/Testing
113*
114* API Standards documentation:
115* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 116*/