Skip to content

Instantly share code, notes, and snippets.

@fedeagripa
Created May 28, 2020 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fedeagripa/29f02be2c8ab39560d06de47e13c7681 to your computer and use it in GitHub Desktop.
Save fedeagripa/29f02be2c8ab39560d06de47e13c7681 to your computer and use it in GitHub Desktop.
credit_card_controller
# app/controllers/api/v1/credit_cards_controller.rb
module Api
module V1
class CreditCardsController < Api::V1::ApiController
helper_method :shop
def index
service = StripeService.new(shop)
@card = service.credit_card_info
@customer = service.customer
end
def create
StripeService.new(shop).add_card(token_id, email, customer_name) if token_id
head :no_content
end
def update
begin
StripeService.new(shop).update_credit_card(token_id)
rescue StripeService::StripeException => ex
return render_not_found(ex.message)
end
head :no_content
end
private
def shop
@shop ||= current_shop
end
def token_json
params[:token]
end
def token_id
token_json['id']
end
def email
token_json['email']
end
def customer_name
token_json['name']
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment