Sha256: 4358330c26bbe64415c2b11ff2a3f2769a9798c94be29081303eafa5f984e03b

Contents?: true

Size: 926 Bytes

Versions: 1

Compression:

Stored size: 926 Bytes

Contents

module Jackpot
  class Payment < ActiveRecord::Base
    before_create :perform_payment

    attr_accessor :credit_card
    attr_accessor :credit_card_token

    belongs_to :subscription
    belongs_to :customer

    cattr_accessor :gateway

    def perform_payment
      credit_card_token = customer.credit_card_token
      if credit_card_token
        self.amount = self.subscription.price
        response = Jackpot::Payment.gateway.authorize       self.amount, credit_card_token
        if response.success?
          billing_response = Jackpot::Payment.gateway.capture(self.amount, 
                                                               response.authorization) 

          self.payment_transaction_token = billing_response.params['transactionid']
        else
          raise Jackpot::Errors::UnauthorizedPayment.new
        end
      end 
    end 

    def customer_email
      customer.email
    end 
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jackpot-0.0.3 app/models/jackpot/payment.rb