Sha256: d3982fb932c69efac7ccf18b6f84f9932e8be4b98a4d6e74e7e848f7bc4dba2c

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

module Securetrading
  class Refund < Connection
    def initialize(amount, parent_transaction, options = {})
      @amount = amount
      @parent_transaction = parent_transaction
      @account_type = options[:account_type].presence || 'ECOM'
      @options = options
    end

    def perform(options = {})
      perform_with(:post, to_xml, options)
    end

    private

    def ox_xml
      prepare_doc do
        req = doc.requestblock.request
        req << merchant << operation << billing
      end
    end

    def request_type
      'REFUND'.freeze
    end

    def operation
      XmlDoc.elements(
        operation: {
          sitereference: Securetrading.config.site_reference,
          accounttypedescription: @account_type,
          parenttransactionreference: @parent_transaction
        }
      ).first
    end

    def billing
      XmlDoc.elements(billing: { amount: @amount }).first
    end

    def merchant
      return '' unless @options[:merchant].present?
      XmlDoc.elements(merchant: @options[:merchant]).first
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
securetrading-0.2.0 lib/securetrading/refund.rb