=== SubscriptionFlow for Gravity Forms ===
Contributors: appssf
Tags: gravity forms, subscriptions, recurring payments, subscription management, billing
Requires at least: 5.0
Tested up to: 7.1
Requires PHP: 7.2
Stable tag: 1.1.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Create customers and subscriptions in SubscriptionFlow when a Gravity Forms form is submitted.

== Description ==

SubscriptionFlow for Gravity Forms connects your Gravity Forms forms to SubscriptionFlow. When a form is submitted, the add-on finds or creates the customer in SubscriptionFlow (matched by email) and creates a subscription on the plan you choose.

= Key Features =

* **Customer sync** - Matches customers by email, updates existing customers or creates new ones
* **Subscription creation** - Creates a termed, auto-renewing subscription on the selected plan and plan price
* **Field mapping** - Map name, email, phone and company, each billing and shipping address line (street, city, state, ZIP, country), plus any custom SubscriptionFlow customer and subscription fields
* **Product and plan picker** - Choose the SubscriptionFlow product and plan from drop downs loaded from your account
* **Plans mapped to form choices** - Click "Add plan" to map a radio button, drop down or checkbox option (for example "1 year" / "2 years") to any SubscriptionFlow product and plan. The term fills in from the plan's billing period. Each ticked checkbox option with a plan creates its own subscription
* **Dynamic plans** - Or enter the product, plan and plan price IDs with merge tags, so a form field can choose the plan
* **Sync after payment** - When Stripe, PayPal or another Gravity Forms payment add-on collects the first payment, the customer and subscription are created only once the payment is confirmed
* **First payment in the form, renewals in SubscriptionFlow** - When Stripe or another payment add-on takes the first payment, the add-on records it against the subscription's first invoice so SubscriptionFlow only charges the renewals
* **Conditional logic** - Only send entries that match your conditions
* **Shared connection** - Reuse the connection from SubscriptionFlow Recurring Payments for WooCommerce, or enter separate credentials
* **Entry notes and logging** - Results are added to the entry notes and to the Gravity Forms logging add-on

= Requirements =

* Gravity Forms 2.5 or later
* A SubscriptionFlow account with API credentials (Instance URL, Client ID and Client Secret)

New to the add-on? Follow the [setup guide](https://support.subscriptionflow.com/hc/en-us/articles/63199397052313-Set-up-SubscriptionFlow-for-Gravity-Forms).

Don't have a SubscriptionFlow account? See [plans and pricing](https://www.subscriptionflow.com/pricing/) or [book a demo](https://calendly.com/info-8275/subscriptionflow/).

== Installation ==

1. Upload the plugin to the `/wp-content/plugins/` directory, or install it from the Plugins screen.
2. Activate the plugin.
3. Go to Forms > Settings > SubscriptionFlow and connect your SubscriptionFlow account.
4. Open a form, go to Settings > SubscriptionFlow and add a feed: map the customer and address fields, then choose one product and plan for every entry, or map plans to the form's choices.

For step-by-step instructions with screenshots, see the [Set up SubscriptionFlow for Gravity Forms](https://support.subscriptionflow.com/hc/en-us/articles/63199397052313-Set-up-SubscriptionFlow-for-Gravity-Forms) guide.

== Frequently Asked Questions ==

= Do I need a SubscriptionFlow account? =

Yes. The add-on sends customers and subscriptions to your SubscriptionFlow account. See [plans and pricing](https://www.subscriptionflow.com/pricing/) or [book a demo](https://calendly.com/info-8275/subscriptionflow/).

= A new product or plan doesn't appear in the feed settings =

Products and plans are cached for an hour. Save the add-on settings (Forms > Settings > SubscriptionFlow) to refresh them right away.

= Stripe takes the first payment in my form. Will SubscriptionFlow charge it again? =

No, if you set the feed's "Who collects the first payment?" to "Stripe, PayPal or another payment add-on in this form". The add-on waits for the payment to be confirmed. The subscription is created without charging its first invoice, the Stripe payment is recorded against that invoice with the Stripe transaction ID, and the invoice is marked paid. SubscriptionFlow charges from the next billing date.

= Where do I see what was sent? =

Each entry gets a note with the SubscriptionFlow subscription and customer IDs, or the error message. For full request details, enable logging for this add-on in Forms > Settings > Logging.

= Will an entry create duplicate subscriptions? =

No. Each feed creates at most one subscription per entry.

== Screenshots ==

1. Connect the add-on to your SubscriptionFlow instance with your Client ID and Client Secret.
2. Map the customer fields: email, name, phone, company and custom SubscriptionFlow customer fields.
3. Map each line of the billing address (and the shipping address, when it differs).
4. Choose the SubscriptionFlow product and plan from drop downs loaded from your account.
5. Map form choices to plans: each option creates its own product, plan and term.
6. Each entry gets a note with the SubscriptionFlow subscription and customer IDs.

== External services ==

This add-on connects to your SubscriptionFlow instance (the Instance URL you enter, for example https://yourcompany.subscriptionflow.com/) through the SubscriptionFlow API.

* When you save or view the add-on settings, it requests an access token with your Client ID and Client Secret.
* When you edit a feed, it reads your products, plans and plan prices.
* When a form is submitted and the feed runs, it sends the mapped entry data (name, email, phone, company, billing and shipping address, any custom fields you map, and the subscription details) to find, create or update the customer and create the subscription.

Nothing is sent until you connect the add-on and set up a feed. SubscriptionFlow is provided by SubscriptionFlow: [Terms of Service](https://subscriptionflow.com/terms-and-conditions/), [Privacy Policy](https://subscriptionflow.com/privacypolicy/).

== Changelog ==

= 1.1.4 =
* New: the plugin can be installed and updated with Composer (package subscriptionflow/subscriptionflow-for-gravity-forms, type wordpress-plugin), for example on Bedrock sites. The Composer package contains only the plugin files. No change to how the plugin works.

= 1.1.3 =
* New: with Gravity Forms logging set to "Log all messages", every authentication step is logged: whether the cached access token is reused or why a new one is requested, the token request (URL, the address the host resolves to, request headers including the User-Agent, timeout, SSL verification, proxy, WP_HTTP_BLOCK_EXTERNAL, WordPress/PHP/OpenSSL versions), how long it took, and the full response, also when authentication succeeds. A 401 that triggers a token refresh is logged too.
* Changed: the Client ID, Client Secret and access tokens are shown in the log as their first and last 4 characters and their length.

= 1.1.2 =
* New: with Gravity Forms logging enabled, a failed connection or API request logs the request URL and the full response: HTTP status, every header (showing whether Cloudflare, Azure or a proxy answered) and the whole body, plus the Client ID and Client Secret masked to their first and last 3 characters. A firewall block can then be told apart from wrong credentials.
* New: every SubscriptionFlow log line starts with the add-on version, e.g. [v1.1.2].

= 1.1.1 =
* Changed: a payment collected outside SubscriptionFlow (by Stripe, PayPal or another payment add-on, or a feed set to Paid) is sent with the subscription as its external payment. SubscriptionFlow records the transaction and marks the first invoice paid in the same request.
* Fixed: the connection status on the settings page now checks the credentials you just saved, instead of the previous ones until the page was saved a second time.

= 1.1.0 =
* New: "Who collects the first payment?" setting. With Stripe, PayPal or another payment add-on, the customer and subscription are created only after the payment is completed, and the first invoice is marked paid with the payment's transaction ID.
* New: Subscription payment status (Pending or Paid) when SubscriptionFlow collects the payment.
* Changed: all functions, methods and variables use the sfgf prefix.

= 1.0.0 =
* Initial release.

== Upgrade Notice ==

= 1.1.4 =
Adds Composer support. No functional changes.

= 1.1.3 =
Logs every step of connecting to SubscriptionFlow, to help diagnose connection problems.

= 1.1.2 =
Logs more detail about failed connections when Gravity Forms logging is enabled.

= 1.1.1 =
First payments are recorded in SubscriptionFlow in one step, and the settings page shows the correct connection status after saving.

= 1.1.0 =
Adds syncing to SubscriptionFlow after a Stripe or PayPal payment is completed. Feeds that used "Payment Status: From the entry payment" now send Pending unless a payment add-on collects the first payment.
