Class: Braintree::ClientTokenGateway
- Inherits:
-
Object
- Object
- Braintree::ClientTokenGateway
- Includes:
- BaseModule
- Defined in:
- lib/braintree/client_token_gateway.rb
Class Method Summary collapse
-
._generate_signature ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #_validate_options(options) ⇒ Object
- #generate(options = {}) ⇒ Object
-
#initialize(gateway) ⇒ ClientTokenGateway
constructor
A new instance of ClientTokenGateway.
Methods included from BaseModule
Methods included from BaseModule::Methods
#copy_instance_variables_from_object, #return_object_or_raise, #set_instance_variables_from_hash, #singleton_class
Constructor Details
#initialize(gateway) ⇒ ClientTokenGateway
Returns a new instance of ClientTokenGateway.
5 6 7 8 9 |
# File 'lib/braintree/client_token_gateway.rb', line 5 def initialize(gateway) @gateway = gateway @config = gateway.config @config.assert_has_access_token_or_keys end |
Class Method Details
._generate_signature ⇒ Object
:nodoc:
28 29 30 31 32 33 34 |
# File 'lib/braintree/client_token_gateway.rb', line 28 def self._generate_signature # :nodoc: [ :address_id, :customer_id, :proxy_merchant_id, :merchant_account_id, :version, {:options => [:make_default, :verify_card, :fail_on_duplicate_payment_method]} ] end |
Instance Method Details
#_validate_options(options) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/braintree/client_token_gateway.rb', line 36 def () [:make_default, :fail_on_duplicate_payment_method, :verify_card].each do |credit_card_option| if [credit_card_option] raise ArgumentError.new("cannot specify #{credit_card_option} without a customer_id") unless [:customer_id] end end end |
#generate(options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/braintree/client_token_gateway.rb', line 11 def generate(={}) () [:version] ||= ClientToken::DEFAULT_VERSION Util.verify_keys(ClientTokenGateway._generate_signature, ) params = {:client_token => } result = @config.http.post("#{@config.base_merchant_path}/client_token", params) if result[:client_token] result[:client_token][:value] else raise ArgumentError, result[:api_error_response][:message] end end |