Sha256: 0b39400d2442092712b7be63edd2a3db54edc972bbf6ef4bbecd4fc373cdc6e0

Contents?: true

Size: 1.1 KB

Versions: 43

Compression:

Stored size: 1.1 KB

Contents

module Braintree
  class DocumentUploadGateway # :nodoc:
    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 # :nodoc:
      [
        :kind,
        :file
      ]
    end

    def _do_create(path, params, file) # :nodoc:
      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

43 entries across 43 versions & 1 rubygems

Version Path
braintree-4.15.0 lib/braintree/document_upload_gateway.rb
braintree-4.14.0 lib/braintree/document_upload_gateway.rb
braintree-4.13.0 lib/braintree/document_upload_gateway.rb
braintree-4.12.0 lib/braintree/document_upload_gateway.rb
braintree-4.11.0 lib/braintree/document_upload_gateway.rb
braintree-4.10.0 lib/braintree/document_upload_gateway.rb
braintree-4.9.0 lib/braintree/document_upload_gateway.rb
braintree-4.8.0 lib/braintree/document_upload_gateway.rb
braintree-4.7.0 lib/braintree/document_upload_gateway.rb
braintree-4.6.0 lib/braintree/document_upload_gateway.rb
braintree-4.5.0 lib/braintree/document_upload_gateway.rb
braintree-4.4.0 lib/braintree/document_upload_gateway.rb
braintree-4.3.0 lib/braintree/document_upload_gateway.rb
braintree-4.2.0 lib/braintree/document_upload_gateway.rb
braintree-4.1.0 lib/braintree/document_upload_gateway.rb
braintree-4.0.0 lib/braintree/document_upload_gateway.rb
braintree-3.4.0 lib/braintree/document_upload_gateway.rb
braintree-3.3.0 lib/braintree/document_upload_gateway.rb
braintree-3.2.0 lib/braintree/document_upload_gateway.rb
braintree-3.1.0 lib/braintree/document_upload_gateway.rb