app/controllers/stripe_controller.rb
# TODO: This has mostly been taken from stripe documentation and it's not very robust right now.
# Rewrite this with strong params etc
# And move it to Background jobs
This has mostly been taken from stripe documentation and it's not very robust right now.
Rewrite this with strong params etc
And move it to Background jobs
This has mostly been taken from stripe documentation and it ' s not very robust right now . Rewrite this with strong params etc And move it to Background jobs
def create_checkout_session
    data = JSON.parse(request.body.read)
    stripe_id = @current_user.subscription.stripe_id
    if stripe_id.nil?
      render json: { 'error': { message: 'Stripe ID not created yet!' } }
      return
    end
    app_host = ENV['APP_HOST']
    begin
      session = Stripe::Checkout::Session.create(
        success_url: "https://#{app_host}/subscription/success?session_id={CHECKOUT_SESSION_ID}",
        cancel_url: "https://#{app_host}/subscription/canceled",
        payment_method_types: ['card'],
        mode: 'subscription',
        customer: stripe_id,
        line_items: [{
          adjustable_quantity: {
            enabled: true,
            minimum: 1,
            maximum: 30
          },
          quantity: 1,
          price: data['priceId'],
          description: "AWS Account"
        }],
      )
    rescue => e
      render json: { 'error': { message: e.error.message } }
      return
    end
    render json: { sessionId: session.id }
  end
def create_checkout_session data = JSON . parse ( request . body . read ) stripe_id = @current_user . subscription . stripe_id if stripe_id . nil? render json : { 'error' : { message : 'Stripe ID not created yet!' } } return end app_host = ENV [ 'APP_HOST' ] begin session = Stripe :: Checkout :: Session . create ( success_url : "https://#{app_host}/subscription/success?session_id={CHECKOUT_SESSION_ID}" , cancel_url : "https://#{app_host}/subscription/canceled" , payment_method_types : [ 'card' ] , mode : 'subscription' , customer : stripe_id , line_items : [ { adjustable_quantity : { enabled : true , minimum : 1 , maximum : 30 } , quantity : 1 , price : data [ 'priceId' ] , description : "AWS Account" } ] , ) rescue => e render json : { 'error' : { message : e . error . message } } return end render json : { sessionId : session . id } end
TODO: This has mostly been taken from stripe documentation and it's not very robust right now.
TODO : This has mostly been taken from stripe documentation and it ' s not very robust right now .
# See https://stripe.com/docs/api/checkout/sessions/create # for additional parameters to pass. # {CHECKOUT_SESSION_ID} is a string literal; do not change it! # the actual Session ID is returned in the query parameter when your customer # is redirected to the success page.