This file contains hidden or 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/services/create_card.rb | |
| require 'stripe' | |
| class CreateCard | |
| def initialize(payment) | |
| @payment = payment | |
| end | |
| def create_card |
This file contains hidden or 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/services/create_stripe_customer.rb | |
| require 'stripe' | |
| class CreateStripeCustomer | |
| def initialize(payment) | |
| @payment = payment | |
| @user = payment.user | |
| #if the user has no stripe_customer_id create a new Stripe customer |
This file contains hidden or 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/services/charge_credit_card.rb | |
| require 'stripe' | |
| class ChargeCreditCard | |
| def initialize(payment) | |
| @payment = payment | |
| @user = payment.user | |
| #retrieve the card object attached to the payments stripe token | |
| @card = Stripe::Token.retrieve(@payment.stripe_token).card.id |
This file contains hidden or 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/views/payments/_form.html.erb --> | |
| <%= form_for(@payment, html: { id: "payment-form" }) do |f| %> | |
| <% if something.errors.any? %> | |
| <div id="error_explanation"> | |
| <h2><%= pluralize(something.errors.count, "error") %> prohibited this something from being saved:</h2> | |
| <ul> | |
| <% @payment.errors.full_messages.each do |message| %> | |
| <li><%= message %></li> | |
| <% end %> |
This file contains hidden or 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
| class PaymentsController < ApplicationController | |
| def new | |
| # this cards variable is accessed later in payments/_form.html.erb | |
| @payment = Payment.new | |
| @user = User.first | |
| @cards = @user.cards | |
| end | |
| def index | |
| #index action |
This file contains hidden or 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
| require 'stripe' | |
| class CreateChargeService | |
| def initialize(payment) | |
| @payment = payment | |
| @user = payment.user | |
| end | |
| private |
This file contains hidden or 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
| class AddAuthenticationTokenToUser < ActiveRecord::Migration | |
| def change | |
| add_column :users, :authentication_token, :string | |
| end | |
| end |
This file contains hidden or 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
| namespace :db do | |
| desc "Erase and fill database" | |
| task :populate => :environment do | |
| require 'populator' | |
| require 'faker' | |
| [Category, Product, VolumePrice, ProductsVolumePrice, User].each(&:delete_all) | |
| #CATEGORIES HAS MANY PRODUCS | |
| VolumePrice.populate(2) do |volume_price| | |
| volume_price.price = Faker::Commerce.price |
NewerOlder