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