Class: Afterpay::Payment

Inherits:
Object
  • Object
show all
Defined in:
lib/afterpay/payment.rb

Overview

They Payment object

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Payment

Initialize Payment from response



25
26
27
28
29
30
31
32
# File 'lib/afterpay/payment.rb', line 25

def initialize(attributes)
  @id = attributes[:id]
  @status = attributes[:status]
  @created = attributes[:created]
  @total = Utils::Money.from_response(attributes[:total])
  @order = Order.from_response(attributes[:orderDetails])
  @error = Error.new(attributes) if attributes[:errorId]
end

Instance Attribute Details

#createdObject

Returns the value of attribute created.



22
23
24
# File 'lib/afterpay/payment.rb', line 22

def created
  @created
end

#errorObject

Returns the value of attribute error.



22
23
24
# File 'lib/afterpay/payment.rb', line 22

def error
  @error
end

#idObject

Returns the value of attribute id.



22
23
24
# File 'lib/afterpay/payment.rb', line 22

def id
  @id
end

#orderObject

Returns the value of attribute order.



22
23
24
# File 'lib/afterpay/payment.rb', line 22

def order
  @order
end

#statusObject

Returns the value of attribute status.



22
23
24
# File 'lib/afterpay/payment.rb', line 22

def status
  @status
end

#totalObject

Returns the value of attribute total.



22
23
24
# File 'lib/afterpay/payment.rb', line 22

def total
  @total
end

Class Method Details

.execute(token:, reference:) ⇒ Payment

Executes the Payment

Parameters:

  • token (String)

    the Order token

  • reference (String)

    the reference for payment

Returns:



11
12
13
14
15
16
17
18
19
20
# File 'lib/afterpay/payment.rb', line 11

def self.execute(token:, reference:)
  request = Afterpay.client.post("/v1/payments/capture") do |req|
    req.body = {
      token: token,
      merchantRefernce: reference
    }
  end

  new(request.body)
end

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/afterpay/payment.rb', line 34

def success?
  @status == "APPROVED"
end