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