Class: Monza::TransactionReceipt

Inherits:
Object
  • Object
show all
Defined in:
lib/monza/transaction_receipt.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ TransactionReceipt

Returns a new instance of TransactionReceipt.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/monza/transaction_receipt.rb', line 34

def initialize(attributes)
  @original_attributes = attributes
  @quantity = attributes['quantity'].to_i
  @product_id = attributes['product_id']
  @transaction_id = attributes['transaction_id']
  @original_transaction_id = attributes['original_transaction_id']
  @purchase_date = DateTime.parse(attributes['purchase_date']) if attributes['purchase_date']
  @purchase_date_ms = Time.zone.at(attributes['purchase_date_ms'].to_i / 1000)
  @purchase_date_pst = DateTime.parse(attributes['purchase_date_pst'].gsub("America/Los_Angeles","PST")) if attributes['purchase_date_pst']
  @original_purchase_date = DateTime.parse(attributes['original_purchase_date']) if attributes['original_purchase_date']
  @original_purchase_date_ms = Time.zone.at(attributes['original_purchase_date_ms'].to_i / 1000)
  @original_purchase_date_pst = DateTime.parse(attributes['original_purchase_date_pst'].gsub("America/Los_Angeles","PST")) if attributes['original_purchase_date_pst']
  @web_order_line_item_id = attributes['web_order_line_item_id']
  @cancellation_reason = attributes['cancellation_reason'] if attributes['cancellation_reason']
  @cancellation_date = DateTime.parse(attributes['cancellation_date']) if attributes['cancellation_date']
  @cancellation_date_ms = Time.zone.at(attributes['cancellation_date_ms'].to_i / 1000) if attributes['cancellation_date_ms']
  @cancellation_date_pst = DateTime.parse(attributes['cancellation_date_pst'].gsub("America/Los_Angeles","PST")) if attributes['cancellation_date_pst']

  if attributes['expires_date']
    begin
      # Attempt to parse as RFC 3339 timestamp (new-style receipt)
      @expires_date = DateTime.parse(attributes['expires_date'])
    rescue
      # Attempt to parse as integer ms epoch (old-style receipt)
      @expires_date = Time.at(attributes['expires_date'].to_i / 1000).to_datetime
    end
  end
  if attributes['expires_date_ms']
    @expires_date_ms = Time.zone.at(attributes['expires_date_ms'].to_i / 1000)
  elsif attributes['expires_date']
    @expires_date_ms = Time.zone.at(attributes['expires_date'].to_i / 1000)
  end
  if attributes['expires_date_pst']
    @expires_date_pst = DateTime.parse(attributes['expires_date_pst'].gsub("America/Los_Angeles","PST"))
  end
  if attributes['is_trial_period']
    @is_trial_period = attributes['is_trial_period'].to_bool
  end
  if attributes['is_in_intro_offer_period']
    @is_in_intro_offer_period = attributes['is_in_intro_offer_period'].to_bool
  end
end

Instance Attribute Details

#cancellation_dateObject (readonly)

Returns the value of attribute cancellation_date.



28
29
30
# File 'lib/monza/transaction_receipt.rb', line 28

def cancellation_date
  @cancellation_date
end

#cancellation_date_msObject (readonly)

Returns the value of attribute cancellation_date_ms.



29
30
31
# File 'lib/monza/transaction_receipt.rb', line 29

def cancellation_date_ms
  @cancellation_date_ms
end

#cancellation_date_pstObject (readonly)

Returns the value of attribute cancellation_date_pst.



30
31
32
# File 'lib/monza/transaction_receipt.rb', line 30

def cancellation_date_pst
  @cancellation_date_pst
end

#cancellation_reasonObject (readonly)

Returns the value of attribute cancellation_reason.



27
28
29
# File 'lib/monza/transaction_receipt.rb', line 27

def cancellation_reason
  @cancellation_reason
end

#expires_dateObject (readonly)

Returns the value of attribute expires_date.



23
24
25
# File 'lib/monza/transaction_receipt.rb', line 23

def expires_date
  @expires_date
end

#expires_date_msObject (readonly)

Returns the value of attribute expires_date_ms.



24
25
26
# File 'lib/monza/transaction_receipt.rb', line 24

def expires_date_ms
  @expires_date_ms
end

#expires_date_pstObject (readonly)

Returns the value of attribute expires_date_pst.



25
26
27
# File 'lib/monza/transaction_receipt.rb', line 25

def expires_date_pst
  @expires_date_pst
end

#is_in_intro_offer_periodObject (readonly)

Returns the value of attribute is_in_intro_offer_period.



31
32
33
# File 'lib/monza/transaction_receipt.rb', line 31

def is_in_intro_offer_period
  @is_in_intro_offer_period
end

#is_trial_periodObject (readonly)

Returns the value of attribute is_trial_period.



26
27
28
# File 'lib/monza/transaction_receipt.rb', line 26

def is_trial_period
  @is_trial_period
end

#original_attributesObject (readonly)

Returns the value of attribute original_attributes.



32
33
34
# File 'lib/monza/transaction_receipt.rb', line 32

def original_attributes
  @original_attributes
end

#original_purchase_dateObject (readonly)

Returns the value of attribute original_purchase_date.



18
19
20
# File 'lib/monza/transaction_receipt.rb', line 18

def original_purchase_date
  @original_purchase_date
end

#original_purchase_date_msObject (readonly)

Returns the value of attribute original_purchase_date_ms.



19
20
21
# File 'lib/monza/transaction_receipt.rb', line 19

def original_purchase_date_ms
  @original_purchase_date_ms
end

#original_purchase_date_pstObject (readonly)

Returns the value of attribute original_purchase_date_pst.



20
21
22
# File 'lib/monza/transaction_receipt.rb', line 20

def original_purchase_date_pst
  @original_purchase_date_pst
end

#original_transaction_idObject (readonly)

Returns the value of attribute original_transaction_id.



14
15
16
# File 'lib/monza/transaction_receipt.rb', line 14

def original_transaction_id
  @original_transaction_id
end

#product_idObject (readonly)

Returns the value of attribute product_id.



12
13
14
# File 'lib/monza/transaction_receipt.rb', line 12

def product_id
  @product_id
end

#purchase_dateObject (readonly)

Returns the value of attribute purchase_date.



15
16
17
# File 'lib/monza/transaction_receipt.rb', line 15

def purchase_date
  @purchase_date
end

#purchase_date_msObject (readonly)

Returns the value of attribute purchase_date_ms.



16
17
18
# File 'lib/monza/transaction_receipt.rb', line 16

def purchase_date_ms
  @purchase_date_ms
end

#purchase_date_pstObject (readonly)

Returns the value of attribute purchase_date_pst.



17
18
19
# File 'lib/monza/transaction_receipt.rb', line 17

def purchase_date_pst
  @purchase_date_pst
end

#quantityObject (readonly)



11
12
13
# File 'lib/monza/transaction_receipt.rb', line 11

def quantity
  @quantity
end

#transaction_idObject (readonly)

Returns the value of attribute transaction_id.



13
14
15
# File 'lib/monza/transaction_receipt.rb', line 13

def transaction_id
  @transaction_id
end

#web_order_line_item_idObject (readonly)

Returns the value of attribute web_order_line_item_id.



21
22
23
# File 'lib/monza/transaction_receipt.rb', line 21

def web_order_line_item_id
  @web_order_line_item_id
end