Class: Payhub::Client::Payments

Inherits:
Object
  • Object
show all
Defined in:
lib/payhub/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Payments

Returns a new instance of Payments.



132
133
134
# File 'lib/payhub/client.rb', line 132

def initialize(client)
  @c = client
end

Instance Method Details

#confirm_otp(payment_id, code, idempotency_key: nil) ⇒ Object



142
143
144
145
146
147
# File 'lib/payhub/client.rb', line 142

def confirm_otp(payment_id, code, idempotency_key: nil)
  key = idempotency_key || SecureRandom.uuid
  raw = @c.request(:post, "/v1/payments/#{payment_id}/otp",
    body: {code: code}, idempotency_key: key)
  Payment.from_raw(raw)
end

#create(request, idempotency_key: nil) ⇒ Object



136
137
138
139
140
# File 'lib/payhub/client.rb', line 136

def create(request, idempotency_key: nil)
  key = idempotency_key || SecureRandom.uuid
  raw = @c.request(:post, "/v1/payments", body: request, idempotency_key: key)
  Payment.from_raw(raw)
end

#refund(payment_id, amount_minor: nil, reason: nil, idempotency_key: nil) ⇒ Object



149
150
151
152
153
154
155
156
157
# File 'lib/payhub/client.rb', line 149

def refund(payment_id, amount_minor: nil, reason: nil, idempotency_key: nil)
  body = {}
  body[:amount_minor] = amount_minor unless amount_minor.nil?
  body[:reason] = reason unless reason.nil?
  key = idempotency_key || SecureRandom.uuid
  raw = @c.request(:post, "/v1/payments/#{payment_id}/refund",
    body: body, idempotency_key: key)
  Payment.from_raw(raw)
end

#retrieve(payment_id) ⇒ Object



159
160
161
# File 'lib/payhub/client.rb', line 159

def retrieve(payment_id)
  Payment.from_raw(@c.request(:get, "/v1/payments/#{payment_id}"))
end