diff --git a/assets/javascripts/discourse/components/donation-form.js.es6 b/assets/javascripts/discourse/components/donation-form.js.es6
deleted file mode 100644
index 6b182a3..0000000
--- a/assets/javascripts/discourse/components/donation-form.js.es6
+++ /dev/null
@@ -1,50 +0,0 @@
-import { default as computed } from "ember-addons/ember-computed-decorators";
-
-export default Ember.Component.extend({
- @computed("confirmation.card.last4")
- last4() {
- return this.get("confirmation.card.last4");
- },
-
- init() {
- this._super(...arguments);
-
- const settings = Discourse.SiteSettings;
- const amounts = settings.discourse_patrons_amounts.split("|");
-
- this.setProperties({
- confirmation: false,
- currency: settings.discourse_donations_currency,
- amounts,
- amount: amounts[0]
- });
- },
-
- actions: {
- closeModal() {
- this.set("paymentError", false);
- this.set("confirmation", false);
- },
-
- handleConfirmStripeCard(paymentMethod, receiptEmail) {
- this.set("receiptEmail", receiptEmail);
- this.set("confirmation", paymentMethod);
- },
-
- confirmStripeCard() {
- const data = {
- payment_method_id: this.confirmation.id,
- amount: this.amount,
- receipt_email: this.receiptEmail
- };
-
- this.stripePaymentHandler(data).then(paymentIntent => {
- if (paymentIntent.error) {
- this.set("paymentError", paymentIntent.error);
- } else {
- this.paymentSuccessHandler(paymentIntent.id);
- }
- });
- }
- }
-});
diff --git a/assets/javascripts/discourse/components/stripe-card.js.es6 b/assets/javascripts/discourse/components/stripe-card.js.es6
deleted file mode 100644
index 2d1e492..0000000
--- a/assets/javascripts/discourse/components/stripe-card.js.es6
+++ /dev/null
@@ -1,77 +0,0 @@
-export default Ember.Component.extend({
- init() {
- this._super(...arguments);
-
- const settings = Discourse.SiteSettings;
-
- this.setProperties({
- cardError: false,
- color: jQuery("body").css("color"),
- backgroundColor: jQuery("body").css("background-color"),
- stripe: Stripe(settings.discourse_subscriptions_public_key)
- });
- },
-
- didInsertElement() {
- this._super(...arguments);
-
- const color = this.get("color");
-
- const style = {
- base: {
- color,
- iconColor: color,
- "::placeholder": { color }
- }
- };
-
- const elements = this.stripe.elements();
- const card = elements.create("card", { style, hidePostalCode: true });
-
- card.mount("#card-element");
-
- this.set("card", card);
-
- card.on("change", result => {
- this.set("cardError", false);
-
- if (result.error) {
- this.set("cardError", result.error.message);
- }
- });
- },
-
- validateBilling() {
- const billing = this.get("billing");
- const deleteEmpty = key => {
- if (Ember.isEmpty(billing.get(key))) {
- billing.set(key, undefined);
- }
- };
- ["name", "phone"].forEach(key => deleteEmpty(key));
- },
-
- actions: {
- submitStripeCard() {
- this.validateBilling();
-
- const paymentOptions = { billing_details: this.get("billing") };
-
- this.stripe.createPaymentMethod("card", this.card, paymentOptions).then(
- result => {
- if (result.error) {
- this.set("cardError", result.error.message);
- } else {
- this.handleConfirmStripeCard(
- result.paymentMethod,
- this.get("billing.email")
- );
- }
- },
- () => {
- this.set("cardError", "Unknown error.");
- }
- );
- }
- }
-});
diff --git a/assets/javascripts/discourse/controllers/s-show.js.es6 b/assets/javascripts/discourse/controllers/s-show.js.es6
index 4a015cb..d0ea851 100644
--- a/assets/javascripts/discourse/controllers/s-show.js.es6
+++ b/assets/javascripts/discourse/controllers/s-show.js.es6
@@ -18,6 +18,10 @@ export default Ember.Controller.extend({
init() {
this._super(...arguments);
+ this.set(
+ "paymentsAllowed",
+ Discourse.SiteSettings.discourse_subscriptions_allow_payments
+ );
this.set(
"stripe",
Stripe(Discourse.SiteSettings.discourse_subscriptions_public_key)
diff --git a/assets/javascripts/discourse/templates/components/payment-options.hbs b/assets/javascripts/discourse/templates/components/payment-options.hbs
index c3ee8c1..312e389 100644
--- a/assets/javascripts/discourse/templates/components/payment-options.hbs
+++ b/assets/javascripts/discourse/templates/components/payment-options.hbs
@@ -1,23 +1,25 @@
-
+{{/if}}
diff --git a/assets/javascripts/discourse/templates/components/stripe-card.hbs b/assets/javascripts/discourse/templates/components/stripe-card.hbs
deleted file mode 100644
index 3a4b520..0000000
--- a/assets/javascripts/discourse/templates/components/stripe-card.hbs
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
- {{#d-button action="submitStripeCard" class="btn btn-primary btn-payment btn-discourse-patrons"}}
- {{i18n 'discourse_subscriptions.buttons.make_payment'}} {{format-curency amount}}
- {{/d-button}}
-
- {{#if cardError}}
-
- {{/if}}
-
-
diff --git a/assets/javascripts/discourse/templates/s/show.hbs b/assets/javascripts/discourse/templates/s/show.hbs
index 318cf56..5c1d6cd 100644
--- a/assets/javascripts/discourse/templates/s/show.hbs
+++ b/assets/javascripts/discourse/templates/s/show.hbs
@@ -4,6 +4,9 @@
{{model.product.name}}
+
+
+
{{model.product.description}}
@@ -14,8 +17,11 @@
{{i18n 'discourse_subscriptions.subscribe.card.title'}}
+
+
{{payment-options
plans=model.plans
+ paymentsAllowed=paymentsAllowed
planTypeIsSelected=planTypeIsSelected
}}
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index fd2cc39..c23a3a2 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -4,13 +4,8 @@ en:
discourse_subscriptions_extra_nav_subscribe: Show the subscribe button in the primary navigation
discourse_subscriptions_public_key: Stripe Publishable Key
discourse_subscriptions_secret_key: Stripe Secret Key
- discourse_subscriptions_currency: Default Currency Code. This can be overridden when creating a subscription plan
- discourse_patrons_zip_code: "Show Zip Code"
- discourse_patrons_billing_address: "Collect billing address"
- discourse_patrons_payment_page: "Text to be added to enter payments page. Markdown is supported."
- discourse_patrons_success_page: "Text to be added to success page. Markdown is supported."
- discourse_patrons_payment_description: "This is sent to Stripe and shows in the payment information"
- discourse_patrons_amounts: "Payment amounts a user can select"
+ discourse_subscriptions_currency: Default Currency Code. This can be overridden when creating a subscription plan.
+ discourse_subscriptions_allow_payments: Allow single payments
errors:
discourse_patrons_amount_must_be_currency: "Currency amounts must be currencies without dollar symbol (eg 1.50)"
js:
diff --git a/config/settings.yml b/config/settings.yml
index 25d7e36..0ed6c2e 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -10,21 +10,9 @@ plugins:
discourse_subscriptions_secret_key:
default: ''
client: false
- discourse_patrons_payment_page:
+ discourse_subscriptions_allow_payments:
+ default: false
client: true
- default: ''
- discourse_patrons_success_page:
- client: true
- default: ''
- discourse_patrons_payment_description:
- client: true
- default: ''
- discourse_patrons_amounts:
- client: true
- type: list
- default: '1.00|2.00|5.00|10.00|20.00|50.00|100.00'
- regex: "^([0-9]+.[0-9]{2}\\|)+[0-9]+.[0-9]{2}$"
- regex_error: "site_settings.errors.discourse_patrons_amount_must_be_currency"
discourse_subscriptions_currency:
client: true
default: "USD"
diff --git a/test/javascripts/components/payment-options-test.js.es6 b/test/javascripts/components/payment-options-test.js.es6
index c12f2d0..d2d72a2 100644
--- a/test/javascripts/components/payment-options-test.js.es6
+++ b/test/javascripts/components/payment-options-test.js.es6
@@ -17,16 +17,22 @@ componentTest("Discourse Subscriptions payment options have no plans", {
});
componentTest("Discourse Subscriptions payment options has content", {
- template: `{{payment-options plans=plans planTypeIsSelected=planTypeIsSelected}}`,
+ template: `{{payment-options
+ paymentsAllowed=paymentsAllowed
+ plans=plans
+ planTypeIsSelected=planTypeIsSelected}}`,
- async test(assert) {
+ beforeEach() {
this.set("plans", [
{ currency: "aud", interval: "year", amountDollars: "44.99" },
{ currency: "gdp", interval: "month", amountDollars: "9.99" }
]);
this.set("planTypeIsSelected", true);
+ this.set("paymentsAllowed", true);
+ },
+ async test(assert) {
assert.equal(
find(".btn-discourse-subscriptions-payment-type").length,
2,
@@ -59,14 +65,46 @@ componentTest("Discourse Subscriptions payment options has content", {
}
});
+componentTest("Discourse Subscriptions payments allowed setting", {
+ template: `{{payment-options plans=plans paymentsAllowed=paymentsAllowed}}`,
+
+ async test(assert) {
+ this.set("paymentsAllowed", true);
+
+ assert.ok(
+ find("#discourse-subscriptions-payment-type-plan").length,
+ "The plan type button displayed"
+ );
+ assert.ok(
+ find("#discourse-subscriptions-payment-type-payment").length,
+ "The payment type button displayed"
+ );
+
+ this.set("paymentsAllowed", false);
+
+ assert.notOk(
+ find("#discourse-subscriptions-payment-type-plan").length,
+ "The plan type button hidden"
+ );
+ assert.notOk(
+ find("#discourse-subscriptions-payment-type-payment").length,
+ "The payment type button hidden"
+ );
+ }
+});
+
componentTest("Discourse Subscriptions payment type plan", {
- template: `{{payment-options plans=plans planTypeIsSelected=planTypeIsSelected}}`,
+ template: `{{payment-options
+ paymentsAllowed=paymentsAllowed
+ plans=plans
+ planTypeIsSelected=planTypeIsSelected}}`,
async test(assert) {
this.set("plans", [
{ currency: "aud", interval: "year", amountDollars: "44.99" }
]);
+ this.set("paymentsAllowed", true);
this.set("planTypeIsSelected", true);
assert.equal(