Class: PayPal::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/pay_pal/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token:, sandbox: true, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
10
11
12
# File 'lib/pay_pal/client.rb', line 5

def initialize(access_token:, sandbox: true, adapter: Faraday.default_adapter, stubs: nil)
  @access_token = access_token
  @sandbox = sandbox
  @adapter = adapter

  # Test stubs for requests
  @stubs = stubs
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



3
4
5
# File 'lib/pay_pal/client.rb', line 3

def access_token
  @access_token
end

#adapterObject (readonly)

Returns the value of attribute adapter.



3
4
5
# File 'lib/pay_pal/client.rb', line 3

def adapter
  @adapter
end

#sandboxObject (readonly)

Returns the value of attribute sandbox.



3
4
5
# File 'lib/pay_pal/client.rb', line 3

def sandbox
  @sandbox
end

Instance Method Details

#connectionObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pay_pal/client.rb', line 22

def connection
  url = @sandbox ? "https://api-m.sandbox.paypal.com" : "https://api-m.paypal.com"

  @connection ||= Faraday.new(url) do |conn|
    conn.request :authorization, :Bearer, access_token
    conn.request :json

    conn.response :json

    conn.adapter adapter, @stubs
  end
end

#ordersObject



18
19
20
# File 'lib/pay_pal/client.rb', line 18

def orders
  OrdersResource.new(self)
end

#productsObject



14
15
16
# File 'lib/pay_pal/client.rb', line 14

def products
  ProductsResource.new(self)
end