Class: YandexMoney::Wallet
- Inherits:
-
Object
- Object
- YandexMoney::Wallet
- Includes:
- Client
- Defined in:
- lib/yandex_money/wallet.rb
Overview
Payments from the Yandex.Money wallet
Instance Attribute Summary collapse
-
#token ⇒ Object
Returns the value of attribute token.
Class Method Summary collapse
-
.build_obtain_token_url(client_id, redirect_uri, scope, extra_options = {}) ⇒ String
Request a authorization URL.
-
.get_access_token(client_id, code, redirect_uri, client_secret = nil) ⇒ String
Access token request.
Instance Method Summary collapse
-
#account_info ⇒ RecursiveOpenStruct
Getting information about the status of the user account.
-
#incoming_transfer_accept(operation_id, protection_code = nil) ⇒ RecursiveOpenStruct
Accepts incoming transfer with a protection code or deferred transfer.
-
#incoming_transfer_reject(operation_id) ⇒ RecursiveOpenStruct
Rejects incoming transfer with a protection code or deferred transfer.
-
#initialize(token) ⇒ Wallet
constructor
A new instance of Wallet.
-
#operation_details(operation_id) ⇒ RecursiveOpenStruct
Returns details of operation specified by operation_id.
-
#operation_history(options = nil) ⇒ Array<RecursiveOpenStruct>
Returns operation history of a user's wallet.
-
#process_payment(options) ⇒ RecursiveOpenStruct
Confirms a payment that was created using the request-payment method.
-
#request_payment(options) ⇒ RecursiveOpenStruct
Requests a payment.
Methods included from Client
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
#token ⇒ Object
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
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.
The authorization result is returned as an HTTP 302 Redirect. The application must process the HTTP Redirect response.
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
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, = {}) uri = "#{YandexMoney.config.sp_money_url}/oauth/authorize" = { client_id: client_id, response_type: "code", redirect_uri: redirect_uri, scope: scope } YandexMoney::Client.post(uri, body: .merge()).headers['location'] end |
.get_access_token(client_id, code, redirect_uri, client_secret = nil) ⇒ String
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
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" = { code: code, client_id: client_id, grant_type: "authorization_code", redirect_uri: redirect_uri } [:client_secret] = client_secret if client_secret response = YandexMoney::Client.post(uri, body: ).body response["access_token"] end |
Instance Method Details
#account_info ⇒ RecursiveOpenStruct
Getting information about the status of the user account.
26 27 28 |
# File 'lib/yandex_money/wallet.rb', line 26 def account_info 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
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
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
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
42 43 44 45 46 47 48 49 50 |
# File 'lib/yandex_money/wallet.rb', line 42 def operation_history(=nil) history = RecursiveOpenStruct.new( send_request("/api/operation-history", ).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.
97 98 99 |
# File 'lib/yandex_money/wallet.rb', line 97 def process_payment() send_payment_request("/api/process-payment", ) end |
#request_payment(options) ⇒ RecursiveOpenStruct
Requests a payment
81 82 83 |
# File 'lib/yandex_money/wallet.rb', line 81 def request_payment() send_payment_request("/api/request-payment", ) end |