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