1
0
зеркало из https://github.com/glebtv/yookassa.git synced 2026-09-03 17:55:51 +03:00
Этот коммит содержится в:
Andrey Paderin
2019-06-11 01:05:39 +03:00
родитель 92a3362729
Коммит aa28e7bc57
5 изменённых файлов: 94 добавлений и 19 удалений

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

@@ -10,5 +10,6 @@ require 'yandex-checkout/response'
require 'yandex-checkout/callable' require 'yandex-checkout/callable'
require 'yandex-checkout/optional' require 'yandex-checkout/optional'
require 'yandex-checkout/entity/payment' require 'yandex-checkout/entity/payment'
require 'yandex-checkout/error'
# require 'yandex-checkout/entity/amount' # require 'yandex-checkout/entity/amount'
# require 'yandex-checkout/entity/payment_method' # require 'yandex-checkout/entity/payment_method'

16
lib/yandex-checkout/entity/confirmation.rb Обычный файл
Просмотреть файл

@@ -0,0 +1,16 @@
# frozen_string_literal: true
module YandexCheckout
module Entity
class Confirmation
extend Dry::Initializer
extend YandexCheckout::Callable
include YandexCheckout::Optional
option :type, proc(&:to_s), optional: true
option :confirmation_url, proc(&:to_s), optional: true
option :enforce, optional: true
option :return_url, proc(&:to_s), optional: true
end
end
end

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

@@ -2,6 +2,7 @@
require_relative './amount' require_relative './amount'
require_relative './payment_method' require_relative './payment_method'
require_relative './confirmation'
module YandexCheckout module YandexCheckout
module Entity module Entity
@@ -9,10 +10,12 @@ module YandexCheckout
option :paid option :paid
option :amount, Entity::Amount option :amount, Entity::Amount
option :created_at option :created_at
option :captured_at, proc(&:to_s), optional: true
option :expires_at, optional: true option :expires_at, optional: true
option :description, proc(&:to_s), optional: true option :description, proc(&:to_s), optional: true
option :metadata option :metadata, optional: true
option :payment_method, Entity::PaymentMethod option :payment_method, Entity::PaymentMethod
option :confirmation, Entity::Confirmation, optional: true
option :test option :test
end end
end end

30
lib/yandex-checkout/error.rb Обычный файл
Просмотреть файл

@@ -0,0 +1,30 @@
# frozen_string_literal: true
module YandexCheckout
class Error
extend Dry::Initializer
extend YandexCheckout::Callable
include YandexCheckout::Optional
option :type, proc(&:to_s)
option :id, proc(&:to_s), optional: true
option :code, proc(&:to_s), optional: true
option :description, proc(&:to_s), optional: true
option :parameter, proc(&:to_s), optional: true
def error?
type == 'error'
end
class << self
def build(*res)
body = res.last
new JSON.parse(body.first)
end
def new(opts)
super opts.each_with_object({}) { |(key, val), obj| obj[key.to_sym] = val }
end
end
end
end

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

@@ -5,28 +5,29 @@ module YandexCheckout
option :shop_id, proc(&:to_s) option :shop_id, proc(&:to_s)
option :api_key, proc(&:to_s) option :api_key, proc(&:to_s)
path { 'https://payment.yandex.net/api/v3' } path { 'https://payment.yandex.net/api/v3/payments' }
security { basic_auth shop_id, api_key } security { basic_auth shop_id, api_key }
operation :get_payment_info do operation :get_payment_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) { |*res| Entity::Payment.build(*res) } 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 # Parses json response, wraps it into model with [#error] and raises
# an exception where [ResponseError#response] contains the model instance # an exception where [ResponseError#response] contains the model instance
response(400, 422) do |(status, *)| # response(400, 422) do |(status, *)|
raise "#{status}: Record invalid" # raise "#{status}: Record invalid"
end # end
response(404) do |(_status, *)| # response(404) do |(_status, *)|
p 'Record Not Found' # p 'Record Not Found'
# raise "#{status}: Record not found" # # raise "#{status}: Record not found"
end # end
end end
operation :create do operation :create do
@@ -35,29 +36,53 @@ module YandexCheckout
http_method :post http_method :post
path { 'payments' } # path { 'payments' }
# query { { params: params } } # query { { params: params } }
format 'json' format 'json'
headers 'Idempotence-Key' => '244afbdc-000f-5000-a000-12526186ce10' headers 'Idempotence-Key' => '244afbdc-000f-5000-a000-12526186ce10'
body { payment } body { payment }
response 200 do |_status, _headers, body| # response 200 do |_status, _headers, body|
p JSON.parse(*body) # p JSON.parse(*body)
end # 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 # Parses json response, wraps it into model with [#error] and raises
# an exception where [ResponseError#response] contains the model instance # an exception where [ResponseError#response] contains the model instance
response(400, 422) do |(status, *)| # response(400, 422) do |(status, *)|
raise "#{status}: Record invalid" # raise "#{status}: Record invalid"
end # end
end end
operation :capture do operation :capture do
option :payment_id, proc(&:to_s)
option :idempotency_key, optional: true
http_method :post
path { "/#{payment_id}/capture" }
format 'json'
headers 'Idempotence-Key' => '244afbdc-000f-5000-a000-12526186ce10'
response(200) { |*res| Entity::Payment.build(*res) }
response(400) { |*res| Error.build(*res) }
end end
operation :cancel do operation :cancel do
option :payment_id, proc(&:to_s)
option :idempotency_key, optional: true
http_method :post
path { "/#{payment_id}/cancel" }
format 'json'
headers 'Idempotence-Key' => '244afbdc-000f-5000-a000-12526186ce10'
response(200) { |*res| Entity::Payment.build(*res) }
response(400) { |*res| Error.build(*res) }
end end
# end
end end
end end