Skip to content

Instantly share code, notes, and snippets.

View EllinaKuznetcova's full-sized avatar

Ellina Kuznetcova EllinaKuznetcova

View GitHub Profile
const appBridge = {
initialize: function () {
if (window.location.host.indexOf('web-demo') !== -1)
return;
console.log('initialize appBridge');
appBridge.parseDom();
window.addEventListener("message", (event) => {
{
"Booking": {
"BookingUuid": "cee3384c-3155-4684-ad06-b9a1ee134e5b",
"Name": "ellinaclient",
"Start": "2022-06-16T12:00:00Z",
"End": "2022-06-16T13:00:00Z",
"Machines": [
"3b8eb5ff-e9ae-4d42-9e3b-7c63d72a1dc3"
],
"WithCoupons": false,
func paymentQueue(_ queue: SKPaymentQueue, restoreCompletedTransactionsFailedWithError error: Swift.Error) {
self.delegate?.inAppLoadingFailed(error: error)
}
func restoreSubscription() {
SKPaymentQueue.default().restoreCompletedTransactions()
self.delegate?.inAppLoadingStarted()
}
class RTSubscriptionResponse: Mappable {
var expirationDate: Date?
var isTrial: Bool?
var productId: String?
required convenience init?(map: Map) {
self.init()
}
func purchaseProduct(productType: ProductType) {
guard let product = self.products.filter({$0.productIdentifier == productType.rawValue}).first else {
self.delegate?.inAppLoadingFailed(error: InAppErrors.noProductsAvailable)
return
}
let payment = SKMutablePayment(product: product)
SKPaymentQueue.default().add(payment)
}
extension InAppManager: SKProductsRequestDelegate {
func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
self.products = response.products
}
}
func loadProducts() {
let productIdentifiers = Set<String>(ProductType.all.map({$0.rawValue}))
let request = SKProductsRequest(productIdentifiers: productIdentifiers)
request.delegate = self
request.start()
}
enum ProductType: String {
case weekly = "com.example.app.weekly"
case monthly = "com.example.app.monthly"
case yearly = "com.example.app.yearly"
static var all: [ProductType] {
return [.weekly, .monthly, .yearly]
}
}
class InAppManager: NSObject {
static let shared = InAppManager()
}
extension InAppManager: SKPaymentTransactionObserver {}
extension InAppManager: SKProductsRequestDelegate {}