зеркало из
https://github.com/glebtv/yookassa.git
synced 2026-08-28 15:16:18 +03:00
add Card, Amount, PaymentMethod entity
Этот коммит содержится в:
@@ -3,7 +3,12 @@
|
||||
require 'evil/client'
|
||||
require 'pry'
|
||||
|
||||
require_relative 'yandex-checkout/version'
|
||||
require_relative 'yandex-checkout/payment'
|
||||
require_relative 'yandex-checkout/refund'
|
||||
require_relative 'yandex-checkout/response'
|
||||
require 'yandex-checkout/version'
|
||||
require 'yandex-checkout/payment'
|
||||
require 'yandex-checkout/refund'
|
||||
require 'yandex-checkout/response'
|
||||
require 'yandex-checkout/callable'
|
||||
require 'yandex-checkout/optional'
|
||||
require 'yandex-checkout/entity/payment'
|
||||
# require 'yandex-checkout/entity/amount'
|
||||
# require 'yandex-checkout/entity/payment_method'
|
||||
|
||||
10
lib/yandex-checkout/callable.rb
Обычный файл
10
lib/yandex-checkout/callable.rb
Обычный файл
@@ -0,0 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module YandexCheckout
|
||||
module Callable
|
||||
def call(*args)
|
||||
new(*args)
|
||||
end
|
||||
alias [] call
|
||||
end
|
||||
end
|
||||
14
lib/yandex-checkout/entity/amount.rb
Обычный файл
14
lib/yandex-checkout/entity/amount.rb
Обычный файл
@@ -0,0 +1,14 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module YandexCheckout
|
||||
module Entity
|
||||
class Amount
|
||||
extend Dry::Initializer
|
||||
extend YandexCheckout::Callable
|
||||
include YandexCheckout::Optional
|
||||
|
||||
option :value, proc(&:to_f), optional: true
|
||||
option :currency, proc(&:to_s), optional: true
|
||||
end
|
||||
end
|
||||
end
|
||||
18
lib/yandex-checkout/entity/card.rb
Обычный файл
18
lib/yandex-checkout/entity/card.rb
Обычный файл
@@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module YandexCheckout
|
||||
module Entity
|
||||
class Card
|
||||
extend Dry::Initializer
|
||||
extend YandexCheckout::Callable
|
||||
include YandexCheckout::Optional
|
||||
|
||||
option :first6
|
||||
option :last4
|
||||
option :expiry_month
|
||||
option :expiry_year
|
||||
option :card_type, proc(&:to_s)
|
||||
option :source, proc(&:to_s), optional: true
|
||||
end
|
||||
end
|
||||
end
|
||||
19
lib/yandex-checkout/entity/payment.rb
Обычный файл
19
lib/yandex-checkout/entity/payment.rb
Обычный файл
@@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative './amount'
|
||||
require_relative './payment_method'
|
||||
|
||||
module YandexCheckout
|
||||
module Entity
|
||||
class Payment < YandexCheckout::Response
|
||||
option :paid
|
||||
option :amount, Entity::Amount
|
||||
option :created_at
|
||||
option :expires_at, optional: true
|
||||
option :description, proc(&:to_s), optional: true
|
||||
option :metadata
|
||||
option :payment_method, Entity::PaymentMethod
|
||||
option :test
|
||||
end
|
||||
end
|
||||
end
|
||||
19
lib/yandex-checkout/entity/payment_method.rb
Обычный файл
19
lib/yandex-checkout/entity/payment_method.rb
Обычный файл
@@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative './card'
|
||||
|
||||
module YandexCheckout
|
||||
module Entity
|
||||
class PaymentMethod
|
||||
extend Dry::Initializer
|
||||
extend YandexCheckout::Callable
|
||||
include YandexCheckout::Optional
|
||||
|
||||
option :type, proc(&:to_s)
|
||||
option :id, proc(&:to_s)
|
||||
option :saved
|
||||
option :card, Entity::Card, optional: true
|
||||
option :title, proc(&:to_s), optional: true
|
||||
end
|
||||
end
|
||||
end
|
||||
1
lib/yandex-checkout/entity/refund.rb
Обычный файл
1
lib/yandex-checkout/entity/refund.rb
Обычный файл
@@ -0,0 +1 @@
|
||||
# frozen_string_literal: true
|
||||
23
lib/yandex-checkout/optional.rb
Обычный файл
23
lib/yandex-checkout/optional.rb
Обычный файл
@@ -0,0 +1,23 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module YandexCheckout
|
||||
module Optional
|
||||
private
|
||||
|
||||
def initialize(opts)
|
||||
super opts.each_with_object({}) { |(key, val), obj| obj[key.to_sym] = val }
|
||||
end
|
||||
|
||||
def __options__
|
||||
@__options__ ||= self.class.dry_initializer.attributes(self)
|
||||
end
|
||||
|
||||
def respond_to_missing?(name, *)
|
||||
__options__.respond_to? name
|
||||
end
|
||||
|
||||
def method_missing(*args, &block)
|
||||
respond_to_missing?(*args) ? __options__.send(*args, &block) : super
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -8,41 +8,13 @@ module YandexCheckout
|
||||
path { 'https://payment.yandex.net/api/v3' }
|
||||
security { basic_auth shop_id, api_key }
|
||||
|
||||
# http_method { :get }
|
||||
# scope :payments do
|
||||
# operation :status 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 :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) }
|
||||
response(200) { |*res| Entity::Payment.build(*res) }
|
||||
|
||||
# Parses json response, wraps it into model with [#error] and raises
|
||||
# an exception where [ResponseError#response] contains the model instance
|
||||
|
||||
@@ -10,7 +10,6 @@ module YandexCheckout
|
||||
class << self
|
||||
def build(*res)
|
||||
body = res.last
|
||||
binding.pry
|
||||
new JSON.parse(body.first)
|
||||
end
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user