product controller
This commit is contained in:
parent
5f71def8a4
commit
6fbcea2cf3
|
@ -10,6 +10,7 @@ module DiscoursePatrons
|
|||
begin
|
||||
plans = ::Stripe::Plan.list(active: true)
|
||||
|
||||
# TODO: Serialize. Remove some attributes like meta.group_name
|
||||
render_json_dump plans.data
|
||||
|
||||
rescue ::Stripe::InvalidRequestError => e
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DiscoursePatrons
|
||||
class ProductsController < ::ApplicationController
|
||||
include DiscoursePatrons::Stripe
|
||||
|
||||
before_action :set_api_key
|
||||
|
||||
def index
|
||||
begin
|
||||
products = ::Stripe::Product.list(active: true)
|
||||
|
||||
# TODO: Serialize. Remove some attributes like metadata
|
||||
render_json_dump products.data
|
||||
|
||||
rescue ::Stripe::InvalidRequestError => e
|
||||
return render_json_error e.message
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,13 @@
|
|||
import { ajax } from "discourse/lib/ajax";
|
||||
|
||||
const Product = Discourse.Model.extend({});
|
||||
|
||||
Product.reopenClass({
|
||||
findAll() {
|
||||
return ajax("/patrons/products", { method: "get" }).then(result =>
|
||||
result.map(product => Product.create(product))
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
export default Product;
|
|
@ -1,6 +1,8 @@
|
|||
export default function() {
|
||||
this.route("patrons", function() {
|
||||
this.route("subscribe");
|
||||
this.route("subscribe", function() {
|
||||
this.route("product", { path: ":product_id" })
|
||||
});
|
||||
this.route("show", { path: ":pid" });
|
||||
});
|
||||
}
|
||||
|
|
|
@ -10,10 +10,9 @@ export default Discourse.Route.extend({
|
|||
return `$${toCurrency(plan.amount)} ${plan.currency.toUpperCase()} / ${plan.interval}`;
|
||||
};
|
||||
|
||||
const group = Group.find();
|
||||
const plans = Plan.findAll().then(results => results.map(p => planSelectText(p)));
|
||||
const subscription = Subscription.create();
|
||||
|
||||
return Ember.RSVP.hash({ group, plans, subscription });
|
||||
return Ember.RSVP.hash({ plans, subscription });
|
||||
}
|
||||
});
|
||||
|
|
|
@ -15,6 +15,7 @@ DiscoursePatrons::Engine.routes.draw do
|
|||
resources :customers, only: [:create]
|
||||
resources :subscriptions, only: [:create]
|
||||
resources :plans, only: [:index]
|
||||
resources :products, only: [:index]
|
||||
resources :patrons, only: [:index, :create]
|
||||
|
||||
get '/' => 'patrons#index'
|
||||
|
|
|
@ -50,6 +50,7 @@ after_initialize do
|
|||
"../app/controllers/customers_controller",
|
||||
"../app/controllers/patrons_controller",
|
||||
"../app/controllers/plans_controller",
|
||||
"../app/controllers/products_controller",
|
||||
"../app/controllers/subscriptions_controller",
|
||||
"../app/models/payment",
|
||||
"../app/serializers/payment_serializer",
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
module DiscoursePatrons
|
||||
RSpec.describe ProductsController do
|
||||
describe "index" do
|
||||
it "lists the active products" do
|
||||
::Stripe::Product.expects(:list).with(active: true)
|
||||
get "/patrons/products.json"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue