Merge pull request #2288 from eileenmcnaughton/CRM-14043
[civicrm-core.git] / api / v3 / examples / Contribution / ContributionCreateWithSoftCredit.php
CommitLineData
6a488035 1<?php
fb32de45 2/**
3 * Test Generated example of using contribution create API
4 * Demonstrates creating contribution with SoftCredit *
6a488035
TO
5 */
6function contribution_create_example(){
53ca8fd7 7$params = array(
8 'contact_id' => 1,
6a488035
TO
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,
6a488035
TO
17 'soft_credit_to' => 2,
18);
19
fb32de45 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}
6a488035 30
fb32de45 31return $result;
6a488035
TO
32}
33
fb32de45 34/**
6a488035
TO
35 * Function returns array of result expected from previous function
36 */
37function contribution_create_expectedresult(){
38
53ca8fd7 39 $expectedResult = array(
6a488035
TO
40 'is_error' => 0,
41 'version' => 3,
42 'count' => 1,
43 'id' => 1,
53ca8fd7 44 'values' => array(
45 '1' => array(
6a488035
TO
46 'id' => '1',
47 'contact_id' => '1',
48 'financial_type_id' => '1',
49 'contribution_page_id' => '',
50 'payment_instrument_id' => '',
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 'honor_contact_id' => '',
67 'is_test' => '',
68 'is_pay_later' => '',
69 'contribution_status_id' => '1',
70 'honor_type_id' => '',
71 'address_id' => '',
72 'check_number' => '',
73 'campaign_id' => '',
5cd28219 74 'contribution_type_id' => '1',
6a488035
TO
75 ),
76 ),
77);
78
fb32de45 79 return $expectedResult;
6a488035
TO
80}
81
82
83/*
84* This example has been generated from the API test suite. The test that created it is called
85*
86* testCreateContributionWithSoftCredt and can be found in
87* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ContributionTest.php
88*
89* You can see the outcome of the API tests at
90* http://tests.dev.civicrm.org/trunk/results-api_v3
91*
92* To Learn about the API read
93* http://book.civicrm.org/developer/current/techniques/api/
94*
95* and review the wiki at
96* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
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*/