Sha256: aa8cc2ec35feff9852bcb55413d746f4635667bc5192a7f03c6ad40db160f789

Contents?: true

Size: 1.07 KB

Versions: 10

Compression:

Stored size: 1.07 KB

Contents

module Braintree
  class DocumentUploadGateway
    include BaseModule

    def initialize(gateway)
      @gateway = gateway
      @config = gateway.config
      @config.assert_has_access_token_or_keys
    end

    def create(attributes)
      Util.verify_keys(DocumentUploadGateway._create_signature, attributes)
      _do_create "/document_uploads", {"document_upload[kind]" => attributes[:kind]}, attributes[:file]
    end

    def create!(*args)
      return_object_or_raise(:document_upload) { create(*args) }
    end

    def self._create_signature
      [
        :kind,
        :file
      ]
    end

    def _do_create(path, params, file)
      response = @config.http.post("#{@config.base_merchant_path}#{path}", params, file)
      if response[:document_upload]
        SuccessfulResult.new(:document_upload => DocumentUpload._new(response[:document_upload]))
      elsif response[:api_error_response]
        ErrorResult.new(@gateway, response[:api_error_response])
      else
        raise UnexpectedError, "expected :document_upload or :api_error_response"
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
braintree-4.25.0 lib/braintree/document_upload_gateway.rb
braintree-4.24.0 lib/braintree/document_upload_gateway.rb
braintree-4.23.0 lib/braintree/document_upload_gateway.rb
braintree-4.22.0 lib/braintree/document_upload_gateway.rb
braintree-4.21.0 lib/braintree/document_upload_gateway.rb
braintree-4.20.0 lib/braintree/document_upload_gateway.rb
braintree-4.19.0 lib/braintree/document_upload_gateway.rb
braintree-4.18.0 lib/braintree/document_upload_gateway.rb
braintree-4.17.0 lib/braintree/document_upload_gateway.rb
braintree-4.16.0 lib/braintree/document_upload_gateway.rb