Class: Oja::Receipt
- Inherits:
-
Object
- Object
- Oja::Receipt
- Defined in:
- lib/oja/receipt.rb
Direct Known Subclasses
Instance Attribute Summary collapse
- #data ⇒ Object
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#format ⇒ Object
Returns the value of attribute format.
-
#password ⇒ Object
Returns the value of attribute password.
Instance Method Summary collapse
- #attributes ⇒ Object
-
#initialize(attributes) ⇒ Receipt
constructor
A new instance of Receipt.
- #json? ⇒ Boolean
- #read ⇒ Object
- #receipt_data ⇒ Object
- #request(environment = :production) ⇒ Object
- #to_json ⇒ Object
- #verify ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Receipt
Returns a new instance of Receipt.
8 9 10 11 12 |
# File 'lib/oja/receipt.rb', line 8 def initialize(attributes) attributes.each do |attribute, value| send("#{attribute}=", value) end end |
Instance Attribute Details
#data ⇒ Object
26 27 28 |
# File 'lib/oja/receipt.rb', line 26 def data @data ||= read end |
#filename ⇒ Object
Returns the value of attribute filename.
5 6 7 |
# File 'lib/oja/receipt.rb', line 5 def filename @filename end |
#format ⇒ Object
Returns the value of attribute format.
5 6 7 |
# File 'lib/oja/receipt.rb', line 5 def format @format end |
#password ⇒ Object
Returns the value of attribute password.
5 6 7 |
# File 'lib/oja/receipt.rb', line 5 def password @password end |
Instance Method Details
#attributes ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/oja/receipt.rb', line 34 def attributes if json? attributes = JSON.parse(data) else attributes = { 'receipt-data' => receipt_data } end attributes['password'] = password if password attributes end |
#json? ⇒ Boolean
45 46 47 |
# File 'lib/oja/receipt.rb', line 45 def json? format == :json end |
#read ⇒ Object
22 23 24 |
# File 'lib/oja/receipt.rb', line 22 def read File.read(filename) end |
#receipt_data ⇒ Object
30 31 32 |
# File 'lib/oja/receipt.rb', line 30 def receipt_data Base64.encode64(data) end |
#request(environment = :production) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/oja/receipt.rb', line 14 def request(environment=:production) request = Request.new( :receipt => self, :environment => environment ) request.run end |
#to_json ⇒ Object
49 50 51 |
# File 'lib/oja/receipt.rb', line 49 def to_json JSON.dump(attributes) end |
#verify ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/oja/receipt.rb', line 53 def verify if response = request(:production) if response.sandbox_receipt_in_production? request(:sandbox) else response end end end |