Class: Spaceship::Tunes::IAP

Inherits:
TunesBase show all
Defined in:
spaceship/lib/spaceship/tunes/iap.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#client, #raw_data

Instance Method Summary collapse

Methods inherited from TunesBase

client

Methods inherited from Base

attr_accessor, attr_mapping, attributes, #attributes, factory, #initialize, #inspect, mapping_module, method_missing, set_client, #setup, #to_s

Constructor Details

This class inherits a constructor from Spaceship::Base

Instance Attribute Details

#applicationSpaceship::Tunes::Application

Returns A reference to the application.

Returns:



16
17
18
# File 'spaceship/lib/spaceship/tunes/iap.rb', line 16

def application
  @application
end

Instance Method Details

#all(include_deleted: false) ⇒ Object

return all available In-App-Purchase’s of current app this is not paged inside iTC-API so if you have a lot if IAP’s (2k+) it might take some time to load, same as it takes when you load the list via App Store Connect



111
112
113
114
115
116
117
118
119
120
121
122
# File 'spaceship/lib/spaceship/tunes/iap.rb', line 111

def all(include_deleted: false)
  r = client.iaps(app_id: self.application.apple_id)
  return_iaps = []
  r.each do |product|
    attrs = product
    attrs[:application] = self.application
    loaded_iap = Tunes::IAPList.factory(attrs)
    next if loaded_iap.status == "deleted" && !include_deleted
    return_iaps << loaded_iap
  end
  return_iaps
end

#create!(type: "consumable", versions: nil, reference_name: nil, product_id: nil, cleared_for_sale: true, merch_screenshot: nil, review_notes: nil, review_screenshot: nil, pricing_intervals: nil, family_id: nil, subscription_free_trial: nil, subscription_duration: nil, subscription_price_target: nil) ⇒ Object

Creates a new In-App-Purchase on App Store Connect if the In-App-Purchase already exists an exception is raised. Spaceship::TunesClient::ITunesConnectError @example: {

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

}

} @example:

[
  {
    country: "WW",
    begin_date: nil,
    end_date: nil,
    tier: 1
  }
]

price of all the countries to be roughly the same as the price calculated from the price tier and currency given as input. @example:

{
  currency: "EUR",
  tier: 2
}

Parameters:

  • type (String) (defaults to: "consumable")

    : The Type of the in-app-purchase (Spaceship::Tunes::IAPType::CONSUMABLE,Spaceship::Tunes::IAPType::NON_CONSUMABLE,Spaceship::Tunes::IAPType::RECURRING,Spaceship::Tunes::IAPType::NON_RENEW_SUBSCRIPTION)

  • versions (Hash) (defaults to: nil)

    : a Hash of the languages

  • reference_name (String) (defaults to: nil)

    : iTC Reference Name

  • product_id (String) (defaults to: nil)

    : A unique ID for your in-app-purchase

  • bundle_id (String)

    : The bundle ID must match the one you used in Xcode. It

  • cleared_for_sale (Boolean) (defaults to: true)

    : Is this In-App-Purchase Cleared for Sale

  • review_notes (String) (defaults to: nil)

    : Review Notes

  • review_screenshot (String) (defaults to: nil)

    : Path to the screenshot (should be 640x940 PNG)

  • pricing_intervals (Hash) (defaults to: nil)

    : a Hash of the languages

  • family_id (String) (defaults to: nil)

    Only used on RECURRING purchases, assigns the In-App-Purchase to a specific family

  • subscription_free_trial (String) (defaults to: nil)

    Free Trial duration (1w,1m,3m.…)

  • subscription_duration (String) (defaults to: nil)

    1w,1m.….

  • subscription_price_target (Hash) (defaults to: nil)

    Only used on RECURRING purchases, used to set the



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'spaceship/lib/spaceship/tunes/iap.rb', line 63

def create!(type: "consumable",
            versions: nil,
            reference_name: nil,
            product_id: nil,
            cleared_for_sale: true,
            merch_screenshot: nil,
            review_notes: nil,
            review_screenshot: nil,
            pricing_intervals: nil,
            family_id: nil,
            subscription_free_trial: nil,
            subscription_duration: nil,
            subscription_price_target: nil)
  client.create_iap!(app_id: self.application.apple_id,
                     type: type,
                     versions: versions,
                     reference_name: reference_name,
                     product_id: product_id,
                     cleared_for_sale: cleared_for_sale,
                     merch_screenshot: merch_screenshot,
                     review_notes: review_notes,
                     review_screenshot: review_screenshot,
                     pricing_intervals: pricing_intervals,
                     family_id: family_id,
                     subscription_duration: subscription_duration,
                     subscription_free_trial: subscription_free_trial)

  # Update pricing for a recurring subscription.
  if type == Spaceship::Tunes::IAPType::RECURRING &&
     (pricing_intervals || subscription_price_target)
    # There are cases where the product that was just created is not immediately found,
    # and in order to update its pricing the purchase_id is needed. Therefore polling is done
    # for 4 times until it is found. If it's not found after 6 tries, a PotentialServerError
    # exception is raised.
    product = find_product_with_retries(product_id, 6)
    raw_pricing_intervals =
      client.transform_to_raw_pricing_intervals(application.apple_id,
                                                product.purchase_id, pricing_intervals,
                                                subscription_price_target)
    client.update_recurring_iap_pricing!(app_id: self.application.apple_id,
                                         purchase_id: product.purchase_id,
                                         pricing_intervals: raw_pricing_intervals)
  end
end

#familiesSpaceship::Tunes::IAPFamilies

Returns A reference to the family list.

Returns:



19
20
21
22
23
# File 'spaceship/lib/spaceship/tunes/iap.rb', line 19

def families
  attrs = {}
  attrs[:application] = self.application
  Tunes::IAPFamilies.new(attrs)
end

#find(product_id) ⇒ Object

find a specific product

Parameters:

  • product_id (String)

    Product Id



126
127
128
129
130
131
132
133
# File 'spaceship/lib/spaceship/tunes/iap.rb', line 126

def find(product_id)
  all.each do |product|
    if product.product_id == product_id
      return product
    end
  end
  return nil
end

#generate_shared_secretObject

generate app-specific shared secret (or regenerate if exists)



136
137
138
# File 'spaceship/lib/spaceship/tunes/iap.rb', line 136

def generate_shared_secret
  client.generate_shared_secret(app_id: self.application.apple_id)
end

#get_shared_secret(create: false) ⇒ Object

retrieve app-specific shared secret

Parameters:

  • create (Boolean) (defaults to: false)

    Create new shared secret if does not exist



142
143
144
145
146
147
148
# File 'spaceship/lib/spaceship/tunes/iap.rb', line 142

def get_shared_secret(create: false)
  secret = client.get_shared_secret(app_id: self.application.apple_id)
  if create && secret.nil?
    secret = generate_shared_secret
  end
  secret
end