Sha256: 836dafafac22a2a37c3801f68c6534ab2f862f8a6474e7474794ea57633342b2
Contents?: true
Size: 1.93 KB
Versions: 1
Compression:
Stored size: 1.93 KB
Contents
# frozen_string_literal: true module SlackRubyBotServer module Stripe module Api module Endpoints class SubscriptionsEndpoint < Grape::API format :json namespace :subscriptions do desc 'Create or update a subscription.' params do requires :stripe_token, type: String optional :stripe_token_type, type: String optional :stripe_email, type: String requires :team_id, type: String end post do begin team = Team.where(team_id: params[:team_id]).first || error!('Team Not Found', 404) if team.subscribed? SlackRubyBotServer::Api::Middleware.logger.info "Updating a subscription for team #{team}." stripe_customer = team.update_subscription!(params) SlackRubyBotServer::Api::Middleware.logger.info "Updated subscription for team #{team}, stripe_customer_id=#{stripe_customer['id']}." else SlackRubyBotServer::Api::Middleware.logger.info "Creating a subscription for team #{team}." stripe_customer = team.subscribe!(params) SlackRubyBotServer::Api::Middleware.logger.info "Subscription for team #{team} created, stripe_customer_id=#{stripe_customer['id']}." end present team, with: SlackRubyBotServer::Api::Presenters::TeamPresenter rescue Errors::AlreadySubscribedError error! 'Already Subscribed', 400 rescue Errors::StripeCustomerExistsError error! 'Customer Already Registered', 400 rescue Errors::NotSubscribedError error! 'Not a Subscriber', 400 rescue Errors::MissingStripeCustomerError error! 'Missing Stripe Customer', 400 end end end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
slack-ruby-bot-server-stripe-0.2.0 | lib/slack-ruby-bot-server-stripe/api/endpoints/subscriptions_endpoint.rb |