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