Class: Braintree::PayPalAccountGateway

Inherits:
Object
  • Object
show all
Defined in:
lib/braintree/paypal_account_gateway.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gateway) ⇒ PayPalAccountGateway

Returns a new instance of PayPalAccountGateway.



3
4
5
6
7
# File 'lib/braintree/paypal_account_gateway.rb', line 3

def initialize(gateway)
  @gateway = gateway
  @config = gateway.config
  @config.assert_has_access_token_or_keys
end

Class Method Details

._create_nested_signatureObject



61
62
63
64
65
66
# File 'lib/braintree/paypal_account_gateway.rb', line 61

def self._create_nested_signature
  [
    :email, :token, :billing_agreement_id,
    {:options => [:make_default]}
  ]
end

._create_signatureObject



53
54
55
56
57
58
59
# File 'lib/braintree/paypal_account_gateway.rb', line 53

def self._create_signature
  options = [:fail_on_duplicate_payment_method, :make_default]
  [
    :email, :token, :billing_agreement_id, :customer_id,
    {:options => options},
  ]
end

._update_signatureObject



68
69
70
71
# File 'lib/braintree/paypal_account_gateway.rb', line 68

def self._update_signature
  options = [:fail_on_duplicate_payment_method, :make_default]
  [:email, :token, :billing_agreement_id, {:options => options}]
end

Instance Method Details

#_do_create(path, params) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/braintree/paypal_account_gateway.rb', line 31

def _do_create(path, params)
  response = @config.http.post("#{@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

#_do_update(http_verb, path, params) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/braintree/paypal_account_gateway.rb', line 42

def _do_update(http_verb, path, params)
  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

#create(attributes) ⇒ Object



17
18
19
20
# File 'lib/braintree/paypal_account_gateway.rb', line 17

def create(attributes)
  Util.verify_keys(PayPalAccountGateway._create_signature, attributes)
  _do_create("/payment_methods", :paypal_account => attributes)
end

#delete(token) ⇒ Object



27
28
29
# File 'lib/braintree/paypal_account_gateway.rb', line 27

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

#find(token) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/braintree/paypal_account_gateway.rb', line 9

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

#update(token, attributes) ⇒ Object



22
23
24
25
# File 'lib/braintree/paypal_account_gateway.rb', line 22

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