Sha256: 35fc92ac795687d316445620f57117b0e7597638031cdf43528237c757d6c3a6

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

require File.dirname(__FILE__) + '/beanstream/beanstream_core'

module MerbMerchant #:nodoc:
  module Billing #:nodoc:
    class BeanstreamInteracResponse < Response
      def redirect
        params['pageContents']
      end
    end
    
    class BeanstreamInteracGateway < Gateway
      include BeanstreamCore
      
      # Confirm a transaction posted back from the bank to Beanstream.
      # Confirming a transaction does not require any credentials,
      # and in an application with many merchants sharing a funded
      # URL the application may not yet know which merchant the 
      # post back is for until the response of the confirmation is
      # received, which contains the order number.
      def self.confirm(transaction)
        gateway = new(:login => '')
        gateway.confirm(transaction)
      end
      
      def purchase(money, options = {})
        post = {}
        add_amount(post, money)
        add_invoice(post, options)
        add_address(post, options)
        add_interac_details(post, options)
        add_transaction_type(post, :purchase)
        commit(post)
      end
      
      # Confirm a transaction posted back from the bank to Beanstream.
      def confirm(transaction)
        post(transaction)
      end
      
      private
      
      def add_interac_details(post, options)
        address = options[:billing_address] || options[:address] || {}
        post[:trnCardOwner] = address[:name]
        post[:paymentMethod] = 'IO'
      end
      
      def build_response(*args)
        BeanstreamInteracResponse.new(*args)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
merb_merchant-1.4.1 lib/merb_merchant/billing/gateways/beanstream_interac.rb