1
0
зеркало из https://github.com/glebtv/yookassa.git synced 2026-09-07 11:25:51 +03:00
Этот коммит содержится в:
Andrey Paderin
2019-06-11 13:49:29 +03:00
родитель f999a58b91
Коммит e922caaa77
2 изменённых файлов: 6 добавлений и 29 удалений

Просмотреть файл

@@ -15,44 +15,21 @@ module YandexCheckout
path { "/#{payment_id}" } path { "/#{payment_id}" }
response(200) { |*res| Entity::Payment.build(*res) } response(200) { |*res| Entity::Payment.build(*res) }
response(400, 404) { |*res| Error.build(*res) } response(400, 404) { |*res| Error.build(*res) }
# Parses json response, wraps it into model with [#error] and raises
# an exception where [ResponseError#response] contains the model instance
# response(400, 422) do |(status, *)|
# raise "#{status}: Record invalid"
# end
# response(404) do |(_status, *)|
# p 'Record Not Found'
# # raise "#{status}: Record not found"
# end
end end
operation :create do operation :create do
option :payment option :payment
option :idempotency_key, optional: true option :idempotency_key, proc(&:to_s)
http_method :post http_method :post
# path { 'payments' }
# query { { params: params } }
format 'json' format 'json'
headers 'Idempotence-Key' => '244afbdc-000f-5000-a000-12526186ce10' headers { { 'Idempotence-Key' => idempotency_key } }
body { payment } body { payment }
# response 200 do |_status, _headers, body|
# p JSON.parse(*body)
# end
response(200) { |*res| Entity::Payment.build(*res) } response(200) { |*res| Entity::Payment.build(*res) }
response(400) { |*res| Error.build(*res) } response(400) { |*res| Error.build(*res) }
# Parses json response, wraps it into model with [#error] and raises
# an exception where [ResponseError#response] contains the model instance
# response(400, 422) do |(status, *)|
# raise "#{status}: Record invalid"
# end
end end
operation :capture do operation :capture do
@@ -64,7 +41,7 @@ module YandexCheckout
path { "/#{payment_id}/capture" } path { "/#{payment_id}/capture" }
format 'json' format 'json'
headers 'Idempotence-Key' => '244afbdc-000f-5000-a000-12526186ce10' headers { { 'Idempotence-Key' => idempotency_key } }
response(200) { |*res| Entity::Payment.build(*res) } response(200) { |*res| Entity::Payment.build(*res) }
response(400) { |*res| Error.build(*res) } response(400) { |*res| Error.build(*res) }
@@ -79,7 +56,7 @@ module YandexCheckout
path { "/#{payment_id}/cancel" } path { "/#{payment_id}/cancel" }
format 'json' format 'json'
headers 'Idempotence-Key' => '244afbdc-000f-5000-a000-12526186ce10' headers { { 'Idempotence-Key' => idempotency_key } }
response(200) { |*res| Entity::Payment.build(*res) } response(200) { |*res| Entity::Payment.build(*res) }
response(400) { |*res| Error.build(*res) } response(400) { |*res| Error.build(*res) }

Просмотреть файл

@@ -3,14 +3,14 @@
RSpec.describe YandexCheckout::Payment do RSpec.describe YandexCheckout::Payment do
describe '#create' do describe '#create' do
let(:settings) { { shop_id: 'SHOP_ID', api_key: 'API_KEY' } } let(:settings) { { shop_id: 'SHOP_ID', api_key: 'API_KEY' } }
let(:idempotence_key) { 12_345 } let(:idempotency_key) { 12_345 }
let(:payment) { described_class.new(settings) } let(:payment) { described_class.new(settings) }
let(:params) { { payment: File.read('spec/fixtures/payment.json') } } let(:params) { { payment: File.read('spec/fixtures/payment.json') } }
let(:url) { 'https://payment.yandex.net/api/v3/payments' } let(:url) { 'https://payment.yandex.net/api/v3/payments' }
let(:body) { File.read('spec/fixtures/payment_response.json') } let(:body) { File.read('spec/fixtures/payment_response.json') }
before { stub_request(:any, //).to_return(body: body) } before { stub_request(:any, //).to_return(body: body) }
subject { payment.create(payment: params, idempotency_key: idempotence_key) } subject { payment.create(payment: params, idempotency_key: idempotency_key) }
it 'sends a request' do it 'sends a request' do
subject subject