Merge pull request #1271 from deepak-srivastava/revisions
[civicrm-core.git] / api / v3 / examples / Contribution / ContributionCreateWithSoftCredit.php
index 4dbea0735128df0a8aa7c110ab488575796654a7..5517820800d4cc3a09a41f1d480f8a9f38da3c12 100644 (file)
@@ -1,10 +1,10 @@
 <?php
-
-/*
- Demonstrates creating contribution with SoftCredit
+/**
+ * Test Generated example of using contribution create API
+ * Demonstrates creating contribution with SoftCredit *
  */
 function contribution_create_example(){
-$params = array( 
+$params = array(
   'contact_id' => 1,
   'receive_date' => '20120511',
   'total_amount' => '100',
@@ -14,27 +14,35 @@ $params = array(
   'net_amount' => '95',
   'source' => 'SSF',
   'contribution_status_id' => 1,
-  'version' => 3,
   'soft_credit_to' => 2,
 );
 
-  $result = civicrm_api( 'contribution','create',$params );
+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 contribution_create_expectedresult(){
 
-  $expectedResult = array( 
+  $expectedResult = array(
   'is_error' => 0,
   'version' => 3,
   'count' => 1,
   'id' => 1,
-  'values' => array( 
-      '1' => array( 
+  'values' => array(
+      '1' => array(
           'id' => '1',
           'contact_id' => '1',
           'financial_type_id' => '1',
@@ -68,7 +76,7 @@ function contribution_create_expectedresult(){
     ),
 );
 
-  return $expectedResult  ;
+  return $expectedResult;
 }