lib/braintree/customer_gateway.rb in braintree-2.83.0 vs lib/braintree/customer_gateway.rb in braintree-2.84.0

- old
+ new

@@ -1,7 +1,9 @@ module Braintree class CustomerGateway # :nodoc: + include BaseModule + def initialize(gateway) @gateway = gateway @config = gateway.config @config.assert_has_access_token_or_keys end @@ -14,10 +16,14 @@ def create(attributes = {}) Util.verify_keys(CustomerGateway._create_signature, attributes) _do_create "/customers", :customer => attributes end + def create!(*args) + return_object_or_raise(:customer) { create(*args) } + end + # Deprecated def create_customer_url "#{@config.base_merchant_url}/customers/all/create_via_transparent_redirect_request" end @@ -30,14 +36,16 @@ def delete(customer_id) @config.http.delete("#{@config.base_merchant_path}/customers/#{customer_id}") SuccessfulResult.new end - def find(customer_id) + def find(customer_id, options = {}) raise ArgumentError, "customer_id contains invalid characters" unless customer_id.to_s =~ /\A[\w-]+\z/ raise ArgumentError, "customer_id cannot be blank" if customer_id.nil?|| customer_id.to_s.strip == "" - response = @config.http.get("#{@config.base_merchant_path}/customers/#{customer_id}") + + query_params = options[:association_filter_id].nil? ? "" : "?association_filter_id=#{options[:association_filter_id]}" + response = @config.http.get("#{@config.base_merchant_path}/customers/#{customer_id}#{query_params}") Customer._new(@gateway, response[:customer]) rescue NotFoundError raise NotFoundError, "customer with id #{customer_id.inspect} not found" end @@ -55,9 +63,13 @@ end def update(customer_id, attributes) Util.verify_keys(CustomerGateway._update_signature, attributes) _do_update(:put, "/customers/#{customer_id}", :customer => attributes) + end + + def update!(*args) + return_object_or_raise(:customer) { update(*args) } end # Deprecated def update_customer_url warn "[DEPRECATED] Customer.update_customer_url is deprecated. Please use TransparentRedirect.url"