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