зеркало из
https://github.com/glebtv/yookassa.git
synced 2026-08-28 15:16:18 +03:00
add payment
Этот коммит содержится в:
@@ -1,7 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'evil/client'
|
||||
require 'pry'
|
||||
|
||||
require 'yandex-checkout/version'
|
||||
require 'yandex-checkout/payment'
|
||||
require 'yandex-checkout/refund'
|
||||
require_relative 'yandex-checkout/version'
|
||||
require_relative 'yandex-checkout/payment'
|
||||
require_relative 'yandex-checkout/refund'
|
||||
require_relative 'yandex-checkout/response'
|
||||
|
||||
@@ -9,53 +9,83 @@ module YandexCheckout
|
||||
security { basic_auth shop_id, api_key }
|
||||
|
||||
# http_method { :get }
|
||||
scope :payments do
|
||||
operation :status do
|
||||
option :payment_id, proc(&:to_s)
|
||||
# scope :payments do
|
||||
# operation :status do
|
||||
# option :payment_id, proc(&:to_s)
|
||||
|
||||
http_method :get
|
||||
path { "payments/#{payment_id}" }
|
||||
# http_method :get
|
||||
# path { "payments/#{payment_id}" }
|
||||
|
||||
response 200 do |_status, _headers, body|
|
||||
p JSON.parse(*body)
|
||||
end
|
||||
# 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
|
||||
# # 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(400, 422) do |(status, *)|
|
||||
# raise "#{status}: Record invalid"
|
||||
# end
|
||||
|
||||
response(404) do |(_status, *)|
|
||||
p 'Record Not Found'
|
||||
# raise "#{status}: Record not found"
|
||||
end
|
||||
# response(404) do |(_status, *)|
|
||||
# p 'Record Not Found'
|
||||
# # raise "#{status}: Record not found"
|
||||
# end
|
||||
# end
|
||||
|
||||
operation :get_payment_info do
|
||||
option :payment_id, proc(&:to_s)
|
||||
|
||||
http_method :get
|
||||
path { "payments/#{payment_id}" }
|
||||
|
||||
# response 200 do |_status, _headers, body|
|
||||
# p JSON.parse(*body)
|
||||
# end
|
||||
response(200) { |*res| p Response.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
|
||||
|
||||
operation :create do
|
||||
option :payment
|
||||
option :idempotency_key, optional: true
|
||||
|
||||
http_method :post
|
||||
|
||||
path { 'payments' }
|
||||
# query { { params: params } }
|
||||
format 'json'
|
||||
headers 'Idempotence-Key' => '244afbdc-000f-5000-a000-12526186ce10'
|
||||
body { payment }
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
operation :create do
|
||||
option :payment
|
||||
option :idempotency_key, optional: true
|
||||
|
||||
http_method :post
|
||||
|
||||
path { 'payments' }
|
||||
# query { { params: params } }
|
||||
format 'json'
|
||||
headers 'Idempotence-Key' => '244afbdc-000f-5000-a000-12526186ce10'
|
||||
body { payment }
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
operation :capture do
|
||||
end
|
||||
|
||||
operation :cancel do
|
||||
end
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,6 +2,52 @@
|
||||
|
||||
module YandexCheckout
|
||||
class Refund < Evil::Client
|
||||
operation :get_refund_info do
|
||||
option :payment_id, proc(&:to_s)
|
||||
|
||||
http_method :get
|
||||
path { "payments/#{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
|
||||
end
|
||||
|
||||
|
||||
operation :create do
|
||||
option :payment
|
||||
option :idempotency_key, optional: true
|
||||
|
||||
http_method :post
|
||||
|
||||
path { 'payments' }
|
||||
# query { { params: params } }
|
||||
format 'json'
|
||||
headers 'Idempotence-Key' => '244afbdc-000f-5000-a000-12526186ce10'
|
||||
body { payment }
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
22
lib/yandex-checkout/response.rb
Обычный файл
22
lib/yandex-checkout/response.rb
Обычный файл
@@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module YandexCheckout
|
||||
class Response
|
||||
extend Dry::Initializer
|
||||
option :id, proc(&:to_s)
|
||||
option :status, proc(&:to_s), default: proc { nil }
|
||||
option :test
|
||||
|
||||
class << self
|
||||
def build(*res)
|
||||
body = res.last
|
||||
binding.pry
|
||||
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
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module YandexCheckout
|
||||
VERSION = '0.1.0'
|
||||
end
|
||||
|
||||
Ссылка в новой задаче
Block a user