mas/Sources/MasKit/AppStore/SSPurchase.swift

62 lines
1.7 KiB
Swift
Raw Normal View History

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 {
convenience init(adamId: UInt64, account: ISStoreAccount, purchase: Bool = false) {
2015-08-25 02:45:54 +08:00
self.init()
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
]
if purchase {
2020-05-14 21:32:51 -06:00
parameters["macappinstalledconfirmed"] = 1
parameters["pricingParameters"] = "STDQ"
} else {
// is redownload, use existing functionality
2020-05-14 21:32:51 -06:00
parameters["pricingParameters"] = "STDRDL"
}
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: "&")
2019-01-29 23:15:24 -07: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-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
}
}