list customer subscriptions
This commit is contained in:
parent
7963d6dea2
commit
03cbc235b1
|
@ -8,13 +8,15 @@ module DiscoursePatrons
|
||||||
|
|
||||||
def index
|
def index
|
||||||
begin
|
begin
|
||||||
customer = DiscoursePatrons::Customer.find_user(current_user)
|
customers = ::Stripe::Customer.list(
|
||||||
|
email: current_user.email,
|
||||||
|
expand: ['data.subscriptions']
|
||||||
|
)
|
||||||
|
|
||||||
if customer.present?
|
|
||||||
subscriptions = ::Stripe::Subscription.list(customer: customer.customer_id).data
|
subscriptions = customers[:data].map do |customer|
|
||||||
else
|
customer[:subscriptions][:data]
|
||||||
subscriptions = []
|
end.flatten(1)
|
||||||
end
|
|
||||||
|
|
||||||
render_json_dump subscriptions
|
render_json_dump subscriptions
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,8 @@ export default Ember.Controller.extend({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
paymentSuccessHandler(paymentIntentId) {
|
paymentSuccessHandler(/* paymentIntentId */) {
|
||||||
bootbox.alert("ok payment good... some kind of message");
|
bootbox.alert(I18n.t("discourse_patrons.transactions.payment.success"));
|
||||||
this.transitionToRoute(
|
this.transitionToRoute(
|
||||||
"user.billing",
|
"user.billing",
|
||||||
Discourse.User.current().username.toLowerCase()
|
Discourse.User.current().username.toLowerCase()
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import Group from "discourse/plugins/discourse-patrons/discourse/models/group";
|
|
||||||
import Plan from "discourse/plugins/discourse-patrons/discourse/models/plan";
|
import Plan from "discourse/plugins/discourse-patrons/discourse/models/plan";
|
||||||
import Subscription from "discourse/plugins/discourse-patrons/discourse/models/subscription";
|
import Subscription from "discourse/plugins/discourse-patrons/discourse/models/subscription";
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
{{#if model}}
|
{{#if model}}
|
||||||
<table class="topic-list">
|
<table class="topic-list">
|
||||||
<thead>
|
<thead>
|
||||||
<th>{{i18n 'discourse_patrons.user.billing.subscriptions.created_at'}}</th>
|
<th>{{i18n 'discourse_patrons.user.subscriptions.created_at'}}</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</thead>
|
</thead>
|
||||||
{{#each model as |subscription|}}
|
{{#each model as |subscription|}}
|
||||||
|
|
|
@ -17,6 +17,9 @@ en:
|
||||||
discourse_patrons:
|
discourse_patrons:
|
||||||
title: Discourse Patrons
|
title: Discourse Patrons
|
||||||
optional: Optional
|
optional: Optional
|
||||||
|
transactions:
|
||||||
|
payment:
|
||||||
|
success: Your payment was successful
|
||||||
navigation:
|
navigation:
|
||||||
subscriptions: Subscriptions
|
subscriptions: Subscriptions
|
||||||
subscribe: Subscribe
|
subscribe: Subscribe
|
||||||
|
|
|
@ -5,6 +5,11 @@ require 'rails_helper'
|
||||||
module DiscoursePatrons
|
module DiscoursePatrons
|
||||||
RSpec.describe SubscriptionsController do
|
RSpec.describe SubscriptionsController do
|
||||||
context "not authenticated" do
|
context "not authenticated" do
|
||||||
|
it "does not get the subscriptions" do
|
||||||
|
::Stripe::Customer.expects(:list).never
|
||||||
|
get "/patrons/subscriptions.json"
|
||||||
|
end
|
||||||
|
|
||||||
it "does not create a subscription" do
|
it "does not create a subscription" do
|
||||||
::Stripe::Plan.expects(:retrieve).never
|
::Stripe::Plan.expects(:retrieve).never
|
||||||
::Stripe::Subscription.expects(:create).never
|
::Stripe::Subscription.expects(:create).never
|
||||||
|
@ -25,16 +30,26 @@ module DiscoursePatrons
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "index" do
|
describe "index" do
|
||||||
it "does not get subscriptions if there is no customer" do
|
let(:customers) do
|
||||||
::Stripe::Subscription.expects(:create).never
|
{
|
||||||
get "/patrons/subscriptions.json"
|
data: [{
|
||||||
expect(response.body).to eq "[]"
|
id: "cus_23456",
|
||||||
|
subscriptions: {
|
||||||
|
data: [{ id: "sub_1234" }, { id: "sub_4567" }]
|
||||||
|
},
|
||||||
|
}]
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
it "gets subscriptions" do
|
it "gets subscriptions" do
|
||||||
DiscoursePatrons::Customer.create(user_id: user.id, customer_id: 'cus_id5678')
|
::Stripe::Customer.expects(:list).with(
|
||||||
::Stripe::Subscription.expects(:list).with(customer: 'cus_id5678')
|
email: user.email,
|
||||||
|
expand: ['data.subscriptions']
|
||||||
|
).returns(customers)
|
||||||
|
|
||||||
get "/patrons/subscriptions.json"
|
get "/patrons/subscriptions.json"
|
||||||
|
|
||||||
|
expect(JSON.parse(response.body)).to eq([{"id"=>"sub_1234"}, {"id"=>"sub_4567"}])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -129,7 +144,7 @@ module DiscoursePatrons
|
||||||
describe "delete" do
|
describe "delete" do
|
||||||
it "deletes a subscription" do
|
it "deletes a subscription" do
|
||||||
::Stripe::Subscription.expects(:delete).with('sub_12345')
|
::Stripe::Subscription.expects(:delete).with('sub_12345')
|
||||||
delete "/patrons/subscription/sub_12345.json"
|
delete "/patrons/subscriptions/sub_12345.json"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue