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