Sha256: 69c48b587c42a7d9b1f1c79d28790e368415065a08746acfa2fdc6d86076b25e

Contents?: true

Size: 1.29 KB

Versions: 33

Compression:

Stored size: 1.29 KB

Contents

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

    def generate(options={})
      _validate_options(options)

      options[:version] ||= ClientToken::DEFAULT_VERSION

      Util.verify_keys(ClientTokenGateway._generate_signature, options)

      params = {:client_token => options}
      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

    def self._generate_signature # :nodoc:
      [
        :address_id, :customer_id, :proxy_merchant_id, :merchant_account_id,
        :version, :sepa_mandate_acceptance_location, :sepa_mandate_type,
        {:options => [:make_default, :verify_card, :fail_on_duplicate_payment_method]}
      ]
    end

    def _validate_options(options)
      [:make_default, :fail_on_duplicate_payment_method, :verify_card].each do |credit_card_option|
        if options[credit_card_option]
          raise ArgumentError.new("cannot specify #{credit_card_option} without a customer_id") unless options[:customer_id]
        end
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
braintree-2.67.0 lib/braintree/client_token_gateway.rb
braintree-2.66.0 lib/braintree/client_token_gateway.rb
braintree-2.65.0 lib/braintree/client_token_gateway.rb
braintree-2.64.0 lib/braintree/client_token_gateway.rb
braintree-2.63.0 lib/braintree/client_token_gateway.rb
braintree-2.62.0 lib/braintree/client_token_gateway.rb
braintree-2.61.1 lib/braintree/client_token_gateway.rb
braintree-2.61.0 lib/braintree/client_token_gateway.rb
braintree-2.60.0 lib/braintree/client_token_gateway.rb
braintree-2.59.0 lib/braintree/client_token_gateway.rb
braintree-2.58.0 lib/braintree/client_token_gateway.rb
braintree-2.57.0 lib/braintree/client_token_gateway.rb
braintree-2.56.0 lib/braintree/client_token_gateway.rb