1
0
mirror of synced 2026-08-03 21:56:54 +00:00

product controller

This commit is contained in:
Rimian Perkins
2019-10-25 08:18:16 +11:00
parent 5f71def8a4
commit 6fbcea2cf3
8 changed files with 55 additions and 3 deletions
+1
View File
@@ -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
+21
View File
@@ -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 });
}
});
+1
View File
@@ -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'
+1
View File
@@ -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",
+14
View File
@@ -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