2015-08-24 18:45:54 +00:00
|
|
|
//
|
|
|
|
// SSPurchase.swift
|
|
|
|
// mas-cli
|
|
|
|
//
|
|
|
|
// Created by Andrew Naylor on 25/08/2015.
|
|
|
|
// Copyright (c) 2015 Andrew Naylor. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2018-10-14 19:41:19 +00:00
|
|
|
import CommerceKit
|
|
|
|
import StoreFoundation
|
|
|
|
|
2019-01-12 01:06:02 +00:00
|
|
|
typealias SSPurchaseCompletion =
|
|
|
|
(_ purchase: SSPurchase?, _ completed: Bool, _ error: Error?, _ response: SSPurchaseResponse?) -> Void
|
2015-08-24 18:45:54 +00:00
|
|
|
|
|
|
|
extension SSPurchase {
|
2021-11-03 20:50:58 +00:00
|
|
|
convenience init(adamId: UInt64, account: ISStoreAccount?, purchase: Bool = false) {
|
2015-08-24 18:45:54 +00:00
|
|
|
self.init()
|
2020-01-09 11:54:01 +00:00
|
|
|
|
2020-05-15 03:32:51 +00:00
|
|
|
var parameters: [String: Any] = [
|
|
|
|
"productType": "C",
|
|
|
|
"price": 0,
|
|
|
|
"salableAdamId": adamId,
|
|
|
|
"pg": "default",
|
2021-03-22 05:25:18 +00:00
|
|
|
"appExtVrsId": 0,
|
2020-05-15 03:32:51 +00:00
|
|
|
]
|
2020-03-21 10:45:41 +00:00
|
|
|
|
2020-05-15 03:24:27 +00:00
|
|
|
if purchase {
|
2020-05-15 03:32:51 +00:00
|
|
|
parameters["macappinstalledconfirmed"] = 1
|
|
|
|
parameters["pricingParameters"] = "STDQ"
|
2020-03-21 10:45:41 +00:00
|
|
|
|
2017-11-28 12:39:44 +00:00
|
|
|
} else {
|
|
|
|
// is redownload, use existing functionality
|
2020-05-15 03:32:51 +00:00
|
|
|
parameters["pricingParameters"] = "STDRDL"
|
2017-11-28 12:39:44 +00:00
|
|
|
}
|
2020-03-21 10:45:41 +00:00
|
|
|
|
2021-03-22 05:25:18 +00:00
|
|
|
buyParameters =
|
|
|
|
parameters.map { key, value in
|
2021-03-22 05:46:17 +00:00
|
|
|
"\(key)=\(value)"
|
2021-03-22 05:25:18 +00:00
|
|
|
}
|
|
|
|
.joined(separator: "&")
|
2020-03-21 10:45:41 +00:00
|
|
|
|
2019-01-30 06:15:24 +00:00
|
|
|
itemIdentifier = adamId
|
2021-11-03 20:50:58 +00:00
|
|
|
|
2024-02-05 21:03:51 +00:00
|
|
|
if let account {
|
2021-11-03 20:50:58 +00:00
|
|
|
accountIdentifier = account.dsID
|
|
|
|
appleID = account.identifier
|
|
|
|
}
|
2017-11-28 12:39:44 +00:00
|
|
|
|
|
|
|
// Not sure if this is needed, but lets use it here.
|
2020-05-15 03:24:27 +00:00
|
|
|
if purchase {
|
2020-01-09 11:54:01 +00:00
|
|
|
isRedownload = false
|
2017-11-28 12:39:44 +00:00
|
|
|
}
|
|
|
|
|
2015-08-24 18:45:54 +00:00
|
|
|
let downloadMetadata = SSDownloadMetadata()
|
|
|
|
downloadMetadata.kind = "software"
|
|
|
|
downloadMetadata.itemIdentifier = adamId
|
2019-01-12 01:06:02 +00:00
|
|
|
|
2015-08-24 18:45:54 +00:00
|
|
|
self.downloadMetadata = downloadMetadata
|
|
|
|
}
|
2019-01-12 01:06:02 +00:00
|
|
|
|
2016-09-17 12:58:38 +00:00
|
|
|
func perform(_ completion: @escaping SSPurchaseCompletion) {
|
|
|
|
CKPurchaseController.shared().perform(self, withOptions: 0, completionHandler: completion)
|
2015-08-24 18:45:54 +00:00
|
|
|
}
|
|
|
|
}
|