Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to the latest App Store Pricing Matrix #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions Example/Extensions/SKProduct+Locale.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// SKProduct+Locale.swift
//
//
// Created by Alex Kovalov on 01.06.2020.
// Copyright © 2020 Alex Kovalov. All rights reserved.
//

import Foundation
import StoreKit
import PriceKit

public extension SKProduct {

func priceNumberInLocale(_ locale: Locale) -> NSNumber? {

guard let store = PriceStore() else {
return nil
}

for tier in Tier.allCases {
if let tierPrice = store.getPrice(of: tier, inPriceLocale: priceLocale),
tierPrice.price == self.price {

if let otherLocalePrice = store.getPrice(of: tier, inPriceLocale: locale) {
return otherLocalePrice.price
}
}
}
return nil
}

func formattedPriceInLocale(_ locale: Locale) -> String? {

guard let price = priceNumberInLocale(locale) else {
return nil
}

let formatter = priceFormatter(locale: locale)
return formatter.string(from: price)
}

func priceFormatter(locale: Locale) -> NumberFormatter {

let formatter = NumberFormatter()
formatter.locale = locale
formatter.numberStyle = .currency
return formatter
}
}
11 changes: 9 additions & 2 deletions Example/Podfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '9.3'

use_frameworks!

target 'PriceKit_Tests' do

pod 'PriceKit', :path => '../'

pod 'Quick', '~> 1.2.0'
pod 'Nimble', '~> 7.0.2'
pod 'Quick'
pod 'Nimble'

end
27 changes: 16 additions & 11 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
PODS:
- Nimble (7.0.3)
- PriceKit (0.1.0)
- Quick (1.2.0)
- Nimble (8.0.9)
- PriceKit (1.1.1)
- Quick (2.2.0)

DEPENDENCIES:
- Nimble (~> 7.0.2)
- Nimble
- PriceKit (from `../`)
- Quick (~> 1.2.0)
- Quick

SPEC REPOS:
trunk:
- Nimble
- Quick

EXTERNAL SOURCES:
PriceKit:
:path: ../
:path: "../"

SPEC CHECKSUMS:
Nimble: 7f5a9c447a33002645a071bddafbfb24ea70e0ac
PriceKit: 0342e04574bf7c02c7a5605527efde7c3eb5d14d
Quick: 58d203b1c5e27fff7229c4c1ae445ad7069a7a08
Nimble: 98b888285a615fd34f20e61753cf58ea1402bde4
PriceKit: 161a745d06190414f5b02905810a1a7ddf0a1df7
Quick: 7fb19e13be07b5dfb3b90d4f9824c855a11af40e

PODFILE CHECKSUM: a746ed5c3da29ecb786ec296c5913405e5a71b03
PODFILE CHECKSUM: db9a3ccaae54a41d3942456969aede15ece34f3f

COCOAPODS: 1.3.1
COCOAPODS: 1.9.3
20 changes: 2 additions & 18 deletions Example/PriceKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
607FACE21AFB9204008FA782 /* Frameworks */,
607FACE31AFB9204008FA782 /* Resources */,
47C387C70B8F62566F49C312 /* [CP] Embed Pods Frameworks */,
E8FBB4559A53E35D5F22D4D7 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -192,7 +191,7 @@
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-PriceKit_Tests/Pods-PriceKit_Tests-frameworks.sh",
"${PODS_ROOT}/Target Support Files/Pods-PriceKit_Tests/Pods-PriceKit_Tests-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/Nimble/Nimble.framework",
"${BUILT_PRODUCTS_DIR}/PriceKit/PriceKit.framework",
"${BUILT_PRODUCTS_DIR}/Quick/Quick.framework",
Expand All @@ -205,22 +204,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-PriceKit_Tests/Pods-PriceKit_Tests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
E8FBB4559A53E35D5F22D4D7 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-PriceKit_Tests/Pods-PriceKit_Tests-resources.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-PriceKit_Tests/Pods-PriceKit_Tests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
Expand Down
2 changes: 1 addition & 1 deletion PriceKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'PriceKit'
s.version = '1.1.0'
s.version = '1.1.1'
s.summary = 'Get App Store product prices by tier and locale.'

s.description = <<-DESC
Expand Down
4 changes: 2 additions & 2 deletions PriceKit/Classes/PricingStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import Foundation

public class PriceStore {
// The name of the default pricing matrix csv file.
// Apple appends the download timestamp to the filename when you download the file from iTunes Connect,
// Apple appends the download timestamp to the filename when you download the file from App Store Connect,
// which is useful information to have and should be preserved as "proof" of when the pricing table was generated.
// If you are updating PriceKit's pricing matrix, delete the outdated CSV file, replace it with the newer CSV file,
// and update the variable here so it points to the updated filename.
static fileprivate let defaultPricingMatrixCsvFilename = "pricing_matrix_20180107-002959"
static fileprivate let defaultPricingMatrixCsvFilename = "pricing_matrix_20200605-053929"

// The actual pricing table, where the keys are region codes (see Apple's Locale documentation)
// and the values are the region's tier to price lookup table.
Expand Down
143 changes: 92 additions & 51 deletions PriceKit/Classes/RegionCodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,70 +9,111 @@ class RegionCodes {
// The two-letter region codes here must be ISO 3166-1 country codes (compatible with the Locale class):
// https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
static fileprivate let regionCodesByCountryName: Dictionary<String, String> = [
"United States" : "US",
"Canada": "CA",
"Mexico": "MX",
"Australia": "AU",
"New Zealand": "NZ",
"Japan": "JP",
"China": "CN",
"Singapore": "SG",

"Hong Kong": "HK",
"Taiwan": "TW",
"Portugal": "PT",
"Honduras": "HN",
"Paraguay": "PY",
"Croatia": "HR",
"Hungary": "HU",
"Qatar": "QA",
"Indonesia": "ID",
"India": "IN",
"Russia": "RU",
"Turkey": "TR",
"Ireland": "IE",
"Israel": "IL",
"United Arab Emirates": "AE",
"Afghanistan": "AF",
"India": "IN",
"South Africa": "ZA",
"Iraq": "IQ",
"Iceland": "IS",
"Albania": "AL",
"Italy": "IT",
"Armenia": "AM",
"Argentina": "AR",
"Zambia": "ZM",
"Austria": "AT",
"Australia": "AU",
"Romania": "RO",
"Bosnia and Herzegovina": "BA",
"Barbados": "BB",
"Serbia": "RS",
"Russia": "RU",
"Belgium": "BE",
"Bulgaria": "BG",
"Rwanda": "RW",
"Japan": "JP",
"Bahrain": "BH",
"Bolivia": "BO",
"Saudi Arabia": "SA",
"United Arab Emirates": "AE",
"United Kingdom": "UK",
"Denmark": "DK",
"Brazil": "BR",
"Sweden": "SE",
"Singapore": "SG",
"Slovenia": "SI",
"Belarus": "BY",
"Slovakia": "SK",
"Canada": "CA",
"Congo, Democratic Republic of": "CD",
"El Salvador": "SV",
"Switzerland": "CH",
"Norway": "NO",
"Luxembourg": "LU",
"Malta": "MT",
"Cote D'Ivoire": "CI",
"Ivoire": "CI",
"South Korea": "KR",
"Chile": "CL",
"Cameroon": "CM",
"China": "CN",
"Colombia": "CO",
"Costa Rica": "CR",
"Kazakhstan": "KZ",
"Thailand": "TH",
"Cyprus": "CY",
"Germany": "DE",
"France": "FR",
"Austria": "AT",
"Bulgaria": "BG",
"Estonia": "EE",
"Slovakia": "SK",
"Belgium": "BE",
"Czech Republic": "CZ",
"Latvia": "LV",
"Tonga": "TO",
"Turkey": "TR",
"Germany": "DE",
"Taiwan": "TW",
"Tanzania": "TZ",
"Denmark": "DK",
"Lithuania": "LT",
"Netherlands": "NL",
"Spain": "ES",
"Italy": "IT",
"Slovenia": "SI",
"Greece": "GR",
"Ireland": "IE",
"Poland": "PL",
"Portugal": "PT",
"Finland": "SF",
"Romania": "RO",
"Hungary": "HU",
"Korea, Republic Of": "KR",
"Thailand": "TH",
"Iceland": "IS",
"Croatia": "HR",
"Albania": "AL",
"Luxembourg": "LU",
"Latvia": "LV",
"Dominican Republic": "DO",
"Ukraine": "UA",
"Libya": "LF",
"Morocco": "MA",
"Moldova": "MD",
"Montenegro": "ME",
"Ecuador": "EC",
"United States": "US",
"Myanmar": "MM",
"Estonia": "EW",
"Egypt": "EG",
"Uruguay": "UY",
"Uzbekistan": "UZ",
"Malta": "MT",
"Maldives": "MV",
"Mexico": "MX",
"Malaysia": "MY",
"Philippines": "PH",
"Spain": "ES",
"Vietnam": "VN",
"Egypt": "EG",
"Kazakhstan": "KZ",
"Qatar": "QA",
"Nigeria": "NG",
"Pakistan": "OK",
"Tanzania, United Republic Of": "TZ",
"Chile": "CL",
"Colombia": "CO",
"Nicaragua": "NI",
"Netherlands": "NL",
"Vanuatu": "VU",
"Norway": "NO",
"Finland": "SF",
"Nauru": "NR",
"New Zealand": "NZ",
"France": "FR",
"Gabon": "GA",
"United Kingdom": "UK",
"Georgia": "GE",
"Greece": "GR",
"Guatemala": "GT",
"Panama": "PA",
"Kosovo": "XK",
"Peru": "PE",
"Brazil": "BR"
"Philippines": "PH",
"Pakistan": "PK",
"Poland": "PL"
]
}
2 changes: 1 addition & 1 deletion PriceKit/Classes/Tier.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

// Available price tiers. These should match the tiers in the pricing matrix CSV.
public enum Tier: String {
public enum Tier: String, CaseIterable {
case free = "Free"
case tier1 = "Tier 1"
case tier2 = "Tier 2"
Expand Down
Loading