subscriptions controller

This commit is contained in:
Rimian Perkins 2019-10-14 09:52:43 +11:00
parent fcfb826929
commit bab76db863
5 changed files with 44 additions and 2 deletions

View File

@ -0,0 +1,20 @@
# frozen_string_literal: true
module DiscoursePatrons
class SubscriptionsController < ::ApplicationController
include DiscoursePatrons::Stripe
before_action :set_api_key
def create
subscription = ::Stripe::Subscription.create(
customer: params[:customer],
items: [
{ plan: 'plan_CBXbz9i7AIOTzr' },
]
)
render_json_dump subscription
end
end
end

View File

@ -13,7 +13,7 @@ export default Ember.Controller.extend({
},
paymentSuccessHandler(paymentIntentId) {
// DiscourseURL.redirectTo(`patrons/${paymentIntentId}`);
DiscourseURL.redirectTo(`patrons/${paymentIntentId}`);
}
}
});

View File

@ -27,7 +27,8 @@ export default Ember.Controller.extend({
return ajax("/patrons/customers", { method: "post", data }).then(
result => {
// create subscription
console.log(4, result, this.get('model'));
// do plan
}
);
}

View File

@ -44,6 +44,7 @@ after_initialize do
"../app/controllers/customers_controller",
"../app/controllers/patrons_controller",
"../app/controllers/plans_controller",
"../app/controllers/subscriptions_controller",
"../app/models/payment",
"../app/serializers/payment_serializer",
].each { |path| require File.expand_path(path, __FILE__) }

View File

@ -0,0 +1,20 @@
# frozen_string_literal: true
require 'rails_helper'
module DiscoursePatrons
RSpec.describe SubscriptionsController do
describe "create" do
let(:user) { Fabricate(:user, email: 'hello.2@example.com') }
before do
sign_in(user)
end
it "creates a subscription with a customer" do
::Stripe::Subscription.expects(:create).with(has_entry(customer: 'cus_1234'))
post "/patrons/subscriptions.json", params: { customer: 'cus_1234' }
end
end
end
end