./lib/venice/client.rb in venice-0.2.0 vs ./lib/venice/client.rb in venice-0.3.0

- old
+ new

@@ -27,28 +27,36 @@ def initialize @verification_url = ENV['IAP_VERIFICATION_ENDPOINT'] end def verify!(data, options = {}) + @verification_url ||= ITUNES_DEVELOPMENT_RECEIPT_VERIFICATION_ENDPOINT + @shared_secret = options[:shared_secret] if options[:shared_secret] + json = json_response_from_verifying_data(data) status, receipt_attributes = json['status'].to_i, json['receipt'] + receipt_attributes['original_json_response'] = json if receipt_attributes case status when 0, 21006 receipt = Receipt.new(receipt_attributes) - if latest_receipt_attributes = json['latest_receipt_info'] - receipt.latest = Receipt.new(latest_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'] + # AppStore returns 'latest_receipt_info' even if we use over iOS 6. Besides, its format is an 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 end - if latest_expired_receipt_attributes = json['latest_expired_receipt_info'] - receipt.latest_expired = Receipt.new(latest_expired_receipt_attributes) - end - return receipt else - raise Receipt::VerificationError.new(status) + raise Receipt::VerificationError.new(status, receipt) end end private @@ -60,10 +68,10 @@ parameters['password'] = @shared_secret if @shared_secret uri = URI(@verification_url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true - http.verify_mode = OpenSSL::SSL::VERIFY_NONE + http.verify_mode = OpenSSL::SSL::VERIFY_PEER request = Net::HTTP::Post.new(uri.request_uri) request['Accept'] = "application/json" request['Content-Type'] = "application/json" request.body = parameters.to_json