diff --git a/lib/yandex-checkout/payment.rb b/lib/yandex-checkout/payment.rb index 14908c8..c5a31f1 100644 --- a/lib/yandex-checkout/payment.rb +++ b/lib/yandex-checkout/payment.rb @@ -15,44 +15,21 @@ module YandexCheckout path { "/#{payment_id}" } response(200) { |*res| Entity::Payment.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 operation :create do option :payment - option :idempotency_key, optional: true + option :idempotency_key, proc(&:to_s) http_method :post - # path { 'payments' } - # query { { params: params } } format 'json' - headers 'Idempotence-Key' => '244afbdc-000f-5000-a000-12526186ce10' + headers { { 'Idempotence-Key' => idempotency_key } } body { payment } - # response 200 do |_status, _headers, body| - # p JSON.parse(*body) - # end response(200) { |*res| Entity::Payment.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 operation :capture do @@ -64,7 +41,7 @@ module YandexCheckout path { "/#{payment_id}/capture" } format 'json' - headers 'Idempotence-Key' => '244afbdc-000f-5000-a000-12526186ce10' + headers { { 'Idempotence-Key' => idempotency_key } } response(200) { |*res| Entity::Payment.build(*res) } response(400) { |*res| Error.build(*res) } @@ -79,7 +56,7 @@ module YandexCheckout path { "/#{payment_id}/cancel" } format 'json' - headers 'Idempotence-Key' => '244afbdc-000f-5000-a000-12526186ce10' + headers { { 'Idempotence-Key' => idempotency_key } } response(200) { |*res| Entity::Payment.build(*res) } response(400) { |*res| Error.build(*res) } diff --git a/spec/yandex-checkout/payment_spec.rb b/spec/yandex-checkout/payment_spec.rb index 71e7872..acc6329 100644 --- a/spec/yandex-checkout/payment_spec.rb +++ b/spec/yandex-checkout/payment_spec.rb @@ -3,14 +3,14 @@ RSpec.describe YandexCheckout::Payment do describe '#create' do 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(:params) { { payment: File.read('spec/fixtures/payment.json') } } let(:url) { 'https://payment.yandex.net/api/v3/payments' } let(:body) { File.read('spec/fixtures/payment_response.json') } 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 subject