Class: Yookassa::Client

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

Overview

API client that holds configuration and provides access to resource endpoints.

You can use the global client via default_client or create an isolated instance for multi-shop setups.

Examples:

Standalone client

client = Yookassa::Client.new(shop_id: "123", api_key: "key_...")
payment = client.payments.create(amount: { value: "100.00", currency: "RUB" })

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shop_id: nil, api_key: nil, auth_token: nil, **options) ⇒ Client

Creates a new API client.

Parameters:

  • shop_id (String, nil) (defaults to: nil)

    YooKassa shop identifier

  • api_key (String, nil) (defaults to: nil)

    secret API key

  • auth_token (String, nil) (defaults to: nil)

    OAuth token (alternative to shop_id/api_key)

  • options (Hash)

    additional options (:timeout, :max_retries, :retry_delay, :logger)



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

def initialize(shop_id: nil, api_key: nil, auth_token: nil, **options)
  @config = Configuration.new
  @config.shop_id = shop_id
  @config.api_key = api_key
  @config.auth_token = auth_token
  @config.timeout = options[:timeout] if options.key?(:timeout)
  @config.max_retries = options[:max_retries] if options.key?(:max_retries)
  @config.retry_delay = options[:retry_delay] if options.key?(:retry_delay)
  @config.logger = options[:logger] if options.key?(:logger)
end

Instance Attribute Details

#configConfiguration (readonly)

Returns the client's configuration.

Returns:



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

def config
  @config
end

Instance Method Details

#dealsResources::Deal

Returns deal resource endpoint.

Returns:



54
55
56
# File 'lib/yookassa/client.rb', line 54

def deals
  @deals ||= Resources::Deal.new(self)
end

#invoicesResources::Invoice

Returns invoice resource endpoint.

Returns:



64
65
66
# File 'lib/yookassa/client.rb', line 64

def invoices
  @invoices ||= Resources::Invoice.new(self)
end

#paymentsResources::Payment

Returns payment resource endpoint.

Returns:



34
35
36
# File 'lib/yookassa/client.rb', line 34

def payments
  @payments ||= Resources::Payment.new(self)
end

#payoutsResources::Payout

Returns payout resource endpoint.

Returns:



49
50
51
# File 'lib/yookassa/client.rb', line 49

def payouts
  @payouts ||= Resources::Payout.new(self)
end

#receiptsResources::Receipt

Returns receipt resource endpoint.

Returns:



44
45
46
# File 'lib/yookassa/client.rb', line 44

def receipts
  @receipts ||= Resources::Receipt.new(self)
end

#refundsResources::Refund

Returns refund resource endpoint.

Returns:



39
40
41
# File 'lib/yookassa/client.rb', line 39

def refunds
  @refunds ||= Resources::Refund.new(self)
end

#settingsResources::Settings

Returns shop settings resource endpoint.

Returns:



69
70
71
# File 'lib/yookassa/client.rb', line 69

def settings
  @settings ||= Resources::Settings.new(self)
end

#webhooksResources::Webhook

Returns webhook resource endpoint.

Returns:



59
60
61
# File 'lib/yookassa/client.rb', line 59

def webhooks
  @webhooks ||= Resources::Webhook.new(self)
end