yandex-money-client 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/.rspec +2 -0
- data/.travis.yml +8 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +43 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +159 -0
- data/Rakefile +7 -0
- data/lib/yandex_money/api.rb +10 -0
- data/lib/yandex_money/api/version.rb +5 -0
- data/lib/yandex_money/client.rb +56 -0
- data/lib/yandex_money/config.rb +26 -0
- data/lib/yandex_money/exceptions.rb +71 -0
- data/lib/yandex_money/external_payment.rb +81 -0
- data/lib/yandex_money/wallet.rb +215 -0
- data/spec/account_info_spec.rb +64 -0
- data/spec/auth_spec.rb +35 -0
- data/spec/cards_spec.rb +55 -0
- data/spec/config_spec.rb +50 -0
- data/spec/exceptions_spec.rb +55 -0
- data/spec/fixtures/vcr_cassettes/accept_incoming_transfer_with_protection_code.yml +40 -0
- data/spec/fixtures/vcr_cassettes/accept_incoming_transfer_with_protection_code_with_wrong_code.yml +40 -0
- data/spec/fixtures/vcr_cassettes/get_account_info.yml +40 -0
- data/spec/fixtures/vcr_cassettes/get_instance_id_fail.yml +38 -0
- data/spec/fixtures/vcr_cassettes/get_instance_id_success.yml +38 -0
- data/spec/fixtures/vcr_cassettes/get_operation_details.yml +233 -0
- data/spec/fixtures/vcr_cassettes/get_operation_history.yml +186 -0
- data/spec/fixtures/vcr_cassettes/get_operation_history_with_params.yml +46 -0
- data/spec/fixtures/vcr_cassettes/get_token_from_authorization_code.yml +48 -0
- data/spec/fixtures/vcr_cassettes/get_wrong_operation_details.yml +40 -0
- data/spec/fixtures/vcr_cassettes/init_without_client_secret.yml +843 -0
- data/spec/fixtures/vcr_cassettes/initialize_with_token.yml +40 -0
- data/spec/fixtures/vcr_cassettes/insufficient_scope_error.yml +40 -0
- data/spec/fixtures/vcr_cassettes/invalid_request_error.yml +40 -0
- data/spec/fixtures/vcr_cassettes/process_external_payment.yml +114 -0
- data/spec/fixtures/vcr_cassettes/process_payment_to_an_account_with_failure.yml +41 -0
- data/spec/fixtures/vcr_cassettes/reject_payment.yml +40 -0
- data/spec/fixtures/vcr_cassettes/reject_payment_fail.yml +40 -0
- data/spec/fixtures/vcr_cassettes/request_external_payment.yml +79 -0
- data/spec/fixtures/vcr_cassettes/request_payment_to_an_account_with_failure.yml +41 -0
- data/spec/fixtures/vcr_cassettes/success_process_payment_to_an_account.yml +40 -0
- data/spec/fixtures/vcr_cassettes/success_request_payment_to_an_account.yml +41 -0
- data/spec/fixtures/vcr_cassettes/unauthorized_error.yml +41 -0
- data/spec/fixtures/vcr_cassettes/unauthorized_exception.yml +41 -0
- data/spec/logger_spec.rb +1 -0
- data/spec/payments_spec.rb +80 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/support/constants.example.rb +13 -0
- data/yandex-money-client.gemspec +31 -0
- metadata +269 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
module YandexMoney
|
2
|
+
# Payments from bank cards without authorization
|
3
|
+
#
|
4
|
+
# @see http://api.yandex.com/money/doc/dg/reference/process-external-payments.xml
|
5
|
+
# @see https://tech.yandex.ru/money/doc/dg/reference/process-external-payments-docpage/
|
6
|
+
class ExternalPayment
|
7
|
+
include YandexMoney::Client
|
8
|
+
|
9
|
+
base_uri YandexMoney.config.money_url
|
10
|
+
|
11
|
+
def initialize(instance_id)
|
12
|
+
@instance_id = instance_id
|
13
|
+
end
|
14
|
+
|
15
|
+
# Registers instance of application
|
16
|
+
#
|
17
|
+
# @see http://api.yandex.com/money/doc/dg/reference/instance-id.xml
|
18
|
+
# @see https://tech.yandex.ru/money/doc/dg/reference/instance-id-docpage/
|
19
|
+
#
|
20
|
+
# @param client_id [String] An identifier of application
|
21
|
+
#
|
22
|
+
# @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.
|
23
|
+
# @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.
|
24
|
+
#
|
25
|
+
# @return [RecursiveOpenStruct] A status of operation
|
26
|
+
def self.get_instance_id(client_id)
|
27
|
+
response = send_external_payment_request("/api/instance-id", client_id: client_id)
|
28
|
+
RecursiveOpenStruct.new response.body
|
29
|
+
end
|
30
|
+
|
31
|
+
# Requests a external payment
|
32
|
+
#
|
33
|
+
# @see http://api.yandex.com/money/doc/dg/reference/request-external-payment.xml
|
34
|
+
# @see https://tech.yandex.ru/money/doc/dg/reference/request-external-payment-docpage/
|
35
|
+
#
|
36
|
+
# @param payment_options [Hash] Method's parameters. Check out docs for more information.
|
37
|
+
#
|
38
|
+
# @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.
|
39
|
+
# @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.
|
40
|
+
#
|
41
|
+
# @return [RecursiveOpenStruct] A struct, containing `payment_id` and additional information about a recipient and payer
|
42
|
+
def request_external_payment(payment_options)
|
43
|
+
payment_options[:instance_id] = @instance_id
|
44
|
+
response = self.class.send_external_payment_request("/api/request-external-payment", payment_options)
|
45
|
+
RecursiveOpenStruct.new response.body
|
46
|
+
end
|
47
|
+
|
48
|
+
# Confirms a payment that was created using the request-extenral-payment method
|
49
|
+
#
|
50
|
+
# @see http://api.yandex.com/money/doc/dg/reference/process-external-payment.xml
|
51
|
+
# @see https://tech.yandex.ru/money/doc/dg/reference/process-external-payment-docpage/
|
52
|
+
#
|
53
|
+
# @param payment_options [Hash] Method's parameters. Check out docs for more information.
|
54
|
+
#
|
55
|
+
# @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.
|
56
|
+
# @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.
|
57
|
+
#
|
58
|
+
# @return [RecursiveOpenStruct] A status of payment and additional steps for authorization (if needed)
|
59
|
+
def process_external_payment(payment_options)
|
60
|
+
payment_options[:instance_id] = @instance_id
|
61
|
+
response = self.class.send_external_payment_request("/api/process-external-payment", payment_options)
|
62
|
+
RecursiveOpenStruct.new response.body
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def self.send_external_payment_request(uri, options)
|
68
|
+
response = self.post(uri, headers: {
|
69
|
+
"Content-Type" => "application/x-www-form-urlencoded"
|
70
|
+
}, body: options)
|
71
|
+
case response.status
|
72
|
+
when 400 then raise YandexMoney::InvalidRequestError.new response
|
73
|
+
when 401 then raise YandexMoney::UnauthorizedError.new response
|
74
|
+
when 403 then raise YandexMoney::InsufficientScopeError response
|
75
|
+
when 500 then raise YandexMoney::ServerError
|
76
|
+
else
|
77
|
+
response
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,215 @@
|
|
1
|
+
module YandexMoney
|
2
|
+
# Payments from the Yandex.Money wallet
|
3
|
+
class Wallet
|
4
|
+
include YandexMoney::Client
|
5
|
+
|
6
|
+
base_uri YandexMoney.config.money_url
|
7
|
+
default_timeout 30
|
8
|
+
|
9
|
+
attr_accessor :token
|
10
|
+
|
11
|
+
def initialize(token)
|
12
|
+
@token = token
|
13
|
+
end
|
14
|
+
|
15
|
+
# Getting information about the status of the user account.
|
16
|
+
#
|
17
|
+
# @see http://api.yandex.com/money/doc/dg/reference/account-info.xml
|
18
|
+
# @see https://tech.yandex.ru/money/doc/dg/reference/account-info-docpage
|
19
|
+
#
|
20
|
+
# @return [RecursiveOpenStruct] Account information
|
21
|
+
#
|
22
|
+
# @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.
|
23
|
+
# @raise [YandexMoney::UnauthorizedError] Nonexistent, expired, or revoked token specified.
|
24
|
+
# @raise [YandexMoney::InsufficientScopeError] The token does not have permissions for the requested operation.
|
25
|
+
# @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.
|
26
|
+
def account_info
|
27
|
+
RecursiveOpenStruct.new send_request("/api/account-info").body
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns operation history of a user's wallet
|
31
|
+
#
|
32
|
+
# @see http://api.yandex.com/money/doc/dg/reference/operation-history.xml
|
33
|
+
# @see https://tech.yandex.ru/money/doc/dg/reference/operation-history-docpage/
|
34
|
+
#
|
35
|
+
# @param options [Hash] A hash with filter parameters according to documetation
|
36
|
+
# @return [Array<RecursiveOpenStruct>] An array containing user's wallet operations.
|
37
|
+
#
|
38
|
+
# @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.
|
39
|
+
# @raise [YandexMoney::UnauthorizedError] Nonexistent, expired, or revoked token specified.
|
40
|
+
# @raise [YandexMoney::InsufficientScopeError] The token does not have permissions for the requested operation.
|
41
|
+
# @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.
|
42
|
+
def operation_history(options=nil)
|
43
|
+
history = RecursiveOpenStruct.new(
|
44
|
+
send_request("/api/operation-history", options).body
|
45
|
+
)
|
46
|
+
history.operations = history.operations.map do |operation|
|
47
|
+
RecursiveOpenStruct.new operation
|
48
|
+
end
|
49
|
+
history
|
50
|
+
end
|
51
|
+
|
52
|
+
# Returns details of operation specified by operation_id
|
53
|
+
#
|
54
|
+
# @see http://api.yandex.com/money/doc/dg/reference/operation-details.xml
|
55
|
+
# @see https://tech.yandex.ru/money/doc/dg/reference/operation-details-docpage/
|
56
|
+
#
|
57
|
+
# @param operation_id [String] A operation identifier
|
58
|
+
# @return [RecursiveOpenStruct] All details of requested operation.
|
59
|
+
#
|
60
|
+
# @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.
|
61
|
+
# @raise [YandexMoney::UnauthorizedError] Nonexistent, expired, or revoked token specified.
|
62
|
+
# @raise [YandexMoney::InsufficientScopeError] The token does not have permissions for the requested operation.
|
63
|
+
# @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.
|
64
|
+
def operation_details(operation_id)
|
65
|
+
response = send_request("/api/operation-details", operation_id: operation_id)
|
66
|
+
RecursiveOpenStruct.new response.body
|
67
|
+
end
|
68
|
+
|
69
|
+
# Requests a payment
|
70
|
+
#
|
71
|
+
# @see http://api.yandex.com/money/doc/dg/reference/request-payment.xml
|
72
|
+
# @see https://tech.yandex.ru/money/doc/dg/reference/request-payment-docpage/
|
73
|
+
#
|
74
|
+
# @param options [Hash] A method's parameters. Check out docs for more information
|
75
|
+
# @return [RecursiveOpenStruct] `payment_id` and additional information about a recipient and payer.
|
76
|
+
#
|
77
|
+
# @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.
|
78
|
+
# @raise [YandexMoney::UnauthorizedError] Nonexistent, expired, or revoked token specified.
|
79
|
+
# @raise [YandexMoney::InsufficientScopeError] The token does not have permissions for the requested operation.
|
80
|
+
# @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.
|
81
|
+
def request_payment(options)
|
82
|
+
send_payment_request("/api/request-payment", options)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Confirms a payment that was created using the request-payment method.
|
86
|
+
#
|
87
|
+
# @see http://api.yandex.com/money/doc/dg/reference/process-payment.xml
|
88
|
+
# @see https://tech.yandex.ru/money/doc/dg/reference/process-payment-docpage/
|
89
|
+
#
|
90
|
+
# @param options [Hash] A method's parameters. Check out docs for more information
|
91
|
+
# @return [RecursiveOpenStruct] A status of payment and additional steps for authorization (if needed)
|
92
|
+
#
|
93
|
+
# @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.
|
94
|
+
# @raise [YandexMoney::UnauthorizedError] Nonexistent, expired, or revoked token specified.
|
95
|
+
# @raise [YandexMoney::InsufficientScopeError] The token does not have permissions for the requested operation.
|
96
|
+
# @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.
|
97
|
+
def process_payment(options)
|
98
|
+
send_payment_request("/api/process-payment", options)
|
99
|
+
end
|
100
|
+
|
101
|
+
# Accepts incoming transfer with a protection code or deferred transfer
|
102
|
+
#
|
103
|
+
# @see http://api.yandex.com/money/doc/dg/reference/incoming-transfer-accept.xml
|
104
|
+
# @see https://tech.yandex.ru/money/doc/dg/reference/incoming-transfer-accept-docpage/
|
105
|
+
#
|
106
|
+
# @param operation_id [String] A operation identifier
|
107
|
+
# @param protection_code [String] Secret code of four decimal digits. Specified for an incoming transfer proteced by a secret code. Omitted for deferred transfers
|
108
|
+
# @return [RecursiveOpenStruct] An information about operation result.
|
109
|
+
#
|
110
|
+
# @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.
|
111
|
+
# @raise [YandexMoney::UnauthorizedError] Nonexistent, expired, or revoked token specified.
|
112
|
+
# @raise [YandexMoney::InsufficientScopeError] The token does not have permissions for the requested operation.
|
113
|
+
# @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.
|
114
|
+
def incoming_transfer_accept(operation_id, protection_code = nil)
|
115
|
+
uri = "/api/incoming-transfer-accept"
|
116
|
+
if protection_code
|
117
|
+
request_body = {
|
118
|
+
operation_id: operation_id,
|
119
|
+
protection_code: protection_code
|
120
|
+
}
|
121
|
+
else
|
122
|
+
request_body = { operation_id: operation_id }
|
123
|
+
end
|
124
|
+
RecursiveOpenStruct.new send_request("/api/incoming-transfer-accept", request_body).body
|
125
|
+
end
|
126
|
+
|
127
|
+
# Rejects incoming transfer with a protection code or deferred transfer
|
128
|
+
#
|
129
|
+
# @see http://api.yandex.com/money/doc/dg/reference/incoming-transfer-reject.xml
|
130
|
+
# @see https://tech.yandex.ru/money/doc/dg/reference/incoming-transfer-reject-docpage/
|
131
|
+
#
|
132
|
+
# @param operation_id [String] A operation identifier
|
133
|
+
# @return [RecursiveOpenStruct] An information about operation result.
|
134
|
+
#
|
135
|
+
# @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.
|
136
|
+
# @raise [YandexMoney::UnauthorizedError] Nonexistent, expired, or revoked token specified.
|
137
|
+
# @raise [YandexMoney::InsufficientScopeError] The token does not have permissions for the requested operation.
|
138
|
+
# @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.
|
139
|
+
def incoming_transfer_reject(operation_id)
|
140
|
+
RecursiveOpenStruct.new send_request("/api/incoming-transfer-reject", operation_id: operation_id).body
|
141
|
+
end
|
142
|
+
|
143
|
+
# Request a authorization URL
|
144
|
+
#
|
145
|
+
# @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.
|
146
|
+
# @note The authorization result is returned as an HTTP 302 Redirect. The application must process the HTTP Redirect response.
|
147
|
+
# @note Attention! If a user repeats the application authorization with the same value for the client_id parameter, the previous authorization is canceled.
|
148
|
+
#
|
149
|
+
# @param client_id [String] The client_id that was assigned to the application during registration
|
150
|
+
# @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.
|
151
|
+
# @param scope [String] A list of requested permissions. Items in the list are separated by a space. List items are case-sensitive.
|
152
|
+
# @param extra_options [Hash] A list of extra parameters for request.
|
153
|
+
#
|
154
|
+
# @return [String] Url to user must be redirected
|
155
|
+
def self.build_obtain_token_url(client_id, redirect_uri, scope, extra_options = {})
|
156
|
+
uri = "#{YandexMoney.config.sp_money_url}/oauth/authorize"
|
157
|
+
options = {
|
158
|
+
client_id: client_id,
|
159
|
+
response_type: "code",
|
160
|
+
redirect_uri: redirect_uri,
|
161
|
+
scope: scope
|
162
|
+
}
|
163
|
+
YandexMoney::Client.post(uri, body: options.merge(extra_options)).headers['location']
|
164
|
+
end
|
165
|
+
|
166
|
+
# Access token request
|
167
|
+
#
|
168
|
+
# @see http://api.yandex.com/money/doc/dg/reference/obtain-access-token.xml
|
169
|
+
# @see https://tech.yandex.ru/money/doc/dg/reference/obtain-access-token-docpage
|
170
|
+
#
|
171
|
+
# @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.
|
172
|
+
#
|
173
|
+
# @param client_id [String] The client_id that was assigned to the application during registration
|
174
|
+
# @param code [String] Temporary token (authorization code)
|
175
|
+
# @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
|
176
|
+
# @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
|
177
|
+
# @return [String] Access token
|
178
|
+
def self.get_access_token(client_id, code, redirect_uri, client_secret=nil)
|
179
|
+
uri = "#{YandexMoney.config.sp_money_url}/oauth/token"
|
180
|
+
options = {
|
181
|
+
code: code,
|
182
|
+
client_id: client_id,
|
183
|
+
grant_type: "authorization_code",
|
184
|
+
redirect_uri: redirect_uri
|
185
|
+
}
|
186
|
+
options[:client_secret] = client_secret if client_secret
|
187
|
+
|
188
|
+
response = YandexMoney::Client.post(uri, body: options).body
|
189
|
+
response["access_token"]
|
190
|
+
end
|
191
|
+
|
192
|
+
protected
|
193
|
+
|
194
|
+
def send_request(uri, options = nil)
|
195
|
+
response = self.class.post(uri, headers: {
|
196
|
+
"Authorization" => "Bearer #{@token}",
|
197
|
+
"Content-Type" => "application/x-www-form-urlencoded"
|
198
|
+
}, body: options)
|
199
|
+
|
200
|
+
case response.status
|
201
|
+
when 400 then raise YandexMoney::InvalidRequestError.new response
|
202
|
+
when 401 then raise YandexMoney::UnauthorizedError.new response
|
203
|
+
when 403 then raise YandexMoney::InsufficientScopeError.new response
|
204
|
+
when 500 then raise YandexMoney::ServerError
|
205
|
+
else
|
206
|
+
response
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
def send_payment_request(uri, options)
|
211
|
+
response = send_request(uri, options)
|
212
|
+
RecursiveOpenStruct.new(response.body, recurse_over_arrays: true)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "get account info" do
|
4
|
+
before :all do
|
5
|
+
VCR.use_cassette "obtain token for get account info" do
|
6
|
+
@api = YandexMoney::Wallet.new(ACCESS_TOKEN)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should return recursive open struct" do
|
11
|
+
VCR.use_cassette "get account info" do
|
12
|
+
info = @api.account_info
|
13
|
+
expect(info.avatar.url).to start_with "https://avatars.yandex.net/"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# http://api.yandex.ru/money/doc/dg/reference/account-info.xml
|
18
|
+
it "should return account info" do
|
19
|
+
VCR.use_cassette "get account info" do
|
20
|
+
info = @api.account_info
|
21
|
+
expect(info.account).to eq WALLET_NUMBER
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# http://api.yandex.com/money/doc/dg/reference/operation-history.xml
|
26
|
+
it "should return operation history" do
|
27
|
+
VCR.use_cassette "get operation history" do
|
28
|
+
history = @api.operation_history
|
29
|
+
expect(history.operations.count).to be_between(1, 30).inclusive
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return operation history with params" do
|
34
|
+
VCR.use_cassette "get operation history with params" do
|
35
|
+
history = @api.operation_history(records: 1)
|
36
|
+
expect(history.operations.count).to eq 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# http://api.yandex.com/money/doc/dg/reference/operation-details.xml
|
41
|
+
describe "operation details" do
|
42
|
+
it "should return valid operation details" do
|
43
|
+
VCR.use_cassette "get operation details" do
|
44
|
+
history = @api.operation_history
|
45
|
+
operation_id = history.operations.first.operation_id
|
46
|
+
details = @api.operation_details operation_id
|
47
|
+
expect(details.status).to eq "success"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it "raise unauthorized exception when wrong token" do
|
52
|
+
VCR.use_cassette "unauthorized exception" do
|
53
|
+
@api = YandexMoney::Wallet.new("wrong_token")
|
54
|
+
expect { @api.operation_details "462449992116028008" }.to raise_error YandexMoney::UnauthorizedError
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should raise exception if operation_id is wrong" do
|
59
|
+
VCR.use_cassette "get wrong operation details" do
|
60
|
+
expect(@api.operation_details("unknown").error).to eq "illegal_param_operation_id"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/spec/auth_spec.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Application authorization flow" do
|
4
|
+
# http://api.yandex.ru/money/doc/dg/reference/request-access-token.xml
|
5
|
+
it "should properly initialize without client_secret" do
|
6
|
+
VCR.use_cassette "init without client secret" do
|
7
|
+
url = YandexMoney::Wallet.build_obtain_token_url(
|
8
|
+
CLIENT_ID,
|
9
|
+
REDIRECT_URI,
|
10
|
+
"account-info operation-history"
|
11
|
+
)
|
12
|
+
expect(url).to start_with("https://money.yandex.ru/select-wallet.xml?requestid=")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# http://api.yandex.ru/money/doc/dg/reference/request-access-token.xml
|
17
|
+
it "should get token from code" do
|
18
|
+
VCR.use_cassette "get token from authorization code" do
|
19
|
+
expect(
|
20
|
+
YandexMoney::Wallet.get_access_token(
|
21
|
+
CLIENT_ID,
|
22
|
+
"SOME CODE",
|
23
|
+
REDIRECT_URI
|
24
|
+
)
|
25
|
+
).to be nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "could be initialized with token" do
|
30
|
+
VCR.use_cassette "initialize with token" do
|
31
|
+
api = YandexMoney::Wallet.new(ACCESS_TOKEN)
|
32
|
+
expect(api.account_info.account).to eq WALLET_NUMBER
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/cards_spec.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Payments from bank cards without authorization" do
|
4
|
+
before :all do
|
5
|
+
VCR.use_cassette "obtain token for payments from bank cards without authorization" do
|
6
|
+
end
|
7
|
+
end
|
8
|
+
it "should fail when try to register an instance of application without connected market" do
|
9
|
+
VCR.use_cassette "get instance id fail" do
|
10
|
+
expect(
|
11
|
+
YandexMoney::ExternalPayment.get_instance_id(nil).status
|
12
|
+
).to eq "refused"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should register an instance of application" do
|
17
|
+
VCR.use_cassette "get instance id success" do
|
18
|
+
expect(
|
19
|
+
YandexMoney::ExternalPayment.get_instance_id(CLIENT_ID)
|
20
|
+
.instance_id.length
|
21
|
+
).to eq 64
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should request external payment" do
|
26
|
+
VCR.use_cassette "request external payment" do
|
27
|
+
instance_id = YandexMoney::ExternalPayment.get_instance_id(CLIENT_ID)
|
28
|
+
@api = YandexMoney::ExternalPayment.new(instance_id)
|
29
|
+
expect(@api.request_external_payment({
|
30
|
+
pattern_id: "p2p",
|
31
|
+
to: "410011285611534",
|
32
|
+
amount_due: "1.00",
|
33
|
+
message: "test"
|
34
|
+
}).status).to eq("success")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should process external payment" do
|
39
|
+
VCR.use_cassette "process external payment" do
|
40
|
+
instance_id = YandexMoney::ExternalPayment.get_instance_id(CLIENT_ID)
|
41
|
+
@api = YandexMoney::ExternalPayment.new(instance_id)
|
42
|
+
request_id = @api.request_external_payment(
|
43
|
+
pattern_id: "p2p",
|
44
|
+
to: "410011285611534",
|
45
|
+
amount_due: "1.00",
|
46
|
+
message: "test"
|
47
|
+
).request_id
|
48
|
+
expect(@api.process_external_payment({
|
49
|
+
request_id: request_id,
|
50
|
+
ext_auth_success_uri: "http://127.0.0.1:4567/success",
|
51
|
+
ext_auth_fail_uri: "http://127.0.0.1:4567/fail"
|
52
|
+
}).status).to eq("ext_auth_required")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|