Merge branch 'feature/one-time-payment' of github.com:rimian/discourse-subscriptions into feature/one-time-payment
This commit is contained in:
@@ -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,5 +0,0 @@
|
||||
export default Ember.Component.extend({
|
||||
classNames: "donation-list",
|
||||
hasSubscriptions: Ember.computed.notEmpty("subscriptions"),
|
||||
hasCharges: Ember.computed.notEmpty("charges")
|
||||
});
|
||||
@@ -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() {
|
||||
this._super(...arguments);
|
||||
this.set(
|
||||
"paymentsAllowed",
|
||||
Discourse.SiteSettings.discourse_subscriptions_allow_payments
|
||||
);
|
||||
this.set(
|
||||
"stripe",
|
||||
Stripe(Discourse.SiteSettings.discourse_subscriptions_public_key)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import EmberObject from "@ember/object";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
|
||||
const Payment = Discourse.Model.extend({
|
||||
const Payment = EmberObject.extend({
|
||||
save() {
|
||||
const data = {
|
||||
payment_method: this.payment_method,
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import computed from "ember-addons/ember-computed-decorators";
|
||||
import EmberObject from "@ember/object";
|
||||
import computed from "discourse-common/utils/decorators";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
|
||||
const Plan = Discourse.Model.extend({
|
||||
const Plan = EmberObject.extend({
|
||||
amountDollars: Ember.computed("amount", {
|
||||
get() {
|
||||
return parseFloat(this.get("amount") / 100).toFixed(2);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import EmberObject from "@ember/object";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
|
||||
const Product = Discourse.Model.extend({});
|
||||
const Product = EmberObject.extend({});
|
||||
|
||||
Product.reopenClass({
|
||||
findAll() {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import EmberObject from "@ember/object";
|
||||
import computed from "discourse-common/utils/decorators";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
|
||||
const UserPayment = EmberObject.extend({
|
||||
@computed("amount")
|
||||
amountDollars(amount) {
|
||||
return parseFloat(amount / 100).toFixed(2);
|
||||
}
|
||||
});
|
||||
|
||||
UserPayment.reopenClass({
|
||||
findAll() {
|
||||
return ajax("/s/user/payments", { method: "get" }).then(result =>
|
||||
result.map(payment => {
|
||||
return UserPayment.create(payment);
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
export default UserPayment;
|
||||
@@ -1,8 +1,9 @@
|
||||
import EmberObject from "@ember/object";
|
||||
import computed from "ember-addons/ember-computed-decorators";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import Plan from "discourse/plugins/discourse-subscriptions/discourse/models/plan";
|
||||
|
||||
const UserSubscription = Discourse.Model.extend({
|
||||
const UserSubscription = EmberObject.extend({
|
||||
@computed("status")
|
||||
canceled(status) {
|
||||
return status === "canceled";
|
||||
|
||||
@@ -7,7 +7,7 @@ export default Route.extend({
|
||||
const product_id = params["subscription-id"];
|
||||
|
||||
const product = Product.find(product_id);
|
||||
const plans = Plan.findAll({ product_id: product_id });
|
||||
const plans = Plan.findAll({ product_id });
|
||||
|
||||
return Ember.RSVP.hash({ plans, product });
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import Route from "@ember/routing/route";
|
||||
import Invoice from "discourse/plugins/discourse-subscriptions/discourse/models/invoice";
|
||||
import UserPayment from "discourse/plugins/discourse-subscriptions/discourse/models/user-payment";
|
||||
|
||||
export default Route.extend({
|
||||
templateName: "user/billing/payments",
|
||||
|
||||
model() {
|
||||
return Invoice.findAll();
|
||||
return UserPayment.findAll();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
{{#if hasSubscriptions}}
|
||||
<div class="subscription-list">
|
||||
<div class="underline">{{i18n 'discourse_donations.donations.subscriptions'}}</div>
|
||||
<ul>
|
||||
{{#each subscriptions as |s|}}
|
||||
<li>{{donation-row subscription=s.subscription customer=customer new=s.new}}</li>
|
||||
{{#if s.invoices}}
|
||||
<ul>
|
||||
{{#each s.invoices as |invoice|}}
|
||||
<li>{{donation-row invoice=invoice customer=customer new=s.new}}</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
</ul>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{#if hasCharges}}
|
||||
<div class="charge-list">
|
||||
<div class='underline'>{{i18n 'discourse_donations.donations.charges'}}</div>
|
||||
<ul>
|
||||
{{#each charges as |charge|}}
|
||||
<li>{{donation-row charge=charge customer=customer new=charge.new}}</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
</div>
|
||||
{{/if}}
|
||||
@@ -1,23 +1,25 @@
|
||||
|
||||
<div class="subscribe-buttons">
|
||||
{{#ds-button
|
||||
id="discourse-subscriptions-payment-type-plan"
|
||||
selected=planButtonSelected
|
||||
action="selectPlans"
|
||||
class="btn-discourse-subscriptions-payment-type"
|
||||
}}
|
||||
{{i18n "discourse_subscriptions.plans.purchase"}}
|
||||
{{/ds-button}}
|
||||
{{#if paymentsAllowed}}
|
||||
<div class="subscribe-buttons">
|
||||
{{#ds-button
|
||||
id="discourse-subscriptions-payment-type-plan"
|
||||
selected=planButtonSelected
|
||||
action="selectPlans"
|
||||
class="btn-discourse-subscriptions-payment-type"
|
||||
}}
|
||||
{{i18n "discourse_subscriptions.plans.purchase"}}
|
||||
{{/ds-button}}
|
||||
|
||||
{{#ds-button
|
||||
id="discourse-subscriptions-payment-type-payment"
|
||||
selected=paymentButtonSelected
|
||||
action="selectPayments"
|
||||
class="btn-discourse-subscriptions-payment-type"
|
||||
}}
|
||||
{{i18n "discourse_subscriptions.payment.purchase"}}
|
||||
{{/ds-button}}
|
||||
</div>
|
||||
{{#ds-button
|
||||
id="discourse-subscriptions-payment-type-payment"
|
||||
selected=paymentButtonSelected
|
||||
action="selectPayments"
|
||||
class="btn-discourse-subscriptions-payment-type"
|
||||
}}
|
||||
{{i18n "discourse_subscriptions.payment.purchase"}}
|
||||
{{/ds-button}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
<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>
|
||||
{{model.product.name}}
|
||||
</h2>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>
|
||||
{{model.product.description}}
|
||||
</p>
|
||||
@@ -14,8 +17,11 @@
|
||||
{{i18n 'discourse_subscriptions.subscribe.card.title'}}
|
||||
</h2>
|
||||
|
||||
<hr>
|
||||
|
||||
{{payment-options
|
||||
plans=model.plans
|
||||
paymentsAllowed=paymentsAllowed
|
||||
planTypeIsSelected=planTypeIsSelected
|
||||
}}
|
||||
|
||||
|
||||
@@ -1,22 +1,15 @@
|
||||
|
||||
{{#if model}}
|
||||
<table class="topic-list">
|
||||
<table class="table discourse-subscriptions-user-table">
|
||||
<thead>
|
||||
<th>{{i18n 'discourse_subscriptions.user.billing.invoices.amount'}}</th>
|
||||
<th>{{i18n 'discourse_subscriptions.user.billing.invoices.number'}}</th>
|
||||
<th>{{i18n 'discourse_subscriptions.user.billing.invoices.created_at'}}</th>
|
||||
<th></th>
|
||||
<th>{{i18n 'discourse_subscriptions.user.payments.id'}}</th>
|
||||
<th>{{i18n 'discourse_subscriptions.user.payments.amount'}}</th>
|
||||
<th>{{i18n 'discourse_subscriptions.user.payments.created_at'}}</th>
|
||||
</thead>
|
||||
{{#each model as |invoice|}}
|
||||
{{#each model as |payment|}}
|
||||
<tr>
|
||||
<td>{{invoice.amount_paid}}</td>
|
||||
<td>{{invoice.number}}</td>
|
||||
<td>{{format-unix-date invoice.created}}</td>
|
||||
<td class="td-right">
|
||||
<a href="{{invoice.invoice_pdf}}" class="btn btn-icon">
|
||||
{{d-icon "download"}}
|
||||
</a>
|
||||
</td>
|
||||
<td>{{payment.id}}</td>
|
||||
<td>{{format-currency payment.currency payment.amountDollars}}</td>
|
||||
<td>{{format-unix-date payment.created}}</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</table>
|
||||
|
||||
@@ -1,34 +1,32 @@
|
||||
{{#d-section pageClass="user-subscriptions" class="user-content"}}
|
||||
{{#if model}}
|
||||
<table class="table discourse-subscriptions-user-table">
|
||||
<thead>
|
||||
<th>{{i18n 'discourse_subscriptions.user.subscriptions.id'}}</th>
|
||||
<th>{{i18n 'discourse_subscriptions.user.plans.product'}}</th>
|
||||
<th>{{i18n 'discourse_subscriptions.user.plans.rate'}}</th>
|
||||
<th>{{i18n 'discourse_subscriptions.user.subscriptions.status'}}</th>
|
||||
<th>{{i18n 'discourse_subscriptions.user.subscriptions.created_at'}}</th>
|
||||
<th></th>
|
||||
</thead>
|
||||
{{#each model as |subscription|}}
|
||||
<tr>
|
||||
<td>{{subscription.id}}</td>
|
||||
<td>{{subscription.product.name}}</td>
|
||||
<td>{{subscription.plan.subscriptionRate}}</td>
|
||||
<td>{{subscription.status}}</td>
|
||||
<td>{{format-unix-date subscription.created}}</td>
|
||||
<td class="td-right">
|
||||
{{#if subscription.loading}}
|
||||
{{loading-spinner size="small"}}
|
||||
{{else}}
|
||||
{{d-button disabled=subscription.canceled label="cancel" action=(route-action "cancelSubscription" subscription) icon="times"}}
|
||||
{{/if}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</table>
|
||||
{{else}}
|
||||
<div class="alert alert-info">
|
||||
{{i18n 'discourse_subscriptions.user.subscriptions_help'}}
|
||||
</div>
|
||||
{{/if}}
|
||||
{{/d-section}}
|
||||
{{#if model}}
|
||||
<table class="table discourse-subscriptions-user-table">
|
||||
<thead>
|
||||
<th>{{i18n 'discourse_subscriptions.user.subscriptions.id'}}</th>
|
||||
<th>{{i18n 'discourse_subscriptions.user.plans.product'}}</th>
|
||||
<th>{{i18n 'discourse_subscriptions.user.plans.rate'}}</th>
|
||||
<th>{{i18n 'discourse_subscriptions.user.subscriptions.status'}}</th>
|
||||
<th>{{i18n 'discourse_subscriptions.user.subscriptions.created_at'}}</th>
|
||||
<th></th>
|
||||
</thead>
|
||||
{{#each model as |subscription|}}
|
||||
<tr>
|
||||
<td>{{subscription.id}}</td>
|
||||
<td>{{subscription.product.name}}</td>
|
||||
<td>{{subscription.plan.subscriptionRate}}</td>
|
||||
<td>{{subscription.status}}</td>
|
||||
<td>{{format-unix-date subscription.created}}</td>
|
||||
<td class="td-right">
|
||||
{{#if subscription.loading}}
|
||||
{{loading-spinner size="small"}}
|
||||
{{else}}
|
||||
{{d-button disabled=subscription.canceled label="cancel" action=(route-action "cancelSubscription" subscription) icon="times"}}
|
||||
{{/if}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</table>
|
||||
{{else}}
|
||||
<div class="alert alert-info">
|
||||
{{i18n 'discourse_subscriptions.user.subscriptions_help'}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
Reference in New Issue
Block a user