Sha256: 282101e4a2ee574ba4e428be2b5a4fad92102bb5663fb37cea9044bb56914de5

Contents?: true

Size: 994 Bytes

Versions: 1

Compression:

Stored size: 994 Bytes

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
      Operation.new(
        sitereference: Securetrading.config.site_reference,
        accounttypedescription: @account_type,
        parenttransactionreference: @parent_transaction
      ).ox_xml
    end

    def billing
      Billing.new(amount: @amount).ox_xml
    end

    def merchant
      return '' unless @options[:merchant].present?
      Merchant.new(@options[:merchant]).ox_xml
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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