Class: YandexMoney::Wallet

Inherits:
Object
  • Object
show all
Includes:
Client
Defined in:
lib/yandex_money/wallet.rb

Overview

Payments from the Yandex.Money wallet

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Client

included, post

Constructor Details

#initialize(token) ⇒ Wallet

Returns a new instance of Wallet.



11
12
13
# File 'lib/yandex_money/wallet.rb', line 11

def initialize(token)
  @token = token
end

Instance Attribute Details

#tokenObject

Returns the value of attribute token.



9
10
11
# File 'lib/yandex_money/wallet.rb', line 9

def token
  @token
end

Class Method Details

.build_obtain_token_url(client_id, redirect_uri, scope, extra_options = {}) ⇒ String

Note:

For the authorization request, the user is redirected to the Yandex.Money authorization page. The user enters his login and password, reviews the list of requested permissions and payment limits, and either approves or rejects the application's authorization request.

Note:

The authorization result is returned as an HTTP 302 Redirect. The application must process the HTTP Redirect response.

Note:

Attention! If a user repeats the application authorization with the same value for the client_id parameter, the previous authorization is canceled.

Request a authorization URL

Parameters:

  • client_id (String)

    The client_id that was assigned to the application during registration

  • redirect_uri (String)

    URI that the OAuth server sends the authorization result to. Must have a string value that exactly matches the redirect_uri parameter specified in the application registration data. Any additional parameters required for the application can be added at the end of the string.

  • scope (String)

    A list of requested permissions. Items in the list are separated by a space. List items are case-sensitive.

  • extra_options (Hash) (defaults to: {})

    A list of extra parameters for request.

Returns:

  • (String)

    Url to user must be redirected



155
156
157
158
159
160
161
162
163
164
# File 'lib/yandex_money/wallet.rb', line 155

def self.build_obtain_token_url(client_id, redirect_uri, scope, extra_options = {})
  uri = "#{YandexMoney.config.sp_money_url}/oauth/authorize"
  options = {
    client_id: client_id,
    response_type: "code",
    redirect_uri: redirect_uri,
    scope: scope
  }
  YandexMoney::Client.post(uri, body: options.merge(extra_options)).headers['location']
end

.get_access_token(client_id, code, redirect_uri, client_secret = nil) ⇒ String

Note:

If authorization was completed successfully, the application should immediately exchange the temporary authorization code for an access token. To do this, a request containing the temporary authorization code must be sent to the Yandex.Money OAuth server.

Access token request

Parameters:

  • client_id (String)

    The client_id that was assigned to the application during registration

  • code (String)

    Temporary token (authorization code)

  • redirect_uri (String)

    URI that the OAuth server sends the authorization result to. The value of this parameter must exactly match the redirect_uri value from the previous "authorize" call

  • client_secret (String) (defaults to: nil)

    A secret word for verifying the application's authenticity. Specified if the service is registered with the option to verify authenticity

Returns:

  • (String)

    Access token

See Also:



178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/yandex_money/wallet.rb', line 178

def self.get_access_token(client_id, code, redirect_uri, client_secret=nil)
  uri = "#{YandexMoney.config.sp_money_url}/oauth/token"
  options = {
    code: code,
    client_id: client_id,
    grant_type: "authorization_code",
    redirect_uri: redirect_uri
  }
  options[:client_secret] = client_secret if client_secret

  response = YandexMoney::Client.post(uri, body: options).body
  response["access_token"]
end

Instance Method Details

#account_infoRecursiveOpenStruct

Getting information about the status of the user account.

Returns:

  • (RecursiveOpenStruct)

    Account information

Raises:

See Also:



26
27
28
# File 'lib/yandex_money/wallet.rb', line 26

def 
  RecursiveOpenStruct.new send_request("/api/account-info").body
end

#incoming_transfer_accept(operation_id, protection_code = nil) ⇒ RecursiveOpenStruct

Accepts incoming transfer with a protection code or deferred transfer

Parameters:

  • operation_id (String)

    A operation identifier

  • protection_code (String) (defaults to: nil)

    Secret code of four decimal digits. Specified for an incoming transfer proteced by a secret code. Omitted for deferred transfers

Returns:

  • (RecursiveOpenStruct)

    An information about operation result.

Raises:

See Also:



114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/yandex_money/wallet.rb', line 114

def incoming_transfer_accept(operation_id, protection_code = nil)
  uri = "/api/incoming-transfer-accept"
  if protection_code
    request_body = {
      operation_id: operation_id,
      protection_code: protection_code
    }
  else
    request_body = { operation_id: operation_id }
  end
  RecursiveOpenStruct.new send_request("/api/incoming-transfer-accept", request_body).body
end

#incoming_transfer_reject(operation_id) ⇒ RecursiveOpenStruct

Rejects incoming transfer with a protection code or deferred transfer

Parameters:

  • operation_id (String)

    A operation identifier

Returns:

  • (RecursiveOpenStruct)

    An information about operation result.

Raises:

See Also:



139
140
141
# File 'lib/yandex_money/wallet.rb', line 139

def incoming_transfer_reject(operation_id)
  RecursiveOpenStruct.new send_request("/api/incoming-transfer-reject", operation_id: operation_id).body
end

#operation_details(operation_id) ⇒ RecursiveOpenStruct

Returns details of operation specified by operation_id

Parameters:

  • operation_id (String)

    A operation identifier

Returns:

  • (RecursiveOpenStruct)

    All details of requested operation.

Raises:

See Also:



64
65
66
67
# File 'lib/yandex_money/wallet.rb', line 64

def operation_details(operation_id)
  response = send_request("/api/operation-details", operation_id: operation_id)
  RecursiveOpenStruct.new response.body
end

#operation_history(options = nil) ⇒ Array<RecursiveOpenStruct>

Returns operation history of a user's wallet

Parameters:

  • options (Hash) (defaults to: nil)

    A hash with filter parameters according to documetation

Returns:

  • (Array<RecursiveOpenStruct>)

    An array containing user's wallet operations.

Raises:

See Also:



42
43
44
45
46
47
48
49
50
# File 'lib/yandex_money/wallet.rb', line 42

def operation_history(options=nil)
  history = RecursiveOpenStruct.new(
    send_request("/api/operation-history", options).body
  )
  history.operations = history.operations.map do |operation|
    RecursiveOpenStruct.new operation
  end
  history
end

#process_payment(options) ⇒ RecursiveOpenStruct

Confirms a payment that was created using the request-payment method.

Parameters:

  • options (Hash)

    A method's parameters. Check out docs for more information

Returns:

  • (RecursiveOpenStruct)

    A status of payment and additional steps for authorization (if needed)

Raises:

See Also:



97
98
99
# File 'lib/yandex_money/wallet.rb', line 97

def process_payment(options)
  send_payment_request("/api/process-payment", options)
end

#request_payment(options) ⇒ RecursiveOpenStruct

Requests a payment

Parameters:

  • options (Hash)

    A method's parameters. Check out docs for more information

Returns:

  • (RecursiveOpenStruct)

    payment_id and additional information about a recipient and payer.

Raises:

See Also:



81
82
83
# File 'lib/yandex_money/wallet.rb', line 81

def request_payment(options)
  send_payment_request("/api/request-payment", options)
end