create the subscription

This commit is contained in:
Rimian Perkins
2019-10-14 11:47:49 +11:00
parent 51a0820397
commit 4e615908f4
6 changed files with 26 additions and 8 deletions
@@ -21,14 +21,27 @@ export default Ember.Controller.extend({
// var errorElement = document.getElementById('card-errors');
// errorElement.textContent = result.error.message;
} else {
const data = {
const customerData = {
source: result.token.id
};
return ajax("/patrons/customers", { method: "post", data }).then(
result => {
console.log(4, result, this.get('model'));
// do plan
return ajax("/patrons/customers", { method: "post", data: customerData }).then(
customer => {
// TODO move default plan into settings
if(this.get('model.selectedPlan') == undefined) {
this.set('model.selectedPlan', this.get('model.plans.firstObject'));
}
const subscriptionData = {
customer: customer.id,
plan: this.get('model.selectedPlan')
};
return ajax("/patrons/subscriptions", { method: "post", data: subscriptionData }).then(
subscription => {
console.log(3, subscription);
}
);
}
);
}
@@ -5,7 +5,6 @@ export default Discourse.Route.extend({
model() {
const group = Group.find();
const plans = Plan.find().then(results => results.map(p => p.id));
return Ember.RSVP.hash({ group, plans });
}
});
@@ -11,7 +11,7 @@
</p>
</div>
<div class="section-column">
{{combo-box valueAttribute="id" content=model.plans value=model.plan}}
{{combo-box valueAttribute="id" content=model.plans value=model.selectedPlan}}
{{#d-button
action="stripePaymentHandler"