Skip to content

Instantly share code, notes, and snippets.

@silasjmatson
Last active August 29, 2015 14:06
Show Gist options
  • Save silasjmatson/75234865754e3e1c0ff3 to your computer and use it in GitHub Desktop.
Save silasjmatson/75234865754e3e1c0ff3 to your computer and use it in GitHub Desktop.
Stripe Customer & Card
class API::Registrar
# Is this possible?
attr_reader :stripe_customer, :postgres_user, :stripe_card
def initialize(user_params, card_params)
@postgres_user = initialize_postgres_user(user_params)
@stripe_customer = initialize_stripe_customer(user_params)
@stripe_card = initialize_stripe_card(card_params)
end
def register
save_postgres && save_stripe_customer && save_stripe_card
@success = errors.empty?
end
private
def initialize_stripe_customer(user_params)
customer = Customer.new
customer["email"] = user_params[:email]
customer["metadata"] = {
first_name: user_params[:first_name],
last_name: user_params[:last_name],
phone_number: user_params[:phone_number]
}
customer
end
def initialize_stripe_card(card_params)
card = Stripe::Card.new
card["number"] = card_params[:card_number]
# etc.
card
end
def save_stripe_card
stripe_card["customer"] = stripe_customer.id
# Save Stripe::Card
end
# Rest of class omitted.
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment