toggle single payments allowed setting
This commit is contained in:
parent
a09abb4a29
commit
9176471551
|
@ -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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
|
@ -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.");
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
|
@ -18,6 +18,10 @@ export default Ember.Controller.extend({
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
|
this.set(
|
||||||
|
"paymentsAllowed",
|
||||||
|
Discourse.SiteSettings.discourse_subscriptions_allow_payments
|
||||||
|
);
|
||||||
this.set(
|
this.set(
|
||||||
"stripe",
|
"stripe",
|
||||||
Stripe(Discourse.SiteSettings.discourse_subscriptions_public_key)
|
Stripe(Discourse.SiteSettings.discourse_subscriptions_public_key)
|
||||||
|
|
|
@ -1,23 +1,25 @@
|
||||||
|
|
||||||
<div class="subscribe-buttons">
|
{{#if paymentsAllowed}}
|
||||||
{{#ds-button
|
<div class="subscribe-buttons">
|
||||||
id="discourse-subscriptions-payment-type-plan"
|
{{#ds-button
|
||||||
selected=planButtonSelected
|
id="discourse-subscriptions-payment-type-plan"
|
||||||
action="selectPlans"
|
selected=planButtonSelected
|
||||||
class="btn-discourse-subscriptions-payment-type"
|
action="selectPlans"
|
||||||
}}
|
class="btn-discourse-subscriptions-payment-type"
|
||||||
{{i18n "discourse_subscriptions.plans.purchase"}}
|
}}
|
||||||
{{/ds-button}}
|
{{i18n "discourse_subscriptions.plans.purchase"}}
|
||||||
|
{{/ds-button}}
|
||||||
|
|
||||||
{{#ds-button
|
{{#ds-button
|
||||||
id="discourse-subscriptions-payment-type-payment"
|
id="discourse-subscriptions-payment-type-payment"
|
||||||
selected=paymentButtonSelected
|
selected=paymentButtonSelected
|
||||||
action="selectPayments"
|
action="selectPayments"
|
||||||
class="btn-discourse-subscriptions-payment-type"
|
class="btn-discourse-subscriptions-payment-type"
|
||||||
}}
|
}}
|
||||||
{{i18n "discourse_subscriptions.payment.purchase"}}
|
{{i18n "discourse_subscriptions.payment.purchase"}}
|
||||||
{{/ds-button}}
|
{{/ds-button}}
|
||||||
</div>
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
|
|
||||||
<div id="stripe-elements">
|
|
||||||
<div id="card-element"></div>
|
|
||||||
<div id="card-action">
|
|
||||||
{{#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}}
|
|
||||||
<div class="popup-tip bad">
|
|
||||||
{{cardError}}
|
|
||||||
</div>
|
|
||||||
{{/if}}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
|
@ -4,6 +4,9 @@
|
||||||
<h2>
|
<h2>
|
||||||
{{model.product.name}}
|
{{model.product.name}}
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
{{model.product.description}}
|
{{model.product.description}}
|
||||||
</p>
|
</p>
|
||||||
|
@ -14,8 +17,11 @@
|
||||||
{{i18n 'discourse_subscriptions.subscribe.card.title'}}
|
{{i18n 'discourse_subscriptions.subscribe.card.title'}}
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
{{payment-options
|
{{payment-options
|
||||||
plans=model.plans
|
plans=model.plans
|
||||||
|
paymentsAllowed=paymentsAllowed
|
||||||
planTypeIsSelected=planTypeIsSelected
|
planTypeIsSelected=planTypeIsSelected
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
|
|
@ -4,13 +4,8 @@ en:
|
||||||
discourse_subscriptions_extra_nav_subscribe: Show the subscribe button in the primary navigation
|
discourse_subscriptions_extra_nav_subscribe: Show the subscribe button in the primary navigation
|
||||||
discourse_subscriptions_public_key: Stripe Publishable Key
|
discourse_subscriptions_public_key: Stripe Publishable Key
|
||||||
discourse_subscriptions_secret_key: Stripe Secret Key
|
discourse_subscriptions_secret_key: Stripe Secret Key
|
||||||
discourse_subscriptions_currency: Default Currency Code. This can be overridden when creating a subscription plan
|
discourse_subscriptions_currency: Default Currency Code. This can be overridden when creating a subscription plan.
|
||||||
discourse_patrons_zip_code: "Show Zip Code"
|
discourse_subscriptions_allow_payments: Allow single payments
|
||||||
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"
|
|
||||||
errors:
|
errors:
|
||||||
discourse_patrons_amount_must_be_currency: "Currency amounts must be currencies without dollar symbol (eg 1.50)"
|
discourse_patrons_amount_must_be_currency: "Currency amounts must be currencies without dollar symbol (eg 1.50)"
|
||||||
js:
|
js:
|
||||||
|
|
|
@ -10,21 +10,9 @@ plugins:
|
||||||
discourse_subscriptions_secret_key:
|
discourse_subscriptions_secret_key:
|
||||||
default: ''
|
default: ''
|
||||||
client: false
|
client: false
|
||||||
discourse_patrons_payment_page:
|
discourse_subscriptions_allow_payments:
|
||||||
|
default: false
|
||||||
client: true
|
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:
|
discourse_subscriptions_currency:
|
||||||
client: true
|
client: true
|
||||||
default: "USD"
|
default: "USD"
|
||||||
|
|
|
@ -17,16 +17,22 @@ componentTest("Discourse Subscriptions payment options have no plans", {
|
||||||
});
|
});
|
||||||
|
|
||||||
componentTest("Discourse Subscriptions payment options has content", {
|
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", [
|
this.set("plans", [
|
||||||
{ currency: "aud", interval: "year", amountDollars: "44.99" },
|
{ currency: "aud", interval: "year", amountDollars: "44.99" },
|
||||||
{ currency: "gdp", interval: "month", amountDollars: "9.99" }
|
{ currency: "gdp", interval: "month", amountDollars: "9.99" }
|
||||||
]);
|
]);
|
||||||
|
|
||||||
this.set("planTypeIsSelected", true);
|
this.set("planTypeIsSelected", true);
|
||||||
|
this.set("paymentsAllowed", true);
|
||||||
|
},
|
||||||
|
|
||||||
|
async test(assert) {
|
||||||
assert.equal(
|
assert.equal(
|
||||||
find(".btn-discourse-subscriptions-payment-type").length,
|
find(".btn-discourse-subscriptions-payment-type").length,
|
||||||
2,
|
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", {
|
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) {
|
async test(assert) {
|
||||||
this.set("plans", [
|
this.set("plans", [
|
||||||
{ currency: "aud", interval: "year", amountDollars: "44.99" }
|
{ currency: "aud", interval: "year", amountDollars: "44.99" }
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
this.set("paymentsAllowed", true);
|
||||||
this.set("planTypeIsSelected", true);
|
this.set("planTypeIsSelected", true);
|
||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
|
|
Loading…
Reference in New Issue