Sha256: 25057519d8c660c0523fadeb3df142527e80ca9d44123d4c051b3da120b7b41f

Contents?: true

Size: 1.59 KB

Versions: 23

Compression:

Stored size: 1.59 KB

Contents

module Spree
  class Gateway::PinGateway < Gateway
    preference :api_key, :string
    preference :currency, :string, :default => 'AUD'

    def provider_class
      ActiveMerchant::Billing::PinGateway
    end
    
    def purchase(money, creditcard, options = {})
      super(money, creditcard.try(:gateway_customer_profile_id) || creditcard.try(:gateway_payment_profile_id) || creditcard, options)
    end
    
    def create_profile(payment)
      if payment.source.gateway_customer_profile_id.nil?
        response = provider.store(payment.source, options_for_payment(payment))
        
        if response.success?
          payment.source.update_attributes!(:gateway_customer_profile_id => response.authorization)

          cc = response.params['response']['card']
          payment.source.update_attributes!(:gateway_payment_profile_id => cc['token']) if cc
        else
          payment.send(:gateway_error, response.message)
        end
      end
    end

    # Pin does not appear to support authorizing transactions yet
    def auto_capture?
      true
    end
    
    def payment_profiles_supported?
      true
    end
    
    private
    
    def options_for_payment(p)
      o = Hash.new
      o[:email] = p.order.email

      if p.order.bill_address
        bill_addr = p.order.bill_address

        o[:billing_address] = {
          address1: bill_addr.address1,
          city: bill_addr.city,
          state: bill_addr.state ? bill_addr.state.name : bill_addr.state_name,
          country: bill_addr.country.iso3,
          zip: bill_addr.zipcode
        }
      end

      return o
    end
    
  end
end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
spree_gateway-3.3.7 app/models/spree/gateway/pin_gateway.rb
spree_gateway-3.6.4 app/models/spree/gateway/pin_gateway.rb
spree_gateway-3.3.5 app/models/spree/gateway/pin_gateway.rb
spree_gateway-3.6.1 app/models/spree/gateway/pin_gateway.rb
spree_gateway-3.6.0 app/models/spree/gateway/pin_gateway.rb
spree_gateway-3.4.1 app/models/spree/gateway/pin_gateway.rb
spree_gateway-3.4.0 app/models/spree/gateway/pin_gateway.rb
spree_gateway-3.3.3 app/models/spree/gateway/pin_gateway.rb
solidus_gateway-1.3.0 app/models/spree/gateway/pin_gateway.rb
spree_gateway-3.3.2 app/models/spree/gateway/pin_gateway.rb
solidus_gateway-1.2.0 app/models/spree/gateway/pin_gateway.rb
spree_gateway-3.3.0 app/models/spree/gateway/pin_gateway.rb
spree_gateway-3.3.0.rc2 app/models/spree/gateway/pin_gateway.rb
spree_gateway-3.3.0.rc1 app/models/spree/gateway/pin_gateway.rb
spree_gateway-3.2.0 app/models/spree/gateway/pin_gateway.rb
spree_gateway-3.2.0.beta app/models/spree/gateway/pin_gateway.rb
solidus_gateway-1.1.1 app/models/spree/gateway/pin_gateway.rb
solidus_gateway-1.1.0 app/models/spree/gateway/pin_gateway.rb
spree_gateway-3.1.0 app/models/spree/gateway/pin_gateway.rb
spree_gateway-3.0.0 app/models/spree/gateway/pin_gateway.rb