X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=api%2Fv3%2Fexamples%2FContribution%2FContributionCreateWithNote.php;h=4a19762036ba1bc554ec2c46587aa2fe201b9b6c;hb=a828d7b823956a46f5a3cea184389c9b108f80ac;hp=6cd86fea80d9ddb6f563d19d6c13aa390e43e4c2;hpb=4730458b553ef9cba94015fe6f458f1b4d03c640;p=civicrm-core.git diff --git a/api/v3/examples/Contribution/ContributionCreateWithNote.php b/api/v3/examples/Contribution/ContributionCreateWithNote.php index 6cd86fea80..4a19762036 100644 --- a/api/v3/examples/Contribution/ContributionCreateWithNote.php +++ b/api/v3/examples/Contribution/ContributionCreateWithNote.php @@ -1,92 +1,102 @@ 1, - 'receive_date' => '2012-01-01', - 'total_amount' => '100', - 'financial_type_id' => 1, - 'payment_instrument_id' => 1, - 'non_deductible_amount' => '10', - 'fee_amount' => '50', - 'net_amount' => '90', - 'trxn_id' => 12345, - 'invoice_id' => 67890, - 'source' => 'SSF', - 'contribution_status_id' => 1, - 'note' => 'my contribution note', -); +function contribution_create_example() { + $params = array( + 'contact_id' => 17, + 'receive_date' => '2012-01-01', + 'total_amount' => '100', + 'financial_type_id' => 1, + 'payment_instrument_id' => 1, + 'non_deductible_amount' => '10', + 'fee_amount' => '50', + 'net_amount' => '90', + 'trxn_id' => 12345, + 'invoice_id' => 67890, + 'source' => 'SSF', + 'contribution_status_id' => 1, + 'note' => 'my contribution note', + ); -try{ - $result = civicrm_api3('contribution', 'create', $params); -} -catch (CiviCRM_API3_Exception $e) { - // handle error here - $errorMessage = $e->getMessage(); - $errorCode = $e->getErrorCode(); - $errorData = $e->getExtraParams(); - return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData); -} + try{ + $result = civicrm_api3('Contribution', 'create', $params); + } + catch (CiviCRM_API3_Exception $e) { + // Handle error here. + $errorMessage = $e->getMessage(); + $errorCode = $e->getErrorCode(); + $errorData = $e->getExtraParams(); + return array( + 'error' => $errorMessage, + 'error_code' => $errorCode, + 'error_data' => $errorData, + ); + } -return $result; + return $result; } /** - * Function returns array of result expected from previous function + * Function returns array of result expected from previous function. + * + * @return array + * API result array */ -function contribution_create_expectedresult(){ +function contribution_create_expectedresult() { $expectedResult = array( - 'is_error' => 0, - 'version' => 3, - 'count' => 1, - 'id' => 1, - 'values' => array( + 'is_error' => 0, + 'version' => 3, + 'count' => 1, + 'id' => 1, + 'values' => array( '1' => array( - 'id' => '1', - 'contact_id' => '1', - 'financial_type_id' => '1', - 'contribution_page_id' => '', - 'payment_instrument_id' => '1', - 'receive_date' => '20120101000000', - 'non_deductible_amount' => '10', - 'total_amount' => '100', - 'fee_amount' => '50', - 'net_amount' => '90', - 'trxn_id' => '12345', - 'invoice_id' => '67890', - 'currency' => 'USD', - 'cancel_date' => '', - 'cancel_reason' => '', - 'receipt_date' => '', - 'thankyou_date' => '', - 'source' => 'SSF', - 'amount_level' => '', - 'contribution_recur_id' => '', - 'is_test' => '', - 'is_pay_later' => '', - 'contribution_status_id' => '1', - 'address_id' => '', - 'check_number' => '', - 'campaign_id' => '', - 'creditnote_id' => '', - 'tax_amount' => '', - 'contribution_type_id' => '1', - ), + 'id' => '1', + 'contact_id' => '17', + 'financial_type_id' => '1', + 'contribution_page_id' => '', + 'payment_instrument_id' => '1', + 'receive_date' => '20120101000000', + 'non_deductible_amount' => '10', + 'total_amount' => '100', + 'fee_amount' => '50', + 'net_amount' => '90', + 'trxn_id' => '12345', + 'invoice_id' => '67890', + 'currency' => 'USD', + 'cancel_date' => '', + 'cancel_reason' => '', + 'receipt_date' => '', + 'thankyou_date' => '', + 'source' => 'SSF', + 'amount_level' => '', + 'contribution_recur_id' => '', + 'is_test' => '', + 'is_pay_later' => '', + 'contribution_status_id' => '1', + 'address_id' => '', + 'check_number' => '', + 'campaign_id' => '', + 'creditnote_id' => '', + 'tax_amount' => '', + 'contribution_type_id' => '1', + ), ), -); + ); return $expectedResult; } - /* -* This example has been generated from the API test suite. The test that created it is called -* -* testCreateContributionWithNote and can be found in +* This example has been generated from the API test suite. +* The test that created it is called "testCreateContributionWithNote" +* and can be found at: * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContributionTest.php * * You can see the outcome of the API tests at @@ -96,7 +106,7 @@ function contribution_create_expectedresult(){ * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API * * Browse the api on your own site with the api explorer -* http://MYSITE.ORG/path/to/civicrm/api/explorer +* http://MYSITE.ORG/path/to/civicrm/api * * Read more about testing here * http://wiki.civicrm.org/confluence/display/CRM/Testing