mas/Sources/MasKit/AppStore/SSPurchase.swift

62 lines
1.7 KiB
Swift
Raw Normal View History

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 {
convenience init(adamId: UInt64, account: ISStoreAccount, purchase: Bool = false) {
2015-08-24 18:45:54 +00:00
self.init()
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
]
if purchase {
2020-05-15 03:32:51 +00:00
parameters["macappinstalledconfirmed"] = 1
parameters["pricingParameters"] = "STDQ"
} else {
// is redownload, use existing functionality
2020-05-15 03:32:51 +00:00
parameters["pricingParameters"] = "STDRDL"
}
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: "&")
2019-01-30 06:15:24 +00:00
itemIdentifier = adamId
accountIdentifier = account.dsID
appleID = account.identifier
// Not sure if this is needed, but lets use it here.
if purchase {
isRedownload = false
}
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
}
}