def create_iap!(app_id: nil, type: nil, versions: nil, reference_name: nil, product_id: nil, cleared_for_sale: true, review_notes: nil, review_screenshot: nil, pricing_intervals: nil, family_id: nil, subscription_duration: nil, subscription_free_trial: nil)
      # Load IAP Template based on Type
      type ||= "consumable"
      r = request(:get, "ra/apps/#{app_id}/iaps/#{type}/template")
      data = parse_response(r, 'data')

      # Now fill in the values we have
      # some values are nil, that's why there is a hash
      data['familyId'] = family_id.to_s if family_id
      data['productId'] = { value: product_id }
      data['referenceName'] = { value: reference_name }
      data['clearedForSale'] = { value: cleared_for_sale }

      data['pricingDurationType'] = { value: subscription_duration } if subscription_duration
      data['freeTrialDurationType'] = { value: subscription_free_trial } if subscription_free_trial

      # pricing tier
      if pricing_intervals
        data['pricingIntervals'] = []
        pricing_intervals.each do |interval|
          data['pricingIntervals'] << {
              value: {
                  country: interval[:country] || "WW",
                  tierStem: interval[:tier].to_s,
                  priceTierEndDate: interval[:end_date],
                  priceTierEffectiveDate: interval[:begin_date]
                }
          }
        end
      end

      versions_array = []
      versions.each do |k, v|
        versions_array << {
                  value: {
                    description: { value: v[:description] },
                    name: { value: v[:name] },
                    localeCode: k.to_s
                  }
        }
      end
      data["versions"][0]["details"]["value"] = versions_array
      data['versions'][0]["reviewNotes"] = { value: review_notes }

      if review_screenshot
        # Upload Screenshot:
        upload_file = UploadFile.from_path(review_screenshot)
        screenshot_data = upload_purchase_review_screenshot(app_id, upload_file)
        data["versions"][0]["reviewScreenshot"] = screenshot_data
      end

      # Now send back the modified hash
      r = request(:post) do |req|
        req.url("ra/apps/#{app_id}/iaps")
        req.body = data.to_json
        req.headers['Content-Type'] = 'application/json'
      end
      handle_itc_response(r.body)
    end
def create_iap!(app_id: nil, type: nil, versions: nil, reference_name: nil, product_id: nil, cleared_for_sale: true, review_notes: nil, review_screenshot: nil, pricing_intervals: nil, family_id: nil, subscription_duration: nil, subscription_free_trial: nil)
      # Load IAP Template based on Type
      type ||= "consumable"
      r = request(:get, "ra/apps/#{app_id}/iaps/#{type}/template")
      data = parse_response(r, 'data')

      # Now fill in the values we have
      # some values are nil, that's why there is a hash
      data['familyId'] = family_id.to_s if family_id
      data['productId'] = { value: product_id }
      data['referenceName'] = { value: reference_name }
      data['clearedForSale'] = { value: cleared_for_sale }

      data['pricingDurationType'] = { value: subscription_duration } if subscription_duration
      data['freeTrialDurationType'] = { value: subscription_free_trial } if subscription_free_trial

      # pricing tier
      if pricing_intervals
        data['pricingIntervals'] = []
        pricing_intervals.each do |interval|
          data['pricingIntervals'] << {
              value: {
                  country: interval[:country] || "WW",
                  tierStem: interval[:tier].to_s,
                  priceTierEndDate: interval[:end_date],
                  priceTierEffectiveDate: interval[:begin_date]
                }
          }
        end
      end

      versions_array = []
      versions.each do |k, v|
        versions_array << {
                  value: {
                    description: { value: v[:description] },
                    name: { value: v[:name] },
                    localeCode: k.to_s
                  }
        }
      end
      data["versions"][0]["details"]["value"] = versions_array
      data['versions'][0]["reviewNotes"] = { value: review_notes }

      if review_screenshot
        # Upload Screenshot:
        upload_file = UploadFile.from_path(review_screenshot)
        screenshot_data = upload_purchase_review_screenshot(app_id, upload_file)
        data["versions"][0]["reviewScreenshot"] = screenshot_data
      end

      # Now send back the modified hash
      r = request(:post) do |req|
        req.url("ra/apps/#{app_id}/iaps")
        req.body = data.to_json
        req.headers['Content-Type'] = 'application/json'
      end
      handle_itc_response(r.body)
    end
Creates an In-App-Purchases