From 2590ea75b4e0665601e3fbeaa048a1cadf073f60 Mon Sep 17 00:00:00 2001
From: Matthew Wire <mjw@mjwconsult.co.uk>
Date: Wed, 4 Mar 2020 22:44:06 +0000
Subject: [PATCH] Fix issues with stripe js on thankyou pages

---
 js/civicrmStripeConfirm.js |  2 +-
 stripe.php                 | 22 ++++++++++------------
 2 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/js/civicrmStripeConfirm.js b/js/civicrmStripeConfirm.js
index b40765ba..c406e02b 100644
--- a/js/civicrmStripeConfirm.js
+++ b/js/civicrmStripeConfirm.js
@@ -11,7 +11,7 @@ CRM.$(function($) {
   switch (CRM.vars.stripe.paymentIntentStatus) {
     case 'succeeded':
     case 'cancelled':
-      debugging('paymentIntent: ' . CRM.vars.stripe.paymentIntentStatus);
+      debugging('paymentIntent: ' + CRM.vars.stripe.paymentIntentStatus);
       return;
   }
 
diff --git a/stripe.php b/stripe.php
index ec9f969f..0ac615b4 100644
--- a/stripe.php
+++ b/stripe.php
@@ -187,18 +187,16 @@ function stripe_civicrm_buildForm($formName, &$form) {
       $paymentProcessor->setAPIParams();
       try {
         $intent = \Stripe\PaymentIntent::retrieve($paymentIntent['paymentintent_id']);
-        if (!in_array($intent->status, ['succeeded', 'cancelled'])) {
-          // We need the confirmation_method to decide whether to use handleCardAction (manual) or handleCardPayment (automatic) on the js side
-          $jsVars = [
-            'id' => $form->_paymentProcessor['id'],
-            'paymentIntentID' => $paymentIntent['paymentintent_id'],
-            'paymentIntentStatus' => $intent->status,
-            'paymentIntentMethod' => $intent->confirmation_method,
-            'publishableKey' => CRM_Core_Payment_Stripe::getPublicKeyById($form->_paymentProcessor['id']),
-            'jsDebug' => (boolean) \Civi::settings()->get('stripe_jsdebug'),
-          ];
-          \Civi::resources()->addVars(E::SHORT_NAME, $jsVars);
-        }
+        // We need the confirmation_method to decide whether to use handleCardAction (manual) or handleCardPayment (automatic) on the js side
+        $jsVars = [
+          'id' => $form->_paymentProcessor['id'],
+          'paymentIntentID' => $paymentIntent['paymentintent_id'],
+          'paymentIntentStatus' => $intent->status,
+          'paymentIntentMethod' => $intent->confirmation_method,
+          'publishableKey' => CRM_Core_Payment_Stripe::getPublicKeyById($form->_paymentProcessor['id']),
+          'jsDebug' => (boolean) \Civi::settings()->get('stripe_jsdebug'),
+        ];
+        \Civi::resources()->addVars(E::SHORT_NAME, $jsVars);
       }
       catch (Exception $e) {
         // Do nothing, we won't attempt further stripe processing
-- 
GitLab