Class: Venice::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/venice/client.rb

Defined Under Namespace

Classes: InvalidResponseError, TimeoutError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



28
29
30
# File 'lib/venice/client.rb', line 28

def initialize
  @verification_url = ENV['IAP_VERIFICATION_ENDPOINT']
end

Instance Attribute Details

#exclude_old_transactions=(value) ⇒ Object (writeonly)

Sets the attribute exclude_old_transactions

Parameters:

  • value

    the value to set the attribute exclude_old_transactions to.



12
13
14
# File 'lib/venice/client.rb', line 12

def exclude_old_transactions=(value)
  @exclude_old_transactions = value
end

#shared_secret=(value) ⇒ Object (writeonly)

Sets the attribute shared_secret

Parameters:

  • value

    the value to set the attribute shared_secret to.



11
12
13
# File 'lib/venice/client.rb', line 11

def shared_secret=(value)
  @shared_secret = value
end

#verification_urlObject

Returns the value of attribute verification_url.



10
11
12
# File 'lib/venice/client.rb', line 10

def verification_url
  @verification_url
end

Class Method Details

.developmentObject



15
16
17
18
19
# File 'lib/venice/client.rb', line 15

def development
  client = new
  client.verification_url = ITUNES_DEVELOPMENT_RECEIPT_VERIFICATION_ENDPOINT
  client
end

.productionObject



21
22
23
24
25
# File 'lib/venice/client.rb', line 21

def production
  client = new
  client.verification_url = ITUNES_PRODUCTION_RECEIPT_VERIFICATION_ENDPOINT
  client
end

Instance Method Details

#verify!(data, options = {}) ⇒ Object



32
33
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
# File 'lib/venice/client.rb', line 32

def verify!(data, options = {})
  @shared_secret = options[:shared_secret] if options[:shared_secret]
  @exclude_old_transactions = options[:exclude_old_transactions] if options[:exclude_old_transactions]

  json = json_response_from_verifying_data(data, options)
  receipt_attributes = json['receipt'].dup if json['receipt']
  receipt_attributes['original_json_response'] = json if receipt_attributes

  case json['status'].to_i
  when 0, 21006
    receipt = Receipt.new(receipt_attributes)

    # From Apple docs:
    # > Only returned for iOS 6 style transaction receipts for auto-renewable subscriptions.
    # > The JSON representation of the receipt for the most recent renewal
    if latest_receipt_info_attributes = json['latest_receipt_info']
      latest_receipt_info_attributes = [latest_receipt_info_attributes] if latest_receipt_info_attributes.is_a?(Hash)

      # AppStore returns 'latest_receipt_info' even if we use over iOS 6. Besides, its format is an Array.
      if latest_receipt_info_attributes.is_a?(Array)
        receipt.latest_receipt_info = []
        latest_receipt_info_attributes.each do |latest_receipt_info_attribute|
          # latest_receipt_info format is identical with in_app
          receipt.latest_receipt_info << InAppReceipt.new(latest_receipt_info_attribute)
        end
      else
        receipt.latest_receipt_info = latest_receipt_info_attributes
      end
    end

    return receipt
  else
    raise Receipt::VerificationError, json
  end
end