Ejegg has submitted this change and it was merged.

Change subject: (merged into 4.7) CRM-17751 add api support for setting the 
trxn_id for a refund
......................................................................


(merged into 4.7) CRM-17751 add api support for setting the trxn_id for a refund

The civicrm_financial_trxn.trxn_id is set to ['refund_trxn_id'] when it is 
passed in.

This has been submitted to the master branch in 
https://github.com/civicrm/civicrm-core/pull/7501
Tests in that PR detail expectations

Relies on previous patch to set contributionStatus var

Bug: T116317
Change-Id: I7dd6494d2bd618b9a1761e1469ad5943f5ca32ad
---
M CRM/Contribute/BAO/Contribution.php
M api/v3/Contribution.php
2 files changed, 27 insertions(+), 6 deletions(-)

Approvals:
  Ejegg: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/CRM/Contribute/BAO/Contribution.php 
b/CRM/Contribute/BAO/Contribution.php
index e152f0b..3f36a42 100644
--- a/CRM/Contribute/BAO/Contribution.php
+++ b/CRM/Contribute/BAO/Contribution.php
@@ -2820,8 +2820,13 @@
         'payment_instrument_id' => 
$params['contribution']->payment_instrument_id,
         'check_number' => CRM_Utils_Array::value('check_number', $params),
       );
+
       if ($contributionStatus == 'Refunded') {
         $trxnParams['trxn_date'] = 
!empty($params['contribution']->cancel_date) ? 
$params['contribution']->cancel_date : date('YmdHis');
+        if (isset($params['refund_trxn_id'])) {
+          // CRM-17751 allow a separate trxn_id for the refund to be passed in 
via api & form.
+          $trxnParams['trxn_id'] = $params['refund_trxn_id'];
+        }
       }
 
       if (!empty($params['payment_processor'])) {
@@ -2843,7 +2848,13 @@
         $params['trxnParams']['total_amount'] = $trxnParams['total_amount'] = 
$params['total_amount'] = $params['prevContribution']->total_amount;
         $params['trxnParams']['fee_amount'] = 
$params['prevContribution']->fee_amount;
         $params['trxnParams']['net_amount'] = 
$params['prevContribution']->net_amount;
-        $params['trxnParams']['trxn_id'] = 
$params['prevContribution']->trxn_id;
+        if (!isset($params['trxnParams']['trxn_id'])) {
+          // Actually I have no idea why we are overwriting any values from 
the previous contribution.
+          // (filling makes sense to me). However, only protecting this value 
as I really really know we
+          // don't want this one overwritten.
+          // CRM-17751.
+          $params['trxnParams']['trxn_id'] = 
$params['prevContribution']->trxn_id;
+        }
         $params['trxnParams']['status_id'] = 
$params['prevContribution']->contribution_status_id;
 
         if (!(($params['prevContribution']->contribution_status_id == 
array_search('Pending', $contributionStatuses)
@@ -2884,7 +2895,12 @@
 
         //Update contribution status
         $params['trxnParams']['status_id'] = 
$params['contribution']->contribution_status_id;
-        $params['trxnParams']['trxn_id'] = $params['contribution']->trxn_id;
+        if (!isset($params['refund_trxn_id'])) {
+          // CRM-17751 This has previously been deliberately set. No 
explanation as to why one variant
+          // gets preference over another so I am only 'protecting' a very 
specific tested flow
+          // and letting natural justice take care of the rest.
+          $params['trxnParams']['trxn_id'] = $params['contribution']->trxn_id;
+        }
         if (!empty($params['contribution_status_id']) &&
           $params['prevContribution']->contribution_status_id != 
$params['contribution']->contribution_status_id
         ) {
diff --git a/api/v3/Contribution.php b/api/v3/Contribution.php
index df4db84..83f069e 100644
--- a/api/v3/Contribution.php
+++ b/api/v3/Contribution.php
@@ -105,21 +105,21 @@
   $params['soft_credit_to'] = array(
     'name' => 'soft_credit_to',
     'title' => 'Soft Credit contact ID (legacy)',
-    'type' => 1,
+    'type' => CRM_Utils_Type::T_INT,
     'description' => 'ID of Contact to be Soft credited to (deprecated - use 
contribution_soft api)',
     'FKClassName' => 'CRM_Contact_DAO_Contact',
   );
   $params['honor_contact_id'] = array(
     'name' => 'honor_contact_id',
     'title' => 'Honoree contact ID (legacy)',
-    'type' => 1,
+    'type' => CRM_Utils_Type::T_INT,
     'description' => 'ID of honoree contact (deprecated - use 
contribution_soft api)',
     'FKClassName' => 'CRM_Contact_DAO_Contact',
   );
   $params['honor_type_id'] = array(
     'name' => 'honor_type_id',
     'title' => 'Honoree Type (legacy)',
-    'type' => 1,
+    'type' => CRM_Utils_Type::T_INT,
     'description' => 'Type of honoree contact (deprecated - use 
contribution_soft api)',
     'pseudoconstant' => TRUE,
   );
@@ -140,9 +140,14 @@
   );
   $params['batch_id'] = array(
     'title' => 'Batch',
-    'type' => 1,
+    'type' => CRM_Utils_Type::T_INT,
     'description' => 'Batch which relevant transactions should be added to',
   );
+  $params['refund_trxn_id'] = array(
+    'title' => 'Refund Transaction ID',
+    'type' => CRM_Utils_Type::T_STRING,
+    'description' => 'Transaction ID specific to the refund taking place',
+  );
 }
 
 /**

-- 
To view, visit https://gerrit.wikimedia.org/r/263314
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I7dd6494d2bd618b9a1761e1469ad5943f5ca32ad
Gerrit-PatchSet: 3
Gerrit-Project: wikimedia/fundraising/crm/civicrm
Gerrit-Branch: master
Gerrit-Owner: Eileen <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Eileen <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to