| 1 | <?php |
| 2 | /** |
| 3 | * Test Generated example of using contribution create API |
| 4 | * Demonstrates creating contribution with Note Entity * |
| 5 | */ |
| 6 | function contribution_create_example(){ |
| 7 | $params = array( |
| 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, |
| 20 | 'note' => 'my contribution note', |
| 21 | ); |
| 22 | |
| 23 | try{ |
| 24 | $result = civicrm_api3('contribution', 'create', $params); |
| 25 | } |
| 26 | catch (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 | } |
| 33 | |
| 34 | return $result; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Function returns array of result expected from previous function |
| 39 | */ |
| 40 | function contribution_create_expectedresult(){ |
| 41 | |
| 42 | $expectedResult = array( |
| 43 | 'is_error' => 0, |
| 44 | 'version' => 3, |
| 45 | 'count' => 1, |
| 46 | 'id' => 1, |
| 47 | 'values' => array( |
| 48 | '1' => array( |
| 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' => '', |
| 69 | 'is_test' => '', |
| 70 | 'is_pay_later' => '', |
| 71 | 'contribution_status_id' => '1', |
| 72 | 'address_id' => '', |
| 73 | 'check_number' => '', |
| 74 | 'campaign_id' => '', |
| 75 | 'creditnote_id' => '', |
| 76 | 'tax_amount' => '', |
| 77 | 'contribution_type_id' => '1', |
| 78 | ), |
| 79 | ), |
| 80 | ); |
| 81 | |
| 82 | return $expectedResult; |
| 83 | } |
| 84 | |
| 85 | |
| 86 | /* |
| 87 | * This example has been generated from the API test suite. The test that created it is called |
| 88 | * |
| 89 | * testCreateContributionWithNote and can be found in |
| 90 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionTest.php |
| 91 | * |
| 92 | * You can see the outcome of the API tests at |
| 93 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
| 94 | * |
| 95 | * To Learn about the API read |
| 96 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
| 97 | * |
| 98 | * Browse the api on your own site with the api explorer |
| 99 | * http://MYSITE.ORG/path/to/civicrm/api/explorer |
| 100 | * |
| 101 | * Read more about testing here |
| 102 | * http://wiki.civicrm.org/confluence/display/CRM/Testing |
| 103 | * |
| 104 | * API Standards documentation: |
| 105 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards |
| 106 | */ |