Class: YandexMoney::Api
- Inherits:
-
Object
- Object
- YandexMoney::Api
- Includes:
- HTTParty
- Defined in:
- lib/yandex_money/api.rb,
lib/yandex_money/api/version.rb
Constant Summary collapse
- VERSION =
"0.10.0"
Instance Attribute Summary collapse
-
#client_url ⇒ Object
Returns the value of attribute client_url.
-
#code ⇒ Object
Returns the value of attribute code.
-
#instance_id ⇒ Object
Returns the value of attribute instance_id.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
-
#account_info ⇒ Object
obtains account info.
- #get_instance_id ⇒ Object
- #incoming_transfer_accept(operation_id, protection_code = nil) ⇒ Object
- #incoming_transfer_reject(operation_id) ⇒ Object
-
#initialize(options) ⇒ Api
constructor
Returns url to get token.
-
#obtain_token(client_secret = nil) ⇒ Object
obtains and saves token from code.
-
#operation_details(operation_id) ⇒ Object
obtains operation details.
-
#operation_history(options = nil) ⇒ Object
obtains operation history.
- #process_external_payment(payment_options) ⇒ Object
-
#process_payment(options) ⇒ Object
basic process payment method.
- #request_external_payment(payment_options) ⇒ Object
-
#request_payment(options) ⇒ Object
basic request payment method.
Constructor Details
#initialize(options) ⇒ Api
Returns url to get token
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/yandex_money/api.rb', line 17 def initialize() # TOKEN provided if .length == 1 && [:token] != nil @token = [:token] else @client_id = [:client_id] @redirect_uri = [:redirect_uri] @instance_id = [:instance_id] if [:scope] != nil @client_url = ( client_id: @client_id, response_type: "code", redirect_uri: @redirect_uri, scope: [:scope] ) end end end |
Instance Attribute Details
#client_url ⇒ Object
Returns the value of attribute client_url.
14 15 16 |
# File 'lib/yandex_money/api.rb', line 14 def client_url @client_url end |
#code ⇒ Object
Returns the value of attribute code.
14 15 16 |
# File 'lib/yandex_money/api.rb', line 14 def code @code end |
#instance_id ⇒ Object
Returns the value of attribute instance_id.
14 15 16 |
# File 'lib/yandex_money/api.rb', line 14 def instance_id @instance_id end |
#token ⇒ Object
Returns the value of attribute token.
14 15 16 |
# File 'lib/yandex_money/api.rb', line 14 def token @token end |
Instance Method Details
#account_info ⇒ Object
obtains account info
52 53 54 55 |
# File 'lib/yandex_money/api.rb', line 52 def account_info check_token OpenStruct.new send_request("/api/account-info").parsed_response end |
#get_instance_id ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/yandex_money/api.rb', line 102 def get_instance_id request = send_request("/api/instance-id", client_id: @client_id) if request["status"] == "refused" raise YandexMoney::ApiError.new request["error"] else request["instance_id"] end end |
#incoming_transfer_accept(operation_id, protection_code = nil) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/yandex_money/api.rb', line 111 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 request = send_request("/api/incoming-transfer-accept", request_body) if request["status"] == "refused" raise YandexMoney::AcceptTransferError.new request["error"], request["protection_code_attempts_available"] else true end end |
#incoming_transfer_reject(operation_id) ⇒ Object
130 131 132 133 134 135 136 137 138 |
# File 'lib/yandex_money/api.rb', line 130 def incoming_transfer_reject(operation_id) request = send_request("/api/incoming-transfer-reject", operation_id: operation_id) if request["status"] == "refused" raise YandexMoney::ApiError.new request["error"] else true end end |
#obtain_token(client_secret = nil) ⇒ Object
obtains and saves token from code
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/yandex_money/api.rb', line 37 def obtain_token(client_secret = nil) raise YandexMoney::FieldNotSetError.new(:code) if @code == nil uri = "/oauth/token" = { code: @code, client_id: @client_id, grant_type: "authorization_code", redirect_uri: @redirect_url } [:client_secret] = client_secret if client_secret @token = self.class.post(uri, body: ) .parsed_response["access_token"] end |
#operation_details(operation_id) ⇒ Object
obtains operation details
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/yandex_money/api.rb', line 64 def operation_details(operation_id) check_token request = send_request("/api/operation-details", operation_id: operation_id) details = OpenStruct.new request.parsed_response if details.error raise YandexMoney::ApiError.new details.error else details end end |
#operation_history(options = nil) ⇒ Object
obtains operation history
58 59 60 61 |
# File 'lib/yandex_money/api.rb', line 58 def operation_history(=nil) check_token OpenStruct.new send_request("/api/operation-history", ).parsed_response end |
#process_external_payment(payment_options) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/yandex_money/api.rb', line 150 def process_external_payment() [:instance_id] ||= @instance_id request = send_request("/api/process-external-payment", ) if request["status"] == "refused" raise YandexMoney::ApiError.new request["error"] elsif request["status"] == "in_progress" raise YandexMoney::ExternalPaymentProgressError.new request["error"], request["next_retry"] else OpenStruct.new request.parsed_response end end |
#process_payment(options) ⇒ Object
basic process payment method
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/yandex_money/api.rb', line 90 def process_payment() check_token request = send_request("/api/process-payment", ) response = OpenStruct.new request.parsed_response if response.error raise YandexMoney::ApiError.new response.error else response end end |
#request_external_payment(payment_options) ⇒ Object
140 141 142 143 144 145 146 147 148 |
# File 'lib/yandex_money/api.rb', line 140 def request_external_payment() [:instance_id] ||= @instance_id request = send_request("/api/request-external-payment", ) if request["status"] == "refused" raise YandexMoney::ApiError.new request["error"] else OpenStruct.new request.parsed_response end end |
#request_payment(options) ⇒ Object
basic request payment method
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/yandex_money/api.rb', line 76 def request_payment() check_token response = with_http_retries do request = send_request("/api/request-payment", ) OpenStruct.new request.parsed_response end if response.error raise YandexMoney::ApiError.new response.error else response end end |