From b24bc18b33e16a8eb0e0e36a2e6d57c520fa3a86 Mon Sep 17 00:00:00 2001
From: Matthew Wire <mjw@mjwconsult.co.uk>
Date: Sat, 22 Apr 2017 20:10:09 +0100
Subject: [PATCH] Check for isBackOffice instead of individual forms

---
 CRM/Core/Payment/Stripe.php | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/CRM/Core/Payment/Stripe.php b/CRM/Core/Payment/Stripe.php
index a13c8173..6a5eac88 100644
--- a/CRM/Core/Payment/Stripe.php
+++ b/CRM/Core/Payment/Stripe.php
@@ -277,14 +277,18 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
     if (empty($form->_paymentProcessor)) {
       return;
     }
-    // Determine if we are dealing with a webform in CiviCRM 4.7.  Those don't have a
-    //  _paymentProcessors array and only have one payprocesssor.
-    if (in_array(get_class($form), array('CRM_Financial_Form_Payment', 'CRM_Contribute_Form_Contribution'))) {
+
+    // When called from admin backend (eg via CRM_Contribute_Form_Contribution, CRM_Member_Form_Membership)
+    // the isBackOffice flag will be set to true.
+    // But if called via webform in CiviCRM 4.7: isBackOffice=NULL and for is of class CRM_Financial_Form_Payment or CRM_Contribute_Form_Contribution
+    // Those don't have a _paymentProcessors array and only have one payprocesssor.
+    if (!empty($form->isBackOffice)
+      || (in_array(get_class($form), array('CRM_Financial_Form_Payment', 'CRM_Contribute_Form_Contribution')))) {
       return $stripe_ppid = $form->_paymentProcessor['id'];
     }
     else {
       // Find a Stripe pay processor ascociated with this Civi form and find the ID.
-   //   $payProcessors = $form->_paymentProcessors;
+      //   $payProcessors = $form->_paymentProcessors;
       $payProcessors = CRM_Core_Form_Stripe::get_ppids($form);
       foreach ($payProcessors as $payProcessor) {
         if ($payProcessor['class_name'] == 'Payment_Stripe') {
-- 
GitLab