class Ios::Receipt::Client
Constants
- ENDPOINTS
Public Class Methods
new(method=nil, secret=nil, ssl_version='TLSv1')
click to toggle source
# 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
Public Instance Methods
verify!(receipt)
click to toggle source
# 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
Protected Instance Methods
post_to_endpoint(env, data)
click to toggle source
# File lib/ios/receipt/client.rb, line 42 def post_to_endpoint(env, data) begin response = RestClient::Request.execute method: :post, url: ENDPOINTS[env], payload: data, ssl_version: @ssl_version Ios::Receipt::Result.new JSON.parse(response), env rescue Ios::Receipt::Exceptions::SandboxReceipt => e raise Ios::Receipt::Exceptions::SandboxReceipt unless env == :production && try_sandbox? nil end end
try_production?()
click to toggle source
# File lib/ios/receipt/client.rb, line 30 def try_production? [:mixed, :production].include? @method end
try_sandbox?()
click to toggle source
# File lib/ios/receipt/client.rb, line 34 def try_sandbox? [:mixed, :sandbox].include? @method end
valid_method?()
click to toggle source
# File lib/ios/receipt/client.rb, line 38 def valid_method? try_production? || try_sandbox? end