class Spaceship::Tunes::IAPDetail

Attributes

application[RW]

@return (Spaceship::Tunes::Application) A reference to the application

cleared_for_sale[RW]

@return (Bool) Cleared for sale flag

is_news_subscription[RW]

@return (Bool) if it is a news subscription

merch_screenshot[RW]

@return (Hash) app store promotion image (optional)

product_id[RW]

@return (String) the IAP Product-Id

purchase_id[RW]

@return (Integer) the IAP id

raw_pricing_data[RW]

@return (Hash) Relevant only for recurring subscriptions. Holds pricing related data, such as subscription pricing, intro offers, etc.

reference_name[RW]

@return (String) the IAP Referencename

review_notes[RW]

@return (String) the notes for the review team

review_screenshot[RW]

@return (Hash) app review screenshot (required)

subscription_duration[RW]

@return (String) subscription duration

subscription_free_trial[RW]

@return (String) free trial period

subscription_price_target[RW]

@return (Hash) subscription pricing target

Public Instance Methods

delete!() click to toggle source

Deletes In-App-Purchase

# File spaceship/lib/spaceship/tunes/iap_detail.rb, line 213
def delete!
  client.delete_iap!(app_id: application.apple_id, purchase_id: self.purchase_id)
end
pricing_info() click to toggle source

Retrieves the actual prices for an iap.

@return ([]) An empty array

if the iap is not yet cleared for sale

@return ([Spaceship::Tunes::PricingInfo]) An array of pricing infos from the same pricing tier

if the iap uses world wide pricing

@return ([Spaceship::Tunes::IAPSubscriptionPricingInfo]) An array of pricing infos from multple subscription pricing tiers

if the iap uses territorial pricing
# File spaceship/lib/spaceship/tunes/iap_detail.rb, line 225
def pricing_info
  return [] unless cleared_for_sale
  return world_wide_pricing_info if world_wide_pricing?
  territorial_pricing_info
end
pricing_intervals() click to toggle source

@return (Array) pricing intervals @example:

[
  {
    country: "WW",
    begin_date: nil,
    end_date: nil,
    tier: 1
  }
]
# File spaceship/lib/spaceship/tunes/iap_detail.rb, line 130
def pricing_intervals
  @pricing_intervals ||= (raw_data["pricingIntervals"] || @raw_pricing_data["subscriptions"] || []).map do |interval|
    {
      tier: interval["value"]["tierStem"].to_i,
      begin_date: interval["value"]["priceTierEffectiveDate"],
      end_date: interval["value"]["priceTierEndDate"],
      grandfathered: interval["value"]["grandfathered"],
      country: interval["value"]["country"]
    }
  end
end
pricing_intervals=(value = []) click to toggle source

transforms user-set intervals to iTC ones

# File spaceship/lib/spaceship/tunes/iap_detail.rb, line 113
def pricing_intervals=(value = [])
  raw_pricing_intervals =
    client.transform_to_raw_pricing_intervals(application.apple_id, self.purchase_id, value)
  raw_data.set(["pricingIntervals"], raw_pricing_intervals)
  @raw_pricing_data["subscriptions"] = raw_pricing_intervals if @raw_pricing_data
end
save!() click to toggle source

Saves the current In-App-Purchase

# File spaceship/lib/spaceship/tunes/iap_detail.rb, line 165
def save!
  # Transform localization versions back to original format.
  versions_array = []
  versions.each do |language, value|
    versions_array << {
              "value" =>  {
                "description" => { "value" => value[:description] },
                "name" => { "value" => value[:name] },
                "localeCode" => language.to_s,
                "id" => value[:id]
              }
    }
  end

  raw_data.set(["versions"], [{ reviewNotes: { value: @review_notes }, contentHosting: raw_data['versions'].first['contentHosting'], "details" => { "value" => versions_array }, id: raw_data["versions"].first["id"], reviewScreenshot: { "value" => review_screenshot } }])

  # transform pricingDetails
  raw_pricing_intervals =
    client.transform_to_raw_pricing_intervals(application.apple_id,
                                              self.purchase_id, pricing_intervals,
                                              subscription_price_target)
  raw_data.set(["pricingIntervals"], raw_pricing_intervals)
  @raw_pricing_data["subscriptions"] = raw_pricing_intervals if @raw_pricing_data

  if @merch_screenshot
    # Upload App Store Promotional image (Optional)
    upload_file = UploadFile.from_path(@merch_screenshot)
    merch_data = client.upload_purchase_merch_screenshot(application.apple_id, upload_file)
    raw_data["versions"][0]["merch"] = merch_data
  end

  if @review_screenshot
    # Upload Screenshot
    upload_file = UploadFile.from_path(@review_screenshot)
    screenshot_data = client.upload_purchase_review_screenshot(application.apple_id, upload_file)
    raw_data["versions"][0]["reviewScreenshot"] = screenshot_data
  end
  # Update the Purchase
  client.update_iap!(app_id: application.apple_id, purchase_id: self.purchase_id, data: raw_data)

  # Update pricing for a recurring subscription.
  if raw_data["addOnType"] == Spaceship::Tunes::IAPType::RECURRING
    client.update_recurring_iap_pricing!(app_id: application.apple_id, purchase_id: self.purchase_id,
                                         pricing_intervals: raw_data["pricingIntervals"])
  end
end
setup() click to toggle source
# File spaceship/lib/spaceship/tunes/iap_detail.rb, line 59
def setup
  @raw_pricing_data = @raw_data["pricingData"]
  @raw_data.delete("pricingData")

  if @raw_pricing_data
    @raw_data.set(["pricingIntervals"], @raw_pricing_data["subscriptions"])
  end
end
status() click to toggle source

@return (String) Human Readable status of the purchase

# File spaceship/lib/spaceship/tunes/iap_detail.rb, line 148
def status
  Tunes::IAPStatus.get_from_string(raw_data["versions"].first["status"])
end
type() click to toggle source

@return (String) Human Readable type of the purchase

# File spaceship/lib/spaceship/tunes/iap_detail.rb, line 143
def type
  Tunes::IAPType.get_from_string(raw_data["addOnType"])
end
versions() click to toggle source

@return (Hash) Hash of languages @example: {

'de-DE': {
  name: "Name shown in AppStore",
  description: "Description of the In app Purchase"

}

}

# File spaceship/lib/spaceship/tunes/iap_detail.rb, line 76
def versions
  parsed_versions = {}
  raw_versions = raw_data["versions"].first["details"]["value"]
  raw_versions.each do |localized_version|
    language = localized_version["value"]["localeCode"]
    parsed_versions[language.to_sym] = {
      name: localized_version["value"]["name"]["value"],
      description: localized_version["value"]["description"]["value"],
      id: localized_version["value"]["id"],
      status: localized_version["value"]["status"]
    }
  end
  return parsed_versions
end
versions=(value = {}) click to toggle source

transforms user-set versions to iTC ones

# File spaceship/lib/spaceship/tunes/iap_detail.rb, line 92
def versions=(value = {})
  if value.kind_of?(Array)
    # input that comes from iTC api
    return
  end
  new_versions = []
  value.each do |language, current_version|
    new_versions << {
      "value" =>   {
        "name" =>  { "value" => current_version[:name] },
        "description" =>  { "value" => current_version[:description] },
        "localeCode" => language.to_s,
        "id" => current_version[:id]
      }
    }
  end

  raw_data.set(["versions"], [{ reviewNotes: { value: @review_notes }, "contentHosting" => raw_data['versions'].first['contentHosting'], "details" => { "value" => new_versions }, "id" => raw_data["versions"].first["id"], "reviewScreenshot" => { "value" => review_screenshot } }])
end

Private Instance Methods

territorial_pricing_info() click to toggle source

Maps pricing intervals to their respective subscription pricing infos.

@return ([Spaceship::Tunes::IAPSubscriptionPricingInfo]) An array of subscription pricing infos

# File spaceship/lib/spaceship/tunes/iap_detail.rb, line 253
def territorial_pricing_info
  pricing_matrix = client.subscription_pricing_tiers(application.apple_id)
  pricing_intervals.map do |interval|
    pricing_matrix
      .find { |p| p.tier_stem == interval[:tier].to_s }
      .pricing_info
      .find { |i| i.country_code == interval[:country] }
  end
end
world_wide_pricing?() click to toggle source

Checks wheather an iap uses world wide or territorial pricing.

@return (true, false)

# File spaceship/lib/spaceship/tunes/iap_detail.rb, line 236
def world_wide_pricing?
  pricing_intervals.fetch(0, {})[:country] == "WW"
end
world_wide_pricing_info() click to toggle source

Maps a single pricing interval to pricing infos.

@return ([Spaceship::Tunes::PricingInfo]) An array of pricing infos from the same tier

# File spaceship/lib/spaceship/tunes/iap_detail.rb, line 243
def world_wide_pricing_info
  client
    .pricing_tiers(application.apple_id)
    .find { |p| p.tier_stem == pricing_intervals.first[:tier].to_s }
    .pricing_info
end