Sha256: c9986439b103fd30420614b4694b7027466d7ce778542d929fbfe0565431aecd

Contents?: true

Size: 1.23 KB

Versions: 37

Compression:

Stored size: 1.23 KB

Contents

require_dependency "ishapi/application_controller"
module Ishapi
  class PaymentsController < ApplicationController

    def create
      authorize! :open_permission, ::Ishapi
      begin
        profile = IshModels::UserProfile.find_by( :email => params[:email] )
        invoice = Ish::Invoice.find_by( :number => params[:number] )
        payment = Ish::Payment.new :invoice => invoice, :profile => profile, :amount => params[:amount]
        amount_cents  = ( params[:amount].to_f * 100 ).to_i

        ::Stripe.api_key = STRIPE_SK
        acct = Stripe::Account.create(
          :country => 'US',
          :type => 'custom'
        )
        charge = ::Stripe::Charge.create(
          :amount => amount_cents,
          :currency => 'usd',
          :source => params[:token][:id],
          :destination => { 
            :account => acct,
          }
        )
        puts! charge, 'charge'
        # byebug

        payment.charge = JSON.parse( charge.to_json )
        if payment.save
          render :json => { :status => :ok }
        else
          render :status => 404, :json => {}
        end
      rescue Mongoid::Errors::DocumentNotFound => e
        puts! e, 'e'
        render :status => 404, :json => {}
      end
    end

  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
ishapi-0.1.8.75 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.74 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.73 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.72 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.71 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.70 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.69 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.68 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.67 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.66 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.65 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.64 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.63 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.62 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.61 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.60 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.59 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.58 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.57 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.56 app/controllers/ishapi/payments_controller.rb