Created
May 28, 2020 14:46
-
-
Save fedeagripa/29f02be2c8ab39560d06de47e13c7681 to your computer and use it in GitHub Desktop.
credit_card_controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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