Skip to content

Commit

Permalink
#1219 redirect thank you page url (#1232)
Browse files Browse the repository at this point in the history
* #1219 redirect thank you page url

* Fix #1219 added new route for thank you URL

* wip #1219 adding a form to change the thankyou page url

* adding the custom_thank_you_page database column

* Fix #1219 updated page text

I updated the text on the "add custom thank you page"

* FIX #1219 adding url validation

* #1219 adding tests

* black formatting

* Update custom_thank_you_page.html

Added bold text and reworded the instructions

* Fix #1236 Updated the Shop Settings Heading in the dashboard

Added Donations & Thank you Page URL in the heading of Shop Settings

* fixing wording

* Fix #1219 improve wording on Custom Thank You page URL

#1219 added heading to settings page Custom Thank You page URL

#1219 less vuage "Your URL" to -> "Custom Thank You page URL:"

* #1219 require require_tld=True customThankYouUrlForm

* #1219 Please enter a valid URL -> Please enter a valid URL. e.g https://example.com/thankyou

* #1219 add form error help feedback

* Ref #1219 dont assume form is present, error handling

* satify black format error

* #1219 remove redundant cudtom thankyou url logic

* adding the redirect-to-custom-url test

* adding default url button

* fixing enable custom url test

* renaming file and adding waitForURL after redirect

* #1219 spacing

* #1219 use custom_thank_you_url, no need for redirect_thankyou_page

* #1219 if a custom_thank_you_url is already set, show it to the shop admin

* #1219 clarified wording 'once their payment is complete' -> 'once they have completed sign-up for a plan' -m 'because free plans exist, payment is not always taken.'

* #1219 remove dead "Click here to reset your shop to use the default Thank You page" text

* #1219 Test: no need to order plan. Use free plan for test

We're not testing the payment flow there, we're testing the custom thankyou page url'
'

* #1219 drop .toMatchSnapshot we dont use that

* #1219 remove unecessery entries in the test DAG

* Ref #1219 remove uneeded timeout & renamed:    e2e/1219_shop_owner_enable_custom_url.spec.js -> e2e/1219_custom_thank_you_url.spec.js

* Create pull_request_template.md

* #1219 redirect thank you page url

* Fix #1219 added new route for thank you URL

* wip #1219 adding a form to change the thankyou page url

* adding the custom_thank_you_page database column

* Fix #1219 updated page text

I updated the text on the "add custom thank you page"

* FIX #1219 adding url validation

* Ref #1219 adding tests

* black formatting

* Update custom_thank_you_page.html

Added bold text and reworded the instructions

* Fix #1236 Updated the Shop Settings Heading in the dashboard

Added Donations & Thank you Page URL in the heading of Shop Settings

* fixing wording

* Fix #1219 improve wording on Custom Thank You page URL

#1219 added heading to settings page Custom Thank You page URL

#1219 less vuage "Your URL" to -> "Custom Thank You page URL:"

* #1219 require require_tld=True customThankYouUrlForm

* #1219 Please enter a valid URL -> Please enter a valid URL. e.g https://example.com/thankyou

* #1219 add form error help feedback

* Ref #1219 dont assume form is present, error handling

* #1219 remove redundant cudtom thankyou url logic

* adding the redirect-to-custom-url test

* adding default url button

* renaming file and adding waitForURL after redirect

* #1219 spacing

* #1219 use custom_thank_you_url, no need for redirect_thankyou_page

* #1219 if a custom_thank_you_url is already set, show it to the shop admin

* #1219 clarified wording 'once their payment is complete' -> 'once they have completed sign-up for a plan' -m 'because free plans exist, payment is not always taken.'

* #1219 remove dead "Click here to reset your shop to use the default Thank You page" text

* #1219 remove unecessery entries in the test DAG

---------

Co-authored-by: Joel <joel@karmacomputing.co.uk>
Co-authored-by: chrisjsimpson <chris.j.simpson@live.co.uk>
  • Loading branch information
3 people authored Sep 28, 2023
1 parent c2031a8 commit 29fa7c5
Show file tree
Hide file tree
Showing 13 changed files with 208 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""add custom thank you url column
Revision ID: 207556b3039b
Revises: 7640c2a9be5b
Create Date: 2023-09-01 19:35:12.241628
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "207556b3039b"
down_revision = "7640c2a9be5b"
branch_labels = None
depends_on = None


def upgrade():
op.add_column(
"setting", sa.Column("custom_thank_you_url", sa.String(), nullable=True)
)


def downgrade():
pass
26 changes: 26 additions & 0 deletions subscribie/blueprints/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
WelcomeEmailTemplateForm,
SetReplyToEmailForm,
UploadFilesForm,
customThankYouUrlForm,
)
from subscribie.auth import (
login_required,
Expand Down Expand Up @@ -1938,6 +1939,31 @@ def vat_settings():
return render_template("admin/settings/vat_settings.html", settings=settings)


@admin.route("/change-thank-you-url", methods=["GET", "POST"])
@login_required
def change_thank_you_url():
settings = Setting.query.first() # Get current shop settings
form = customThankYouUrlForm()

if request.method == "POST":
if request.form.get("default"):
settings.custom_thank_you_url = None
database.session.commit()
flash(f"Custom thank you url changed to default")
return render_template(
"admin/settings/custom_thank_you_page.html",
form=form,
)

elif form.validate():
settings.custom_thank_you_url = form.custom_thank_you_url.data
database.session.commit()
flash(f"Custom thank you url changed to: {form.custom_thank_you_url.data}")
return redirect(url_for("admin.change_thank_you_url", form=form))
return render_template("admin/settings/custom_thank_you_page.html", form=form)
return render_template("admin/settings/custom_thank_you_page.html", form=form)


@admin.route("/donate-enabled-settings", methods=["GET", "POST"])
@login_required
def donations_enabled_settings():
Expand Down
6 changes: 5 additions & 1 deletion subscribie/blueprints/admin/templates/admin/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ <h3 class="card-title">Templates</h3>
<div class="card">
<div class="card-header" id="headingShopSettings">
<button class="btn btn-link btn-block text-left collapsed" type="button" data-toggle="collapse" data-target="#collapseShopSettings" aria-expanded="false" aria-controls="collapseShopSettings">
Shop Settings (TAX{% if shop_default_country_code == "GB" %}, VAT {% endif %} &amp; Rename shop)
Shop Settings (TAX{% if shop_default_country_code == "GB" %}, VAT {% endif %}, Rename Shop, Donations & Thank you Page URL)
</button>
</div>
<div id="collapseShopSettings" class="collapse" aria-labelledby="headingShopSettings">
Expand All @@ -534,6 +534,10 @@ <h3 class="card-title">Templates</h3>
VAT Settings
</a>
{% endif %}
<a class="btn btn-success btn-block"
href="{{ url_for('admin.change_thank_you_url') }}">
Change Thank You Page/Payment Successful Page URL
</a>

</div>

Expand Down
11 changes: 11 additions & 0 deletions subscribie/blueprints/admin/templates/admin/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@
</div>
</section> -->
<main>
{% if form and form.errors %}
<div class="card alert-warning my-3 mx-3 px-3 py-2" role="alert">
<h4 class="alert-heading">Form help</h4>
<hr>
<ul>
{% for key in form.errors %}
<li><em>{{ key }}</em> - {{ form.errors[key][0] }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% with messages = get_flashed_messages() %}
{% if messages %}
<div class="card alert-primary my-3 mx-3 px-3 py-2" role="alert">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{% extends "admin/layout.html" %}
{% block title %} Add Custom Thank you page{% endblock %}

{% block body %}

<h2 class="text-center text-dark mb-3">Custom Thank You Page url</h2>

<div class="container">
<ul class="breadcrumb">
<li class="breadcrumb-item"><a href="/">Shop</a></li>
<li class="breadcrumb-item"><a href="{{ url_for('admin.dashboard') }}">Manage My Shop</a></li>
<li class="breadcrumb-item active" aria-current="page">Custom Thank You Page URL</li>
</ul>
</div>

<main>
<div class="section">
<div class="container">

<div class="row row-cols-1 row-cols-md-2">
<div class="col-md-7">
<h2>Custom Thank You page URL</h2>
<p>
By default, your Subscribers get sent to the default thank you page '/thankyou'.<br />
For most shop owners the default is perfect and no change is needed.<br/><br />
Some shop owners, however, prefer to direct their Subscribers <em>somehwere else</em> after they
have subscribed.</p>
<p>If you would like to set a custom thank you page URL, set one below.</p>
<p>Otherwise, keep the default.</p>
<p>
Please type the exact URL you want your subscribers taken to automatically after subscribing to a plan. Your subscribers will be taken to this page once they have completed sign-up for a plan.
</p>

<form action="" method="POST" action="/">
{{ form.csrf_token }}
<div class="form-group">
<label for="custom_thank_you_url"><b>Custom Thank You page URL:</b></label>
<input type="url" name="custom_thank_you_url" class="form-control"
id="custom_thank_you_url" aria-describedby="custom_thank_you_url"
value="{{ settings.custom_thank_you_url or '' }}"
placeholder="https://example.com/thankyou" required>
</div>
<button name="Save" type="submit" class="btn btn-primary btn-block mb-3">Save</button>
</form>
<form action="" method="POST" action="/">
{{ form.csrf_token }}
<button for="default_thank_you_url" value = "default" name="default" type="submit" class="btn btn-info btn-block mb-3">Use default thank you page</button>
</form>
</div>

</div>

</div> <!-- end container-->
</div> <!-- end section-->
</main>



{% endblock %}
12 changes: 11 additions & 1 deletion subscribie/blueprints/checkout/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,17 @@ def thankyou():
subscription_uuid=uuid,
)

return render_template("thankyou.html")
# If a custom_thank_you_url is set,
# redirect subscriber to the custom_thank_you_url
# otherwise use default thankyou.html
# https://github.com/Subscribie/subscribie/issues/1219
settings = Setting.query.first()

custom_thank_you_url = settings.custom_thank_you_url
if custom_thank_you_url is None:
return render_template("thankyou.html")
else:
return redirect(custom_thank_you_url)


@checkout.route("/stripe-create-checkout-session", methods=["POST"])
Expand Down
13 changes: 13 additions & 0 deletions subscribie/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,18 @@ class SetReplyToEmailForm(StripWhitespaceForm):
email = StringField("email", validators=[DataRequired(), EmailValid()])


class customThankYouUrlForm(FlaskForm):
custom_thank_you_url = StringField(
"url",
validators=[
validators.URL(
require_tld=True,
message="Please enter a valid URL. e.g https://example.com/thankyou",
)
],
default=None,
)


class UploadFilesForm(FlaskForm):
upload = MultipleFileField("Files")
1 change: 1 addition & 0 deletions subscribie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,7 @@ class Setting(database.Model):
api_key_secret_live = database.Column(database.String(), default=None)
api_key_secret_test = database.Column(database.String(), default=None)
donations_enabled = database.Column(database.Boolean(), default=False)
custom_thank_you_url = database.Column(database.String(), default=None)


class File(database.Model):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const { test, expect } = require('@playwright/test');
const SUBSCRIBER_EMAIL_USER = process.env.SUBSCRIBER_EMAIL_USER;
const { admin_login } = require('./features/admin_login');
test.describe("order free plan tests:", () => {
test("@1219 @shop-owner @1219_custom_thank_you_url @1219_shop-owner_enable_custom_url", async ({ page }) => {

await admin_login(page);
await page.goto('/admin/change-thank-you-url');
await page.fill('#custom_thank_you_url', 'https://www.google.com');
await page.click('role=button[name="Save"]');
const custom_url = await page.textContent('text="Custom thank you url changed to: https://www.google.com"');
expect(custom_url === 'Custom thank you url changed to: https://www.google.com');

console.log("Ordering plan with only recurring charge...");
// Buy item with subscription & upfront fee
await page.goto("/"); // Go to home before selecting product
await page.click('[name="Free plan"]');

// Fill in order form
await page.fill('#given_name', 'John');
await page.fill('#family_name', 'Smith');
await page.fill('#email', SUBSCRIBER_EMAIL_USER);
await page.fill('#mobile', '07123456789');
await page.fill('#address_line_one', '123 Short Road');
await page.fill('#city', 'London');
await page.fill('#postcode', 'L01 T3U');
await page.click('.btn-primary-lg');

// Verify get to the thank you page order complete
await page.waitForURL('https://www.google.com');
//changing it back to the default
await page.goto('/admin/change-thank-you-url');
await page.getByRole('button', { name: 'default'}).click();
await new Promise(x => setTimeout(x, 2000));
const default_custom_url = await page.textContent('text="Custom thank you url changed to default"');
expect(default_custom_url === 'Custom thank you url changed to default');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { fetch_upcomming_invoices } = require('./features/fetch_upcomming_invoice

const SUBSCRIBER_EMAIL_USER = process.env.SUBSCRIBER_EMAIL_USER;
test.describe("order plan with cooling off:", () => {
test("@133 @133_shop_owner_order_plan_with_cooling_off_period", async ({ page }) => {
test("@133 @133_subscriber_order_plan_with_cooling_off_period", async ({ page }) => {
console.log("Ordering plan with cooling off");
await admin_login(page);
await set_test_name_cookie(page, "@133_shop_owner_order_plan_with_cooling_off_period");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { set_test_name_cookie } = require('./features/set_test_name_cookie');
const { fetch_upcomming_invoices } = require('./features/fetch_upcomming_invoices');

const SUBSCRIBER_EMAIL_USER = process.env.SUBSCRIBER_EMAIL_USER;
test("@463@subscriber@Ordering plan with VAT @463_order_plan_with_vat", async ({ page }) => {
test("@463@subscriber@Ordering plan with VAT @463_subscriber_order_plan_with_vat", async ({ page }) => {
await admin_login(page);
await set_test_name_cookie(page, "@463_order_plan_with_vat")
console.log("Ordering plan with only recurring charge + VAT...");
Expand Down
18 changes: 13 additions & 5 deletions tests/browser-automated-tests-playwright/run-playwright-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
"@491_shop_owner_create_private_plan",
"@264_shop_owner_create_plan_with_choice_options",
],
"@463_order_plan_with_vat": ["@stripe_connect", "@463_shop_owner_adding_vat"],
"@1219_shop-owner_enable_custom_url": [],
"@463_subscriber_order_plan_with_vat": [
"@stripe_connect",
"@463_shop_owner_adding_vat",
],
"@475_subscriber_order_plan_with_free_trial": [
"@stripe_connect",
"@475_shop_owner_create_free_trial",
Expand All @@ -28,14 +32,18 @@
"@stripe_connect",
"@264_shop_owner_create_plan_with_choice_options",
],
"@133_shop_owner_order_plan_with_cooling_off_period": [
"@133_subscriber_order_plan_with_cooling_off_period": [
"@stripe_connect",
"@133_shop_owner_create_plan_with_cooling_off_period",
],
"@293_shop_owner_order_recurring_plan": ["@stripe_connect"],
"@293-2_subscriber_order_plan_with_only_upfront_charge": ["@stripe_connect"],
"@293_shop_owner_order_recurring_plan": [
"@stripe_connect",
],
"@293-2_subscriber_order_plan_with_only_upfront_charge": [
"@stripe_connect",
],
"@293-3_subscriber_order_plan_with_recurring_and_upfront_charge": [
"@stripe_connect"
"@stripe_connect",
],
"@619_shop_owner_transaction_filter_by_name_and_by_plan_title": [
"@stripe_connect",
Expand Down
4 changes: 3 additions & 1 deletion tests/browser-automated-tests-playwright/worker2.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ test.beforeEach(async ({ page }) => {
});
const plan_creation = require('./tests/shop_owner_plan_creation');
const custom_url = require('./tests/1219_shop_owner_enable_custom_url');
const changing_plans_order = require('./tests/275_shop_owner_changing_plans_order');
Expand All @@ -29,4 +31,4 @@ test.beforeEach(async ({ page }) => {
const enabling_donations = require('./tests/1065_shop_owner_enabling_donations');
const checkout_donations = require('./tests/1065_subscriber_checkout_donation');
*/
*/

0 comments on commit 29fa7c5

Please sign in to comment.