From 24a19fffa992c1282c987a3aba4730d20cce9db2 Mon Sep 17 00:00:00 2001
From: Matthew Wire <mjw@mjwconsult.co.uk>
Date: Sun, 9 May 2021 19:20:31 +0100
Subject: [PATCH] Fix #306 Can't pay for event with more then one participant

---
 docs/releasenotes.md | 3 ++-
 info.xml             | 2 +-
 js/civicrm_stripe.js | 6 ++++--
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/docs/releasenotes.md b/docs/releasenotes.md
index 89070f53..d2162d28 100644
--- a/docs/releasenotes.md
+++ b/docs/releasenotes.md
@@ -9,7 +9,7 @@ Releases use the following numbering system:
 
 * **[BC]**: Items marked with [BC] indicate a breaking change that will require updates to your code if you are using that code in your extension.
 
-## Release 6.6 (not yet released 2021-04-10)
+## Release 6.6 (not yet released 2021-05-09)
 **Requires mjwshared (Payment Shared) 1.0**
 
 **Access AJAX API permission is required** for all users that make payments using Stripe (including the anonymous user).
@@ -34,6 +34,7 @@ Make sure you update your CMS user roles to include this permission.
 * Make more javascript strings translatable.
 * Disable billing fields by default.
 * Add 6.6 upgrade message to system checks.
+* Fix [#306](https://lab.civicrm.org/extensions/stripe/-/issues/306) Can't pay for event with more then one participant.
 
 ## Release 6.5.8
 
diff --git a/info.xml b/info.xml
index 2083a809..8c5bf09f 100644
--- a/info.xml
+++ b/info.xml
@@ -15,7 +15,7 @@
     <author>Matthew Wire (MJW Consulting)</author>
     <email>mjw@mjwconsult.co.uk</email>
   </maintainer>
-  <releaseDate>2021-04-12</releaseDate>
+  <releaseDate>2021-05-09</releaseDate>
   <version>6.6-dev</version>
   <develStage>beta</develStage>
   <compatibility>
diff --git a/js/civicrm_stripe.js b/js/civicrm_stripe.js
index 1de12741..6977eee2 100644
--- a/js/civicrm_stripe.js
+++ b/js/civicrm_stripe.js
@@ -200,12 +200,14 @@
         // For recur, additional participants we do NOT know the final amount so must create a paymentMethod and only create the paymentIntent
         //   once the form is finally submitted.
         // We should never get here with amount=0 as we should be doing a "nonStripeSubmit()" instead. This may become needed when we save cards
-        if (CRM.payment.getIsRecur() || CRM.payment.isEventAdditionalParticipants() || (CRM.payment.getTotalAmount() === 0.0)) {
+        var totalAmount = CRM.payment.getTotalAmount();
+        if (totalAmount) { totalAmount = totalAmount.toFixed(2); }
+        if (CRM.payment.getIsRecur() || CRM.payment.isEventAdditionalParticipants() || (totalAmount === null)) {
           CRM.api3('StripePaymentintent', 'createorupdate', {
             stripe_intent_id: createPaymentMethodResult.paymentMethod.id,
             description: document.title,
             payment_processor_id: CRM.vars.stripe.id,
-            amount: CRM.payment.getTotalAmount().toFixed(2),
+            amount: totalAmount,
             currency: CRM.payment.getCurrency(CRM.vars.stripe.currency),
             status: 'payment_method',
             csrfToken: CRM.vars.stripe.csrfToken,
-- 
GitLab