Class: Deliver::UploadPriceTier

Inherits:
Object
  • Object
show all
Defined in:
deliver/lib/deliver/upload_price_tier.rb

Overview

Set the app's pricing

Instance Method Summary collapse

Instance Method Details

#upload(options) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'deliver/lib/deliver/upload_price_tier.rb', line 7

def upload(options)
  return unless options[:price_tier]

  price_tier = options[:price_tier].to_s

  legacy_app = options[:app]
  app_id = legacy_app.apple_id
  app = Spaceship::ConnectAPI::App.get(app_id: app_id)

  attributes = {}
  territory_ids = []

  app_prices = app.fetch_app_prices
  if app_prices.first
    old_price = app_prices.first.price_tier.id
  else
    UI.message("App has no prices yet... Enabling all countries in App Store Connect")
    territory_ids = Spaceship::ConnectAPI::Territory.all.map(&:id)
    attributes[:availableInNewTerritories] = true
  end

  if price_tier == old_price
    UI.success("Price Tier unchanged (tier #{old_price})")
    return
  end

  app.update(attributes: attributes, app_price_tier_id: price_tier, territory_ids: territory_ids)
  UI.success("Successfully updated the pricing from #{old_price} to #{price_tier}")
end