From a1f459dacf2d63c7ce4c3dbe2bbfdb35c51b56fe Mon Sep 17 00:00:00 2001 From: komagata Date: Fri, 8 Apr 2022 17:20:15 +0900 Subject: [PATCH] =?UTF-8?q?Stripe=E3=81=AEBillingPortal=E3=81=B8=E3=81=AE?= =?UTF-8?q?=E3=83=AA=E3=83=B3=E3=82=AF=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/billing_portal_controller.rb | 10 ++++++++++ app/views/application/_user_menu.html.slim | 2 ++ config/routes.rb | 1 + 3 files changed, 13 insertions(+) create mode 100644 app/controllers/billing_portal_controller.rb diff --git a/app/controllers/billing_portal_controller.rb b/app/controllers/billing_portal_controller.rb new file mode 100644 index 00000000000..a01cc8f9ab5 --- /dev/null +++ b/app/controllers/billing_portal_controller.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class BillingPortalController < ApplicationController + before_action :require_login + + def create + session = Stripe::BillingPortal::Session.create(customer: current_user.customer_id) + redirect_to session.url + end +end diff --git a/app/views/application/_user_menu.html.slim b/app/views/application/_user_menu.html.slim index 678bfd9fca9..48ee21b58e5 100644 --- a/app/views/application/_user_menu.html.slim +++ b/app/views/application/_user_menu.html.slim @@ -8,6 +8,8 @@ | 登録情報変更 - if !current_user.adviser? && !current_user.mentor? && !current_user.trainee? - if current_user.card? + li.header-dropdown__item + = link_to 'お支払い情報', billing_portal_path, method: :post, class: 'header-dropdown__item-link' li.header-dropdown__item = link_to 'クレジットカード情報', card_path, class: 'header-dropdown__item-link' li.header-dropdown__item diff --git a/config/routes.rb b/config/routes.rb index 1330b2db0ec..6831ceee8fc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -71,6 +71,7 @@ resources :products, only: %i(index), controller: "companies/products" end resources :generations, only: %i(show index) + resource :billing_portal, only: :create, controller: "billing_portal" get "articles/tags/:tag", to: "articles#index", as: :tag, tag: /.+/ get "pages/tags/:tag", to: "pages#index", as: :pages_tag, tag: /.+/, format: "html" get "questions/tags/:tag", to: "questions#index", as: :questions_tag, tag: /.+/, format: "html"