Class: YandexMoney::Wallet
- Inherits:
-
Object
- Object
- YandexMoney::Wallet
- Includes:
- HTTParty
- 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) ⇒ 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.
Constructor Details
#initialize(token) ⇒ Wallet
Returns a new instance of Wallet.
14 15 16 |
# File 'lib/yandex_money/wallet.rb', line 14 def initialize(token) @token = token end |
Instance Attribute Details
#token ⇒ Object
Returns the value of attribute token.
12 13 14 |
# File 'lib/yandex_money/wallet.rb', line 12 def token @token end |
Class Method Details
.build_obtain_token_url(client_id, redirect_uri, scope) ⇒ 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
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/yandex_money/wallet.rb', line 157 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 } HTTParty.post(uri, body: ).request.path.to_s 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
180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/yandex_money/wallet.rb', line 180 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 = HTTParty.post(uri, body: ).parsed_response response["access_token"] end |
Instance Method Details
#account_info ⇒ RecursiveOpenStruct
Getting information about the status of the user account.
29 30 31 |
# File 'lib/yandex_money/wallet.rb', line 29 def account_info RecursiveOpenStruct.new send_request("/api/account-info", recurse_over_arrays: true).parsed_response end |
#incoming_transfer_accept(operation_id, protection_code = nil) ⇒ RecursiveOpenStruct
Accepts incoming transfer with a protection code or deferred transfer
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/yandex_money/wallet.rb', line 117 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) end |
#incoming_transfer_reject(operation_id) ⇒ RecursiveOpenStruct
Rejects incoming transfer with a protection code or deferred transfer
142 143 144 |
# File 'lib/yandex_money/wallet.rb', line 142 def incoming_transfer_reject(operation_id) RecursiveOpenStruct.new send_request("/api/incoming-transfer-reject", operation_id: operation_id) end |
#operation_details(operation_id) ⇒ RecursiveOpenStruct
Returns details of operation specified by operation_id
67 68 69 70 |
# File 'lib/yandex_money/wallet.rb', line 67 def operation_details(operation_id) request = send_request("/api/operation-details", operation_id: operation_id) RecursiveOpenStruct.new request.parsed_response end |
#operation_history(options = nil) ⇒ Array<RecursiveOpenStruct>
Returns operation history of a user's wallet
45 46 47 48 49 50 51 52 53 |
# File 'lib/yandex_money/wallet.rb', line 45 def operation_history(=nil) history = RecursiveOpenStruct.new( send_request("/api/operation-history", ).parsed_response ) 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.
100 101 102 |
# File 'lib/yandex_money/wallet.rb', line 100 def process_payment() send_payment_request("/api/process-payment", ) end |
#request_payment(options) ⇒ RecursiveOpenStruct
Requests a payment
84 85 86 |
# File 'lib/yandex_money/wallet.rb', line 84 def request_payment() send_payment_request("/api/request-payment", ) end |