Sha256: e0efaf514474b8a67ee6312c87c929614149e1aab842860b42eb4dc59f77c1d1

Contents?: true

Size: 1.17 KB

Versions: 48

Compression:

Stored size: 1.17 KB

Contents

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

    def create
      authorize! :open_permission, ::Ishapi
      begin
        invoice = Ish::Invoice.where( :email => params[:email], :number => params[:number] ).first
        payment = Ish::Payment.new :invoice => invoice, :email => params[:email], :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'

        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

48 entries across 48 versions & 1 rubygems

Version Path
ishapi-0.1.8.133 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.132 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.131 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.130 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.129 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.128 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.127 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.126 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.125 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.124 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.123 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.122 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.121 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.120 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.119 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.118 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.117 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.116 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.114 app/controllers/ishapi/payments_controller.rb
ishapi-0.1.8.113 app/controllers/ishapi/payments_controller.rb