From 74572074d85e4289361a81fd5089a66e68b40b8e Mon Sep 17 00:00:00 2001
From: Matthew Wire <mjw@mjwconsult.co.uk>
Date: Sun, 26 Apr 2020 13:18:19 +0100
Subject: [PATCH] Fix #178 - allow recurring interval for drupal webform

---
 docs/integration.md           | 10 ++++++++++
 docs/release/release_notes.md |  1 +
 js/civicrm_stripe.js          |  4 +++-
 mkdocs.yml                    |  3 ++-
 4 files changed, 16 insertions(+), 2 deletions(-)
 create mode 100644 docs/integration.md

diff --git a/docs/integration.md b/docs/integration.md
new file mode 100644
index 00000000..648ca543
--- /dev/null
+++ b/docs/integration.md
@@ -0,0 +1,10 @@
+# Integrations
+
+## Drupal Webform + Webform_civicrm
+
+The Stripe extension works with Drupal Webform + Webform_civicrm.
+
+For recurring payments make sure that:
+1. You have either "Number of installments" or "Interval of installments" element on the same "page" as the payment.
+2. The elements are either visible or hidden (hidden element) - do NOT select hidden (secure value) as it won't work.
+
diff --git a/docs/release/release_notes.md b/docs/release/release_notes.md
index 5481d276..3f62d286 100644
--- a/docs/release/release_notes.md
+++ b/docs/release/release_notes.md
@@ -32,6 +32,7 @@ Where:
 * Make sure we generate backend contact links for customer metadata (previously they would sometimes get generated as frontend links).
 * If Stripe is not using the same currency as the payment was made we need to convert the fees/net amounts back to the CiviCRM currency.
 * Fix missing receipts for recurring subscription payment [#122](https://lab.civicrm.org/extensions/stripe/issues/122).
+* Fix [#178](https://lab.civicrm.org/extensions/stripe/issues/122) recurring payments for webform_civicrm when "Interval of installments" is selected.
 
 #### Behind the scenes:
 
diff --git a/js/civicrm_stripe.js b/js/civicrm_stripe.js
index d3236797..227585e1 100644
--- a/js/civicrm_stripe.js
+++ b/js/civicrm_stripe.js
@@ -606,7 +606,9 @@ CRM.$(function($) {
     var isRecur = false;
     // Auto-renew contributions for CiviCRM Webforms.
     if (getIsDrupalWebform()) {
-      if($('input[id$="contribution-installments"]').length !== 0 && $('input[id$="contribution-installments"]').val() > 1 ) {
+      if (($('input[data-civicrm-field-key$="contribution_installments"]').length !== 0 && $('input[data-civicrm-field-key$="contribution_installments"]').val() > 1) ||
+          ($('input[data-civicrm-field-key$="contribution_frequency_interval"]').length !== 0 && $('input[data-civicrm-field-key$="contribution_frequency_interval"]').val() > 0)
+      ) {
         isRecur = true;
       }
     }
diff --git a/mkdocs.yml b/mkdocs.yml
index fbcdfad3..e1043de0 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -1,6 +1,6 @@
 site_name: Stripe Payment Processor (https://stripe.com)
 repo_url: https://lab.civicrm.org/extensions/stripe
-theme: 
+theme:
   name: material
 markdown_extensions:
   - attr_list
@@ -22,6 +22,7 @@ nav:
 - Setup: setup.md
 - Webhooks (Notifications): webhook.md
 - FAQs: faqs.md
+- Integrations: integration.md
 - Recurring Contributions (Subscriptions): recur.md
 - Advanced:
   - API: api.md
-- 
GitLab