Sha256: ef23c4af180eb16d3d8a47b93041a1e52b6a32f724321900318de615874cb0df

Contents?: true

Size: 1.5 KB

Versions: 20

Compression:

Stored size: 1.5 KB

Contents

module Braintree
  class PayPalAccountGateway
    def initialize(gateway)
      @gateway = gateway
      @config = gateway.config
      @config.assert_has_access_token_or_keys
    end

    def find(token)
      raise ArgumentError if token.nil? || token.to_s.strip == ""
      response = @config.http.get("#{@config.base_merchant_path}/payment_methods/paypal_account/#{token}")
      PayPalAccount._new(@gateway, response[:paypal_account])
    rescue NotFoundError
      raise NotFoundError, "payment method with token #{token.inspect} not found"
    end

    def update(token, attributes)
      Util.verify_keys(PayPalAccountGateway._update_signature, attributes)
      _do_update(:put, "/payment_methods/paypal_account/#{token}", :paypal_account => attributes)
    end

    def delete(token)
      @config.http.delete("#{@config.base_merchant_path}/payment_methods/paypal_account/#{token}")
    end

    def _do_update(http_verb, path, params) # :nodoc:
      response = @config.http.send(http_verb, "#{@config.base_merchant_path}#{path}", params)
      if response[:paypal_account]
        SuccessfulResult.new(:paypal_account => PayPalAccount._new(@gateway, response[:paypal_account]))
      elsif response[:api_error_response]
        ErrorResult.new(@gateway, response[:api_error_response])
      else
        raise UnexpectedError, "expected :paypal_account or :api_error_response"
      end
    end

    def self._update_signature # :nodoc:
      options = [:make_default]
      [:token, {:options => options}]
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
braintree-2.66.0 lib/braintree/paypal_account_gateway.rb
braintree-2.65.0 lib/braintree/paypal_account_gateway.rb
braintree-2.64.0 lib/braintree/paypal_account_gateway.rb
braintree-2.63.0 lib/braintree/paypal_account_gateway.rb
braintree-2.62.0 lib/braintree/paypal_account_gateway.rb
braintree-2.61.1 lib/braintree/paypal_account_gateway.rb
braintree-2.61.0 lib/braintree/paypal_account_gateway.rb
braintree-2.60.0 lib/braintree/paypal_account_gateway.rb
braintree-2.59.0 lib/braintree/paypal_account_gateway.rb
braintree-2.58.0 lib/braintree/paypal_account_gateway.rb
braintree-2.57.0 lib/braintree/paypal_account_gateway.rb
braintree-2.56.0 lib/braintree/paypal_account_gateway.rb
braintree-2.55.0 lib/braintree/paypal_account_gateway.rb
braintree-2.54.0 lib/braintree/paypal_account_gateway.rb
braintree-2.50.0 lib/braintree/paypal_account_gateway.rb
braintree-2.49.0 lib/braintree/paypal_account_gateway.rb
braintree-2.48.1 lib/braintree/paypal_account_gateway.rb
braintree-2.48.0 lib/braintree/paypal_account_gateway.rb
braintree-2.47.0 lib/braintree/paypal_account_gateway.rb
braintree-2.46.0 lib/braintree/paypal_account_gateway.rb