Class: Monri::Payments

Inherits:
Object
  • Object
show all
Defined in:
lib/monri/payments.rb,
lib/monri/payments/payment_result.rb,
lib/monri/payments/create_response.rb,
lib/monri/payments/status_response.rb

Defined Under Namespace

Classes: CreateResponse, PaymentResult, StatusResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#access_tokens=(value) ⇒ Monri::AccessTokens (writeonly)

Returns:



11
12
13
# File 'lib/monri/payments.rb', line 11

def access_tokens=(value)
  @access_tokens = value
end

#configMonri::Config

Returns:



6
7
8
# File 'lib/monri/payments.rb', line 6

def config
  @config
end

#http_client=(value) ⇒ Monri::HttpClient (writeonly)

Returns:



8
9
10
# File 'lib/monri/payments.rb', line 8

def http_client=(value)
  @http_client = value
end

Instance Method Details

#create(options) ⇒ Monri::Payments::CreateResponse

Parameters:

  • options (Hash)

Returns:



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/monri/payments.rb', line 15

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

#status(id) ⇒ StatusResponse

Returns id.

Parameters:

  • id (String)

Returns:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/monri/payments.rb', line 31

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