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