Class: Braintree::AddressGateway

### Home Classes Methods

### In Files

- lib/braintree/address_gateway.rb

### Parent

Object

### Methods

- ::new
- #create
- #delete
- #find
- #update

### Class/Module Index

Quicksearch

- Braintree
- Braintree::AddOn
- Braintree::AddOnGateway
- Braintree::Address
- Braintree::AddressGateway
- Braintree::AdvancedSearch
- Braintree::AdvancedSearch::MultipleValueOrTextNode
- Braintree::AuthenticationError
- Braintree::AuthorizationError
- Braintree::BraintreeError
- Braintree::Configuration
- Braintree::ConfigurationError
- Braintree::CreditCard
- Braintree::CreditCard::CardType
- Braintree::CreditCard::CustomerLocation
- Braintree::CreditCardVerification
- Braintree::CreditCardVerification::Status
- Braintree::Customer
- Braintree::Discount
- Braintree::DiscountGateway
- Braintree::DownForMaintenanceError
- Braintree::ErrorCodes
- Braintree::ErrorCodes::Address
- Braintree::ErrorCodes::CreditCard
- Braintree::ErrorCodes::CreditCard::Options
- Braintree::ErrorCodes::Customer
- Braintree::ErrorCodes::Descriptor
- Braintree::ErrorCodes::SettlementBatchSummary
- Braintree::ErrorCodes::Subscription
- Braintree::ErrorCodes::Subscription::Modification
- Braintree::ErrorCodes::Transaction
- Braintree::ErrorCodes::Transaction::Options
- Braintree::ErrorResult
- Braintree::Errors
- Braintree::ForgedQueryString
- Braintree::NotFoundError
- Braintree::Plan
- Braintree::SSLCertificateError
- Braintree::ServerError
- Braintree::SettlementBatchSummary
- Braintree::SettlementBatchSummaryGateway
- Braintree::Subscription
- Braintree::Subscription::Status
- Braintree::Subscription::TrialDurationUnit
- Braintree::SuccessfulResult
- Braintree::Test
- Braintree::Test::CreditCardNumbers
- Braintree::Test::CreditCardNumbers::FailsSandboxVerification
- Braintree::Test::TransactionAmounts
- Braintree::Transaction
- Braintree::Transaction::CreatedUsing
- Braintree::Transaction::GatewayRejectionReason
- Braintree::Transaction::Source
- Braintree::Transaction::Status
- Braintree::TransparentRedirect
- Braintree::TransparentRedirectGateway
- Braintree::UnexpectedError
- Braintree::UpgradeRequiredError
- Braintree::ValidationError
- Braintree::ValidationErrorCollection
- Braintree::ValidationsFailed
- Braintree::Version

No matching classes.

# Braintree::AddressGateway

### Public Class Methods

new(gateway) click to toggle source

    # File lib/braintree/address_gateway.rb, line 3
    def initialize(gateway)
      @gateway = gateway
      @config = gateway.config
    end

### Public Instance Methods

create(attributes) click to toggle source

    # File lib/braintree/address_gateway.rb, line 8
    def create(attributes)
      Util.verify_keys(AddressGateway._create_signature, attributes)
      unless attributes[:customer_id]
        raise ArgumentError, "Expected hash to contain a :customer_id"
      end
      unless attributes[:customer_id] =~ /\A[0-9A-Za-z_-]+\z/
        raise ArgumentError, ":customer_id contains invalid characters"
      end
      response = @config.http.post "/customers/#{attributes.delete(:customer_id)}/addresses", :address => attributes
      if response[:address]
        SuccessfulResult.new(:address => Address._new(@gateway, response[:address]))
      elsif response[:api_error_response]
        ErrorResult.new(@gateway, response[:api_error_response])
      else
        raise UnexpectedError, "expected :address or :api_error_response"
      end
    end

delete(customer_or_customer_id, address_id) click to toggle source

    # File lib/braintree/address_gateway.rb, line 26
    def delete(customer_or_customer_id, address_id)
      customer_id = _determine_customer_id(customer_or_customer_id)
      @config.http.delete("/customers/#{customer_id}/addresses/#{address_id}")
      SuccessfulResult.new
    end

find(customer_or_customer_id, address_id) click to toggle source

    # File lib/braintree/address_gateway.rb, line 32
    def find(customer_or_customer_id, address_id)
      customer_id = _determine_customer_id(customer_or_customer_id)
      raise ArgumentError if address_id.nil? || address_id.strip.to_s == ""
      response = @config.http.get("/customers/#{customer_id}/addresses/#{address_id}")
      Address._new(@gateway, response[:address])
    rescue NotFoundError
      raise NotFoundError, "address for customer #{customer_id.inspect} with id #{address_id.inspect} not found"
    end

update(customer_or_customer_id, address_id, attributes) click to toggle source

    # File lib/braintree/address_gateway.rb, line 41
    def update(customer_or_customer_id, address_id, attributes)
      Util.verify_keys(AddressGateway._update_signature, attributes)
      customer_id = _determine_customer_id(customer_or_customer_id)
      response = @config.http.put "/customers/#{customer_id}/addresses/#{address_id}", :address => attributes
      if response[:address]
        SuccessfulResult.new(:address => Address._new(@gateway, response[:address]))
      elsif response[:api_error_response]
        ErrorResult.new(@gateway, response[:api_error_response])
      else
        raise UnexpectedError, "expected :address or :api_error_response"
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.