From 3dd8c1f018ae7f508ff147423f05886310f2bc52 Mon Sep 17 00:00:00 2001
From: "Matthew Wire (MJW Consulting)" <mjw@mjwconsult.co.uk>
Date: Wed, 25 Sep 2019 23:45:41 +0100
Subject: [PATCH] Support recording full refunds from Stripe

---
 CRM/Core/Payment/StripeIPN.php | 15 ++++++++++++++-
 CRM/Stripe/Check.php           |  2 +-
 docs/index.md                  |  9 +++++++++
 docs/release/release_notes.md  |  2 +-
 4 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/CRM/Core/Payment/StripeIPN.php b/CRM/Core/Payment/StripeIPN.php
index 2dc05f2b..da2c393c 100644
--- a/CRM/Core/Payment/StripeIPN.php
+++ b/CRM/Core/Payment/StripeIPN.php
@@ -252,7 +252,7 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
         $refunds = \Stripe\Refund::all(['charge' => $this->charge_id, 'limit' => 1]);
         $params = [
           'id' => $this->contribution['id'],
-          'total_amount' => $this->retrieve('amount_refunded', 'Float'),
+          'payment_trxn_id' => $this->charge_id,
           'cancel_reason' => $refunds->data[0]->reason,
           'cancel_date' => date('YmdHis', $refunds->data[0]->created),
         ];
@@ -367,11 +367,22 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
       }
     }
 
+    $contributionParamsToReturn = [
+      'id',
+      'trxn_id',
+      'contribution_status_id',
+      'total_amount',
+      'fee_amount',
+      'net_amount',
+      'tax_amount',
+    ];
+
     if ($this->charge_id) {
       try {
         $this->contribution = civicrm_api3('Contribution', 'getsingle', [
           'trxn_id' => $this->charge_id,
           'contribution_test' => $this->_paymentProcessor->getIsTestMode(),
+          'return' => $contributionParamsToReturn,
         ]);
       }
       catch (Exception $e) {
@@ -383,6 +394,7 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
         $this->contribution = civicrm_api3('Contribution', 'getsingle', [
           'trxn_id' => $this->invoice_id,
           'contribution_test' => $this->_paymentProcessor->getIsTestMode(),
+          'return' => $contributionParamsToReturn,
         ]);
       }
       catch (Exception $e) {
@@ -397,6 +409,7 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
           'return' => ['id', 'contribution_status_id', 'total_amount', 'trxn_id'],
           'contribution_recur_id' => $this->contribution_recur_id,
           'contribution_test' => $this->_paymentProcessor->getIsTestMode(),
+          'return' => $contributionParamsToReturn,
           'options' => ['limit' => 1, 'sort' => 'id DESC'],
         ]);
       }
diff --git a/CRM/Stripe/Check.php b/CRM/Stripe/Check.php
index 8a4ea2d9..ca12e708 100644
--- a/CRM/Stripe/Check.php
+++ b/CRM/Stripe/Check.php
@@ -10,7 +10,7 @@ use CRM_Stripe_ExtensionUtil as E;
  */
 class CRM_Stripe_Check {
 
-  const MIN_VERSION_MJWSHARED = '0.4.3';
+  const MIN_VERSION_MJWSHARED = '0.4.4';
 
   public static function checkRequirements(&$messages) {
     $extensions = civicrm_api3('Extension', 'get', [
diff --git a/docs/index.md b/docs/index.md
index 1ce09ab0..114c939e 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -5,6 +5,15 @@ Integrates the Stripe payment processor (for Credit/Debit cards) into CiviCRM so
 
 View/Download this extension in the [Extension Directory](https://civicrm.org/extensions/stripe-payment-processor).
 
+## Supports
+* PSD2 / SCA payments on one-off payments, partial support for recurring payments (may not be able to authorise card in some cases).
+* Cancellation of subscriptions from Stripe / CiviCRM.
+* Full refund of payments from Stripe.
+
+### Does not support
+* Partial refunds (they will not be processed by CiviCRM correctly and will be recorded as a full refund of a contribution).
+* Updating Stripe subscriptions from CiviCRM.
+
 ## Compatibility / Requirements
 * CiviCRM 5.13+
 * PHP 7.1+
diff --git a/docs/release/release_notes.md b/docs/release/release_notes.md
index 7abd1102..2aaace25 100644
--- a/docs/release/release_notes.md
+++ b/docs/release/release_notes.md
@@ -1,7 +1,7 @@
 ## Release 6.1.5
 
 * Send email receipts from Stripe by default (as this was what 5.x did). Add a setting under Administer->CiviContribute->Stripe Settings to enable/disable receipts from Stripe.
-
+* Support recording full refunds from Stripe.
 
 ## Release 6.1.4
 **This release fixes a MAJOR issue that caused duplicate payments to be taken when a new recurring contribution (subscription) was setup.  All users of 6.x should upgrade.**
-- 
GitLab