Sha256: 46be36c1657dcc76424d934e92e432fdddc7cd99b8946da31a2503a0d04500fc

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module Monri
  class Payments
    # @return [Monri::Config]
    attr_accessor :config
    # @return [Monri::HttpClient]
    attr_writer :http_client

    # @return [Monri::AccessTokens]
    attr_writer :access_tokens

    # @param [Hash] options
    # @return [Monri::Payments::CreateResponse]
    def create(options)
      CreateResponse.create do
        access_token = @access_tokens.create!(scopes: ['payments']).access_token
        response = @http_client.post('/v2/payment/new', options, oauth: access_token)
        if response.failed?
          raise response.exception
        elsif response.success?
          response.body
        else
          nil
        end
      end
    end

    # @param [String] id
    # @return [StatusResponse] id
    def status(id)
      StatusResponse.create do
        if id.nil? || !id.is_a?(String)
          raise ArgumentError('Id should be a string')
        end

        access_token = @access_tokens.create!(scopes: ['payments']).access_token
        response = @http_client.get("/v2/payment/#{id}/status", oauth: access_token)
        if response.failed?
          raise response.exception
        elsif response.success?
          response.body
        else
          # TODO: handle this case
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
monri-0.3.0 lib/monri/payments.rb
monri-0.2.0 lib/monri/payments.rb