diff --git a/lib/yandex-checkout/entity/refund.rb b/lib/yandex-checkout/entity/refund.rb index 8e9b8f9..b5826dc 100644 --- a/lib/yandex-checkout/entity/refund.rb +++ b/lib/yandex-checkout/entity/refund.rb @@ -1 +1,15 @@ # frozen_string_literal: true + +require_relative './amount' + +module YandexCheckout + module Entity + class Refund < YandexCheckout::Response + option :payment_id + option :created_at, proc(&:to_s) + option :amount, Entity::Amount + option :receipt_registration, proc(&:to_s), optional: true + option :description, proc(&:to_s), optional: true + end + end +end diff --git a/lib/yandex-checkout/refund.rb b/lib/yandex-checkout/refund.rb index d249732..dd8b605 100644 --- a/lib/yandex-checkout/refund.rb +++ b/lib/yandex-checkout/refund.rb @@ -2,52 +2,34 @@ module YandexCheckout class Refund < Evil::Client + option :shop_id, proc(&:to_s) + option :api_key, proc(&:to_s) + + path { 'https://payment.yandex.net/api/v3/refunds' } + security { basic_auth shop_id, api_key } + operation :get_refund_info do option :payment_id, proc(&:to_s) http_method :get - path { "payments/#{payment_id}" } + path { "/#{payment_id}" } - response 200 do |_status, _headers, body| - p JSON.parse(*body) - end - - # 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 + response(200) { |*res| Entity::Refund.build(*res) } + response(400, 404) { |*res| Error.build(*res) } end - operation :create do - option :payment - option :idempotency_key, optional: true + option :payload + option :idempotency_key, proc(&:to_s) http_method :post - path { 'payments' } - # query { { params: params } } format 'json' - headers 'Idempotence-Key' => '244afbdc-000f-5000-a000-12526186ce10' - body { payment } + headers { { 'Idempotence-Key' => idempotency_key } } + body { payload } - response 200 do |_status, _headers, body| - p JSON.parse(*body) - end - - # 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(200) { |*res| Entity::Refund.build(*res) } + response(400, 404) { |*res| Error.build(*res) } end end end diff --git a/lib/yandex-checkout/response.rb b/lib/yandex-checkout/response.rb index 85c4134..c5d267d 100644 --- a/lib/yandex-checkout/response.rb +++ b/lib/yandex-checkout/response.rb @@ -5,7 +5,6 @@ module YandexCheckout extend Dry::Initializer option :id, proc(&:to_s) option :status, proc(&:to_s), default: proc { nil } - option :test class << self def build(*res)