class Bambora::Rest::BatchPaymentFileUploadClient

Constants

CONTENT_DISPOSITION
CONTENT_TYPES
FILE_TYPE_HEADER

Public Instance Methods

post(args = {}) click to toggle source

@param args [String] CSV file contents @param args [Hash] Request Parameters as documented by Bambora. @param args [String]

Calls superclass method Bambora::Rest::Client#post
# File lib/bambora/rest/batch_payment_file_upload_client.rb, line 16
def post(args = {})
  init_payload(args[:file_contents], args[:options])
  parse_response_body(
    super(
      path: args[:path],
      body: @payload.body,
      headers: build_headers(api_key: args[:api_key]),
    ),
  ).to_h
end

Private Instance Methods

build_headers(api_key:) click to toggle source
# File lib/bambora/rest/batch_payment_file_upload_client.rb, line 48
def build_headers(api_key:)
  headers = Bambora::Builders::Headers.new(
    content_type: @payload.content_type,
    api_key: api_key,
    merchant_id: merchant_id,
  ).build
  headers.merge(FILE_TYPE_HEADER)
end
init_payload(file_contents, options) click to toggle source
# File lib/bambora/rest/batch_payment_file_upload_client.rb, line 29
def init_payload(file_contents, options)
  return @payload if @payload

  @payload = Bambora::Adapters::MultipartMixedRequest.new(
    multipart_args: {
      criteria: {
        content_disposition: CONTENT_DISPOSITION,
        content_type: CONTENT_TYPES[:application_json],
        content: options.to_json,
      },
      data: {
        filename: "merchant_#{sub_merchant_id}.txt",
        content_type: CONTENT_TYPES[:text_plain],
        content: file_contents,
      },
    },
  )
end