Sha256: 92bf9699c2330d7f4a97b737d383ea4951d3745f9576b2d637ec38ed89b8987e

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

module Yookassa
  class Payment < Evil::Client
    option :shop_id,  proc(&:to_s)
    option :api_key,  proc(&:to_s)

    path { 'https://api.yookassa.ru/v3/payments' }
    security { basic_auth shop_id, api_key }

    operation :get_payment_info do
      option :payment_id, proc(&:to_s)

      http_method :get
      path { "/#{payment_id}" }

      response(200) { |*res| Entity::Payment.build(*res) }
      response(400, 404) { |*res| Error.build(*res) }
    end

    operation :create do
      option :payment
      option :idempotency_key, proc(&:to_s)

      http_method :post

      format 'json'
      headers { { 'Idempotence-Key' => idempotency_key } }
      body { payment }

      response(200) { |*res| Entity::Payment.build(*res) }
      response(400) { |*res| Error.build(*res) }
    end

    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' => idempotency_key } }

      response(200) { |*res| Entity::Payment.build(*res) }
      response(400) { |*res| Error.build(*res) }
    end

    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' => idempotency_key } }

      response(200) { |*res| Entity::Payment.build(*res) }
      response(400) { |*res| Error.build(*res) }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
yookassa-0.1.0 lib/yookassa/payment.rb