Class: Ios::Receipt::Client

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

Constant Summary collapse

ENDPOINTS =
{
  production: 'https://buy.itunes.apple.com/verifyReceipt',
  sandbox: 'https://sandbox.itunes.apple.com/verifyReceipt'
}

Instance Method Summary collapse

Constructor Details

#initialize(method = nil, secret = nil, ssl_version = 'TLSv1') ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
12
13
14
# File 'lib/ios/receipt/client.rb', line 7

def initialize(method=nil, secret=nil, ssl_version='TLSv1')
  method ||= :mixed
  @method = method
  @secret = secret
  @ssl_version = ssl_version
  
  raise Ios::Receipt::Exceptions::InvalidConfiguration unless valid_method?
end

Instance Method Details

#verify!(receipt) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ios/receipt/client.rb', line 16

def verify!(receipt)
  data = { 'receipt-data' => receipt }
  data['password'] = @secret unless @secret.nil?
  data = data.to_json
  
  response = nil
  response = post_to_endpoint(:production, data) if try_production?
  response = post_to_endpoint(:sandbox, data) if response.nil? && try_sandbox?
  
  response
end