Merge pull request #9765 from monishdeb/CRM-19938
[civicrm-core.git] / api / v3 / examples / Contribution / ContributionCreateWithSoftCreditDefaults.php
index ffe3b52001000573fef100e837a7d39306e735d6..8d7126cb897de7c0f5218e7f9f9b630623beca52 100644 (file)
@@ -1,87 +1,99 @@
 <?php
 /**
- * Test Generated example of using contribution create API
- * Demonstrates creating contribution with Soft Credit defaults for amount and type *
+ * Test Generated example demonstrating the Contribution.create API.
+ *
+ * Demonstrates creating contribution with Soft Credit defaults for amount and type.
+ *
+ * @return array
+ *   API result array
  */
-function contribution_create_example(){
-$params = array(
-  'contact_id' => 3,
-  'receive_date' => '20120511',
-  'total_amount' => '100',
-  'financial_type_id' => 1,
-  'non_deductible_amount' => '10',
-  'fee_amount' => '5',
-  'net_amount' => '95',
-  'source' => 'SSF',
-  'contribution_status_id' => 1,
-  'soft_credit_to' => 4,
-);
+function contribution_create_example() {
+  $params = array(
+    'contact_id' => 21,
+    'receive_date' => '20120511',
+    'total_amount' => '100',
+    'financial_type_id' => 1,
+    'non_deductible_amount' => '10',
+    'fee_amount' => '5',
+    'net_amount' => '95',
+    'source' => 'SSF',
+    'contribution_status_id' => 1,
+    'soft_credit_to' => 22,
+  );
 
-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' => '3',
-          'financial_type_id' => '1',
-          'contribution_page_id' => '',
-          'payment_instrument_id' => '4',
-          'receive_date' => '20120511000000',
-          'non_deductible_amount' => '10',
-          'total_amount' => '100',
-          'fee_amount' => '5',
-          'net_amount' => '95',
-          'trxn_id' => '',
-          'invoice_id' => '',
-          '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' => '',
-          'contribution_type_id' => '1',
-        ),
+        'id' => '1',
+        'contact_id' => '21',
+        'financial_type_id' => '1',
+        'contribution_page_id' => '',
+        'payment_instrument_id' => '4',
+        'receive_date' => '20120511000000',
+        'non_deductible_amount' => '10',
+        'total_amount' => '100',
+        'fee_amount' => '5',
+        'net_amount' => '95',
+        'trxn_id' => '',
+        'invoice_id' => '',
+        '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
-*
-* testCreateContributionWithSoftCreditDefaults and can be found in
+* This example has been generated from the API test suite.
+* The test that created it is called "testCreateContributionWithSoftCreditDefaults"
+* 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
@@ -91,7 +103,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