class YandexMoney::Wallet
Payments from the Yandex.Money wallet
Attributes
Public Class Methods
Request a authorization URL
@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.
@param client_id [String] The client_id that was assigned to the application during registration @param 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. @param scope [String] A list of requested permissions. Items in the list are separated by a space. List items are case-sensitive. @param extra_options [Hash] A list of extra parameters for request.
@return [String] Url to user must be redirected
# 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
Access token request
@see api.yandex.com/money/doc/dg/reference/obtain-access-token.xml @see tech.yandex.ru/money/doc/dg/reference/obtain-access-token-docpage
@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.
@param client_id [String] The client_id that was assigned to the application during registration @param code [String] Temporary token (authorization code) @param 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 @param client_secret [String] A secret word for verifying the application's authenticity. Specified if the service is registered with the option to verify authenticity @return [String] Access token
# 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
# File lib/yandex_money/wallet.rb, line 11 def initialize(token) @token = token end
Public Instance Methods
Getting information about the status of the user account.
@see api.yandex.com/money/doc/dg/reference/account-info.xml @see tech.yandex.ru/money/doc/dg/reference/account-info-docpage
@return [RecursiveOpenStruct] Account information
@raise [YandexMoney::InvalidRequestError] HTTP request does not conform to protocol format. Unable to parse HTTP request, or the Authorization header is missing or has an invalid value. @raise [YandexMoney::UnauthorizedError] Nonexistent, expired, or revoked token specified. @raise [YandexMoney::InsufficientScopeError] The token does not have permissions for the requested operation. @raise [YandexMoney::ServerError] A technical error occurs (the server responds with the HTTP code 500 Internal Server Error
). The application should repeat the request with the same parameters later.
# File lib/yandex_money/wallet.rb, line 26 def account_info RecursiveOpenStruct.new send_request("/api/account-info").body end
Accepts incoming transfer with a protection code or deferred transfer
@see api.yandex.com/money/doc/dg/reference/incoming-transfer-accept.xml @see tech.yandex.ru/money/doc/dg/reference/incoming-transfer-accept-docpage/
@param operation_id [String] A operation identifier @param protection_code [String] Secret code of four decimal digits. Specified for an incoming transfer proteced by a secret code. Omitted for deferred transfers @return [RecursiveOpenStruct] An information about operation result.
@raise [YandexMoney::InvalidRequestError] HTTP request does not conform to protocol format. Unable to parse HTTP request, or the Authorization header is missing or has an invalid value. @raise [YandexMoney::UnauthorizedError] Nonexistent, expired, or revoked token specified. @raise [YandexMoney::InsufficientScopeError] The token does not have permissions for the requested operation. @raise [YandexMoney::ServerError] A technical error occurs (the server responds with the HTTP code 500 Internal Server Error
). The application should repeat the request with the same parameters later.
# 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
Rejects incoming transfer with a protection code or deferred transfer
@see api.yandex.com/money/doc/dg/reference/incoming-transfer-reject.xml @see tech.yandex.ru/money/doc/dg/reference/incoming-transfer-reject-docpage/
@param operation_id [String] A operation identifier @return [RecursiveOpenStruct] An information about operation result.
@raise [YandexMoney::InvalidRequestError] HTTP request does not conform to protocol format. Unable to parse HTTP request, or the Authorization header is missing or has an invalid value. @raise [YandexMoney::UnauthorizedError] Nonexistent, expired, or revoked token specified. @raise [YandexMoney::InsufficientScopeError] The token does not have permissions for the requested operation. @raise [YandexMoney::ServerError] A technical error occurs (the server responds with the HTTP code 500 Internal Server Error
). The application should repeat the request with the same parameters later.
# 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
Returns details of operation specified by operation_id
@see api.yandex.com/money/doc/dg/reference/operation-details.xml @see tech.yandex.ru/money/doc/dg/reference/operation-details-docpage/
@param operation_id [String] A operation identifier @return [RecursiveOpenStruct] All details of requested operation.
@raise [YandexMoney::InvalidRequestError] HTTP request does not conform to protocol format. Unable to parse HTTP request, or the Authorization header is missing or has an invalid value. @raise [YandexMoney::UnauthorizedError] Nonexistent, expired, or revoked token specified. @raise [YandexMoney::InsufficientScopeError] The token does not have permissions for the requested operation. @raise [YandexMoney::ServerError] A technical error occurs (the server responds with the HTTP code 500 Internal Server Error
). The application should repeat the request with the same parameters later.
# 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
Returns operation history of a user's wallet
@see api.yandex.com/money/doc/dg/reference/operation-history.xml @see tech.yandex.ru/money/doc/dg/reference/operation-history-docpage/
@param options [Hash] A hash with filter parameters according to documetation @return [Array<RecursiveOpenStruct>] An array containing user's wallet operations.
@raise [YandexMoney::InvalidRequestError] HTTP request does not conform to protocol format. Unable to parse HTTP request, or the Authorization header is missing or has an invalid value. @raise [YandexMoney::UnauthorizedError] Nonexistent, expired, or revoked token specified. @raise [YandexMoney::InsufficientScopeError] The token does not have permissions for the requested operation. @raise [YandexMoney::ServerError] A technical error occurs (the server responds with the HTTP code 500 Internal Server Error
). The application should repeat the request with the same parameters later.
# 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
Confirms a payment that was created using the request-payment method.
@see api.yandex.com/money/doc/dg/reference/process-payment.xml @see tech.yandex.ru/money/doc/dg/reference/process-payment-docpage/
@param options [Hash] A method's parameters. Check out docs for more information @return [RecursiveOpenStruct] A status of payment and additional steps for authorization (if needed)
@raise [YandexMoney::InvalidRequestError] HTTP request does not conform to protocol format. Unable to parse HTTP request, or the Authorization header is missing or has an invalid value. @raise [YandexMoney::UnauthorizedError] Nonexistent, expired, or revoked token specified. @raise [YandexMoney::InsufficientScopeError] The token does not have permissions for the requested operation. @raise [YandexMoney::ServerError] A technical error occurs (the server responds with the HTTP code 500 Internal Server Error
). The application should repeat the request with the same parameters later.
# File lib/yandex_money/wallet.rb, line 97 def process_payment(options) send_payment_request("/api/process-payment", options) end
Requests a payment
@see api.yandex.com/money/doc/dg/reference/request-payment.xml @see tech.yandex.ru/money/doc/dg/reference/request-payment-docpage/
@param options [Hash] A method's parameters. Check out docs for more information @return [RecursiveOpenStruct] `payment_id` and additional information about a recipient and payer.
@raise [YandexMoney::InvalidRequestError] HTTP request does not conform to protocol format. Unable to parse HTTP request, or the Authorization header is missing or has an invalid value. @raise [YandexMoney::UnauthorizedError] Nonexistent, expired, or revoked token specified. @raise [YandexMoney::InsufficientScopeError] The token does not have permissions for the requested operation. @raise [YandexMoney::ServerError] A technical error occurs (the server responds with the HTTP code 500 Internal Server Error
). The application should repeat the request with the same parameters later.
# File lib/yandex_money/wallet.rb, line 81 def request_payment(options) send_payment_request("/api/request-payment", options) end
Protected Instance Methods
# File lib/yandex_money/wallet.rb, line 210 def send_payment_request(uri, options) response = send_request(uri, options) RecursiveOpenStruct.new(response.body, recurse_over_arrays: true) end
# File lib/yandex_money/wallet.rb, line 194 def send_request(uri, options = nil) response = self.class.post(uri, headers: { "Authorization" => "Bearer #{@token}", "Content-Type" => "application/x-www-form-urlencoded" }, body: options) case response.status when 400 then raise YandexMoney::InvalidRequestError.new response when 401 then raise YandexMoney::UnauthorizedError.new response when 403 then raise YandexMoney::InsufficientScopeError.new response when 500 then raise YandexMoney::ServerError else response end end