diff --git a/lib/yandex-checkout.rb b/lib/yandex-checkout.rb index bcb80f6..56063e0 100644 --- a/lib/yandex-checkout.rb +++ b/lib/yandex-checkout.rb @@ -1,6 +1,7 @@ -require 'yandex-checkout/version' +# frozen_string_literal: true -module YandexCheckout - class Error < StandardError; end - # Your code goes here... -end +require 'evil/client' + +require 'yandex-checkout/version' +require 'yandex-checkout/payment' +require 'yandex-checkout/refund' diff --git a/lib/yandex-checkout/payment.rb b/lib/yandex-checkout/payment.rb new file mode 100644 index 0000000..4818247 --- /dev/null +++ b/lib/yandex-checkout/payment.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +module YandexCheckout + class Payment < Evil::Client + option :shop_id, proc(&:to_s) + option :api_key, proc(&:to_s) + + 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 :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 +end diff --git a/lib/yandex-checkout/refund.rb b/lib/yandex-checkout/refund.rb new file mode 100644 index 0000000..0487845 --- /dev/null +++ b/lib/yandex-checkout/refund.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module YandexCheckout + class Refund < Evil::Client + + end +end