Class: Mpp::Receipt

Inherits:
Data
  • Object
show all
Defined in:
lib/mpp/receipt.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, timestamp:, reference:, method: "", external_id: nil, extra: nil) ⇒ Receipt

Returns a new instance of Receipt.



6
7
8
# File 'lib/mpp/receipt.rb', line 6

def initialize(status:, timestamp:, reference:, method: "", external_id: nil, extra: nil)
  super
end

Instance Attribute Details

#external_idObject (readonly)

Returns the value of attribute external_id

Returns:

  • (Object)

    the current value of external_id



5
6
7
# File 'lib/mpp/receipt.rb', line 5

def external_id
  @external_id
end

#extraObject (readonly)

Returns the value of attribute extra

Returns:

  • (Object)

    the current value of extra



5
6
7
# File 'lib/mpp/receipt.rb', line 5

def extra
  @extra
end

#methodObject (readonly)

Returns the value of attribute method

Returns:

  • (Object)

    the current value of method



5
6
7
# File 'lib/mpp/receipt.rb', line 5

def method
  @method
end

#referenceObject (readonly)

Returns the value of attribute reference

Returns:

  • (Object)

    the current value of reference



5
6
7
# File 'lib/mpp/receipt.rb', line 5

def reference
  @reference
end

#statusObject (readonly)

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



5
6
7
# File 'lib/mpp/receipt.rb', line 5

def status
  @status
end

#timestampObject (readonly)

Returns the value of attribute timestamp

Returns:

  • (Object)

    the current value of timestamp



5
6
7
# File 'lib/mpp/receipt.rb', line 5

def timestamp
  @timestamp
end

Class Method Details

.from_payment_receipt(header) ⇒ Object

Parse a Receipt from a Payment-Receipt header value.



11
12
13
# File 'lib/mpp/receipt.rb', line 11

def self.from_payment_receipt(header)
  Mpp::Parsing.parse_payment_receipt(header)
end

.success(reference, timestamp: nil, method: "tempo", external_id: nil) ⇒ Object

Create a success receipt with current timestamp.



21
22
23
24
25
26
27
28
29
# File 'lib/mpp/receipt.rb', line 21

def self.success(reference, timestamp: nil, method: "tempo", external_id: nil)
  new(
    status: "success",
    timestamp: timestamp || Time.now.utc,
    reference: reference,
    method: method,
    external_id: external_id
  )
end

Instance Method Details

#to_payment_receiptObject

Serialize to a Payment-Receipt header value.



16
17
18
# File 'lib/mpp/receipt.rb', line 16

def to_payment_receipt
  Mpp::Parsing.format_payment_receipt(self)
end