Sha256: f9430f67a274e4e88f82cb05d5fc6216a8c2b5c16719525c16c7cab6f0edee96

Contents?: true

Size: 1.54 KB

Versions: 3

Compression:

Stored size: 1.54 KB

Contents

module Laundry
  module PaymentsGateway

    class AccountDriver < MerchantAuthenticatableDriver

      attr_accessor :client
      def initialize(client, merchant)
        super merchant
        self.client = client
      end

      def client_driver
        @client_driver ||= ClientDriver.new(self.merchant)
      end

      def find(payment_method_id)
        r = client_driver.get_payment_method({'ClientID' => self.client.id, 'PaymentMethodID' => payment_method_id}) do
          http.headers["SOAPAction"] = 'https://ws.paymentsgateway.net/v1/IClientService/getPaymentMethod'
        end
        Account.from_response(r, self.merchant)
      end

      # Returns the payment method id
      def create!(options = {})
        raise ArgumentError, "Tried to create an account on an invalid client." if self.client.nil? || self.client.blank?
        options = {merchant_id: self.merchant.id, client_id: self.client.id, payment_method_id: 0}.merge(options)
        options = AccountDriver.uglify_hash(options)
        r = client_driver.create_payment_method({'payment' => options}) do
          http.headers["SOAPAction"] = 'https://ws.paymentsgateway.net/v1/IClientService/createPaymentMethod'
        end
        r[:create_payment_method_response][:create_payment_method_result]
      end

      def self.prettifiable_fields
        ['MerchantID',
         'ClientID',
         'PaymentMethodID',
         'AcctHolderName',
         'EcAccountNumber',
         'EcAccountTRN',
         'EcAccountType',
         'Note',
         'IsDefault']
      end

    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
laundry-0.0.8 lib/laundry/payments_gateway/drivers/account_driver.rb
laundry-0.0.7 lib/laundry/payments_gateway/drivers/account_driver.rb
laundry-0.0.6 lib/laundry/payments_gateway/drivers/account_driver.rb