Class: Monza::Receipt

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Receipt

Returns a new instance of Receipt.



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
# File 'lib/monza/receipt.rb', line 35

def initialize(attributes)
  @receipt_type = attributes['receipt_type']
  @adam_id = attributes['adam_id']
  @bundle_id = attributes['bundle_id']
  @application_version = attributes['application_version']
  @download_id = attributes['download_id']

  @receipt_creation_date = DateTime.parse(attributes['receipt_creation_date']) rescue nil
  @receipt_creation_date_ms = Time.zone.at(attributes['receipt_creation_date_ms'].to_i / 1000) rescue nil
  @receipt_creation_date_pst = DateTime.parse(attributes['receipt_creation_date_pst'].gsub("America/Los_Angeles","PST")) rescue nil
  @request_date = DateTime.parse(attributes['request_date']) rescue nil
  @request_date_ms = Time.zone.at(attributes['request_date_ms'].to_i / 1000) rescue nil
  @request_date_pst = DateTime.parse(attributes['request_date_pst'].gsub("America/Los_Angeles","PST")) rescue nil

  @original_purchase_date = DateTime.parse(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"))
  @original_application_version = attributes['original_application_version']

  if attributes['version_external_identifier']
    @version_external_identifier = attributes['version_external_identifier']
  end
  if attributes['app_item_id']
    @app_item_id = attributes['app_item_id']
  end
  if attributes['expiration_date']
    @expires_at = Time.zone.at(attributes['expiration_date'].to_i / 1000)
  end

  @in_app = []
  if attributes['in_app']
    attributes['in_app'].each do |transaction_receipt_attributes|
      @in_app << TransactionReceipt.new(transaction_receipt_attributes)
    end
  end
end

Instance Attribute Details

#adam_idObject (readonly)

Returns the value of attribute adam_id.



10
11
12
# File 'lib/monza/receipt.rb', line 10

def adam_id
  @adam_id
end

#app_item_idObject (readonly)

This field is not present for Mac apps



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

def app_item_id
  @app_item_id
end

#application_versionObject (readonly)

Returns the value of attribute application_version.



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

def application_version
  @application_version
end

#bundle_idObject (readonly)

Returns the value of attribute bundle_id.



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

def bundle_id
  @bundle_id
end

#download_idObject (readonly)

Returns the value of attribute download_id.



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

def download_id
  @download_id
end

#expiration_dateObject (readonly)

This key is present only for apps purchased through the Volume Purchase Program. If this key is not present, the receipt does not expire.



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

def expiration_date
  @expiration_date
end

#in_appObject (readonly)

Returns the value of attribute in_app.



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

def in_app
  @in_app
end

#original_application_versionObject (readonly)

Returns the value of attribute original_application_version.



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

def original_application_version
  @original_application_version
end

#original_purchase_dateObject (readonly)

Returns the value of attribute original_purchase_date.



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

def original_purchase_date
  @original_purchase_date
end

#original_purchase_date_msObject (readonly)

Returns the value of attribute original_purchase_date_ms.



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

def original_purchase_date_ms
  @original_purchase_date_ms
end

#original_purchase_date_pstObject (readonly)

Returns the value of attribute original_purchase_date_pst.



22
23
24
# File 'lib/monza/receipt.rb', line 22

def original_purchase_date_pst
  @original_purchase_date_pst
end

#receipt_creation_dateObject (readonly)

Returns the value of attribute receipt_creation_date.



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

def receipt_creation_date
  @receipt_creation_date
end

#receipt_creation_date_msObject (readonly)

Returns the value of attribute receipt_creation_date_ms.



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

def receipt_creation_date_ms
  @receipt_creation_date_ms
end

#receipt_creation_date_pstObject (readonly)

Returns the value of attribute receipt_creation_date_pst.



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

def receipt_creation_date_pst
  @receipt_creation_date_pst
end

#receipt_typeObject (readonly)



9
10
11
# File 'lib/monza/receipt.rb', line 9

def receipt_type
  @receipt_type
end

#request_dateObject (readonly)

Returns the value of attribute request_date.



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

def request_date
  @request_date
end

#request_date_msObject (readonly)

Returns the value of attribute request_date_ms.



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

def request_date_ms
  @request_date_ms
end

#request_date_pstObject (readonly)

Returns the value of attribute request_date_pst.



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

def request_date_pst
  @request_date_pst
end

#version_external_identifierObject (readonly)

This key is not present for receipts created in the test environment.



33
34
35
# File 'lib/monza/receipt.rb', line 33

def version_external_identifier
  @version_external_identifier
end

Class Method Details

.verify(data, options = {}) ⇒ Object

end initialize



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/monza/receipt.rb', line 72

def self.verify(data, options = {})
  client = Client.production

  begin
    client.verify(data, options)
  rescue VerificationResponse::VerificationError => error
    case error.code
    when 21007 # This receipt is from the test environment, but it was sent to the production environment for verification. Send it to the test environment instead.
      client = Client.development
      retry
    when 21008 # This receipt is from the production environment, but it was sent to the test environment for verification. Send it to the production environment instead.
      client = Client.production
      retry
    else
      raise error
    end
  end
end