Class: Yookassa::Payments

Inherits:
Object
  • Object
show all
Defined in:
lib/yookassa/payments.rb

Instance Method Summary collapse

Constructor Details

#initialize(api) ⇒ Payments

Returns a new instance of Payments.



7
8
9
# File 'lib/yookassa/payments.rb', line 7

def initialize(api)
  @api = api
end

Instance Method Details

#cancel(payment_id:, idempotency_key: SecureRandom.hex(10)) ⇒ Object



26
27
28
29
# File 'lib/yookassa/payments.rb', line 26

def cancel(payment_id:, idempotency_key: SecureRandom.hex(10))
  data = api.post("payments/#{payment_id}/cancel", idempotency_key: idempotency_key)
  Entity::Payment.new(**data.merge(idempotency_key: idempotency_key))
end

#capture(payment_id:, idempotency_key: SecureRandom.hex(10)) ⇒ Object



21
22
23
24
# File 'lib/yookassa/payments.rb', line 21

def capture(payment_id:, idempotency_key: SecureRandom.hex(10))
  data = api.post("payments/#{payment_id}/capture", idempotency_key: idempotency_key)
  Entity::Payment.new(**data.merge(idempotency_key: idempotency_key))
end

#create(payment:, idempotency_key: SecureRandom.hex(10)) ⇒ Object



16
17
18
19
# File 'lib/yookassa/payments.rb', line 16

def create(payment:, idempotency_key: SecureRandom.hex(10))
  data = api.post("payments", payload: payment, idempotency_key: idempotency_key)
  Entity::Payment.new(**data.merge(idempotency_key: idempotency_key))
end

#find(payment_id:) ⇒ Object



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

def find(payment_id:)
  data = api.get("payments/#{payment_id}")
  Entity::Payment.new(**data)
end