зеркало из
https://github.com/glebtv/yookassa.git
synced 2026-09-07 11:25:51 +03:00
add refund
Этот коммит содержится в:
@@ -1 +1,15 @@
|
|||||||
# frozen_string_literal: true
|
# 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
|
||||||
|
|||||||
@@ -2,52 +2,34 @@
|
|||||||
|
|
||||||
module YandexCheckout
|
module YandexCheckout
|
||||||
class Refund < Evil::Client
|
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
|
operation :get_refund_info do
|
||||||
option :payment_id, proc(&:to_s)
|
option :payment_id, proc(&:to_s)
|
||||||
|
|
||||||
http_method :get
|
http_method :get
|
||||||
path { "payments/#{payment_id}" }
|
path { "/#{payment_id}" }
|
||||||
|
|
||||||
response 200 do |_status, _headers, body|
|
response(200) { |*res| Entity::Refund.build(*res) }
|
||||||
p JSON.parse(*body)
|
response(400, 404) { |*res| Error.build(*res) }
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
operation :create do
|
operation :create do
|
||||||
option :payment
|
option :payload
|
||||||
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 { payload }
|
||||||
|
|
||||||
response 200 do |_status, _headers, body|
|
response(200) { |*res| Entity::Refund.build(*res) }
|
||||||
p JSON.parse(*body)
|
response(400, 404) { |*res| Error.build(*res) }
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ module YandexCheckout
|
|||||||
extend Dry::Initializer
|
extend Dry::Initializer
|
||||||
option :id, proc(&:to_s)
|
option :id, proc(&:to_s)
|
||||||
option :status, proc(&:to_s), default: proc { nil }
|
option :status, proc(&:to_s), default: proc { nil }
|
||||||
option :test
|
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def build(*res)
|
def build(*res)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user