expo-iap 2.4.1 → 2.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ios/ExpoIapModule.swift +60 -146
- package/package.json +1 -1
package/ios/ExpoIapModule.swift
CHANGED
|
@@ -209,9 +209,7 @@ public class ExpoIapModule: Module {
|
|
|
209
209
|
|
|
210
210
|
AsyncFunction("getItems") { (skus: [String]) -> [[String: Any?]?] in
|
|
211
211
|
guard let productStore = self.productStore else {
|
|
212
|
-
throw
|
|
213
|
-
domain: "ExpoIapModule", code: 1,
|
|
214
|
-
userInfo: [NSLocalizedDescriptionKey: "Connection not initialized"])
|
|
212
|
+
throw Exception(name: "ExpoIapModule", description: "Connection not initialized", code: "1")
|
|
215
213
|
}
|
|
216
214
|
|
|
217
215
|
do {
|
|
@@ -225,6 +223,9 @@ public class ExpoIapModule: Module {
|
|
|
225
223
|
return products.map { serializeProduct($0) }.compactMap { $0 }
|
|
226
224
|
} catch {
|
|
227
225
|
print("Error fetching items: \(error)")
|
|
226
|
+
if error is Exception {
|
|
227
|
+
throw error
|
|
228
|
+
}
|
|
228
229
|
throw error
|
|
229
230
|
}
|
|
230
231
|
}
|
|
@@ -325,9 +326,7 @@ public class ExpoIapModule: Module {
|
|
|
325
326
|
appAccountToken: String?, quantity: Int, discountOffer: [String: String]?
|
|
326
327
|
) -> [String: Any?]? in
|
|
327
328
|
guard let productStore = self.productStore else {
|
|
328
|
-
throw
|
|
329
|
-
domain: "ExpoIapModule", code: 1,
|
|
330
|
-
userInfo: [NSLocalizedDescriptionKey: "Connection not initialized"])
|
|
329
|
+
throw Exception(name: "ExpoIapModule", description: "Connection not initialized", code: "1")
|
|
331
330
|
}
|
|
332
331
|
|
|
333
332
|
let product: Product? = await productStore.getProduct(productID: sku)
|
|
@@ -357,9 +356,7 @@ public class ExpoIapModule: Module {
|
|
|
357
356
|
options.insert(.appAccountToken(appAccountUUID))
|
|
358
357
|
}
|
|
359
358
|
guard let windowScene = await self.currentWindowScene() else {
|
|
360
|
-
throw
|
|
361
|
-
domain: "ExpoIapModule", code: 2,
|
|
362
|
-
userInfo: [NSLocalizedDescriptionKey: "Could not find window scene"])
|
|
359
|
+
throw Exception(name: "ExpoIapModule", description: "Could not find window scene", code: "2")
|
|
363
360
|
}
|
|
364
361
|
let result: Product.PurchaseResult
|
|
365
362
|
#if swift(>=5.9)
|
|
@@ -402,30 +399,20 @@ public class ExpoIapModule: Module {
|
|
|
402
399
|
return serialized
|
|
403
400
|
}
|
|
404
401
|
case .userCancelled:
|
|
405
|
-
throw
|
|
406
|
-
domain: "ExpoIapModule", code: 3,
|
|
407
|
-
userInfo: [NSLocalizedDescriptionKey: "User cancelled the purchase"])
|
|
402
|
+
throw Exception(name: "ExpoIapModule", description: "User cancelled the purchase", code: "3")
|
|
408
403
|
case .pending:
|
|
409
|
-
throw
|
|
410
|
-
domain: "ExpoIapModule", code: 4,
|
|
411
|
-
userInfo: [NSLocalizedDescriptionKey: "The payment was deferred"])
|
|
404
|
+
throw Exception(name: "ExpoIapModule", description: "The payment was deferred", code: "4")
|
|
412
405
|
@unknown default:
|
|
413
|
-
throw
|
|
414
|
-
domain: "ExpoIapModule", code: 5,
|
|
415
|
-
userInfo: [NSLocalizedDescriptionKey: "Unknown purchase result"])
|
|
406
|
+
throw Exception(name: "ExpoIapModule", description: "Unknown purchase result", code: "5")
|
|
416
407
|
}
|
|
417
408
|
} catch {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
"Purchase failed: \(error.localizedDescription)"
|
|
423
|
-
])
|
|
409
|
+
if error is Exception {
|
|
410
|
+
throw error
|
|
411
|
+
}
|
|
412
|
+
throw Exception(name: "ExpoIapModule", description: "Purchase failed: \(error.localizedDescription)", code: "6")
|
|
424
413
|
}
|
|
425
414
|
} else {
|
|
426
|
-
throw
|
|
427
|
-
domain: "ExpoIapModule", code: 7,
|
|
428
|
-
userInfo: [NSLocalizedDescriptionKey: "Invalid product ID"])
|
|
415
|
+
throw Exception(name: "ExpoIapModule", description: "Invalid product ID", code: "7")
|
|
429
416
|
}
|
|
430
417
|
}
|
|
431
418
|
|
|
@@ -435,9 +422,7 @@ public class ExpoIapModule: Module {
|
|
|
435
422
|
|
|
436
423
|
AsyncFunction("subscriptionStatus") { (sku: String) -> [[String: Any?]?]? in
|
|
437
424
|
guard let productStore = self.productStore else {
|
|
438
|
-
throw
|
|
439
|
-
domain: "ExpoIapModule", code: 1,
|
|
440
|
-
userInfo: [NSLocalizedDescriptionKey: "Connection not initialized"])
|
|
425
|
+
throw Exception(name: "ExpoIapModule", description: "Connection not initialized", code: "1")
|
|
441
426
|
}
|
|
442
427
|
|
|
443
428
|
do {
|
|
@@ -449,20 +434,16 @@ public class ExpoIapModule: Module {
|
|
|
449
434
|
}
|
|
450
435
|
return status.map { serializeSubscriptionStatus($0) }
|
|
451
436
|
} catch {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
"Error getting subscription status: \(error.localizedDescription)"
|
|
457
|
-
])
|
|
437
|
+
if error is Exception {
|
|
438
|
+
throw error
|
|
439
|
+
}
|
|
440
|
+
throw Exception(name: "ExpoIapModule", description: "Error getting subscription status: \(error.localizedDescription)", code: "2")
|
|
458
441
|
}
|
|
459
442
|
}
|
|
460
443
|
|
|
461
444
|
AsyncFunction("currentEntitlement") { (sku: String) -> [String: Any?]? in
|
|
462
445
|
guard let productStore = self.productStore else {
|
|
463
|
-
throw
|
|
464
|
-
domain: "ExpoIapModule", code: 1,
|
|
465
|
-
userInfo: [NSLocalizedDescriptionKey: "Connection not initialized"])
|
|
446
|
+
throw Exception(name: "ExpoIapModule", description: "Connection not initialized", code: "1")
|
|
466
447
|
}
|
|
467
448
|
|
|
468
449
|
if let product = await productStore.getProduct(productID: sku) {
|
|
@@ -471,37 +452,24 @@ public class ExpoIapModule: Module {
|
|
|
471
452
|
let transaction = try self.checkVerified(result)
|
|
472
453
|
return serializeTransaction(transaction)
|
|
473
454
|
} catch StoreError.failedVerification {
|
|
474
|
-
throw
|
|
475
|
-
domain: "ExpoIapModule", code: 2,
|
|
476
|
-
userInfo: [
|
|
477
|
-
NSLocalizedDescriptionKey:
|
|
478
|
-
"Failed to verify transaction for sku \(sku)"
|
|
479
|
-
])
|
|
455
|
+
throw Exception(name: "ExpoIapModule", description: "Failed to verify transaction for sku \(sku)", code: "2")
|
|
480
456
|
} catch {
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
"Error fetching entitlement for sku \(sku): \(error.localizedDescription)"
|
|
486
|
-
])
|
|
457
|
+
if error is Exception {
|
|
458
|
+
throw error
|
|
459
|
+
}
|
|
460
|
+
throw Exception(name: "ExpoIapModule", description: "Error fetching entitlement for sku \(sku): \(error.localizedDescription)", code: "3")
|
|
487
461
|
}
|
|
488
462
|
} else {
|
|
489
|
-
throw
|
|
490
|
-
domain: "ExpoIapModule", code: 4,
|
|
491
|
-
userInfo: [NSLocalizedDescriptionKey: "Can't find entitlement for sku \(sku)"])
|
|
463
|
+
throw Exception(name: "ExpoIapModule", description: "Can't find entitlement for sku \(sku)", code: "4")
|
|
492
464
|
}
|
|
493
465
|
} else {
|
|
494
|
-
throw
|
|
495
|
-
domain: "ExpoIapModule", code: 5,
|
|
496
|
-
userInfo: [NSLocalizedDescriptionKey: "Can't find product for sku \(sku)"])
|
|
466
|
+
throw Exception(name: "ExpoIapModule", description: "Can't find product for sku \(sku)", code: "5")
|
|
497
467
|
}
|
|
498
468
|
}
|
|
499
469
|
|
|
500
470
|
AsyncFunction("latestTransaction") { (sku: String) -> [String: Any?]? in
|
|
501
471
|
guard let productStore = self.productStore else {
|
|
502
|
-
throw
|
|
503
|
-
domain: "ExpoIapModule", code: 1,
|
|
504
|
-
userInfo: [NSLocalizedDescriptionKey: "Connection not initialized"])
|
|
472
|
+
throw Exception(name: "ExpoIapModule", description: "Connection not initialized", code: "1")
|
|
505
473
|
}
|
|
506
474
|
|
|
507
475
|
if let product = await productStore.getProduct(productID: sku) {
|
|
@@ -510,29 +478,18 @@ public class ExpoIapModule: Module {
|
|
|
510
478
|
let transaction = try self.checkVerified(result)
|
|
511
479
|
return serializeTransaction(transaction)
|
|
512
480
|
} catch StoreError.failedVerification {
|
|
513
|
-
throw
|
|
514
|
-
domain: "ExpoIapModule", code: 2,
|
|
515
|
-
userInfo: [
|
|
516
|
-
NSLocalizedDescriptionKey:
|
|
517
|
-
"Failed to verify transaction for sku \(sku)"
|
|
518
|
-
])
|
|
481
|
+
throw Exception(name: "ExpoIapModule", description: "Failed to verify transaction for sku \(sku)", code: "2")
|
|
519
482
|
} catch {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
"Error fetching latest transaction for sku \(sku): \(error.localizedDescription)"
|
|
525
|
-
])
|
|
483
|
+
if error is Exception {
|
|
484
|
+
throw error
|
|
485
|
+
}
|
|
486
|
+
throw Exception(name: "ExpoIapModule", description: "Error fetching latest transaction for sku \(sku): \(error.localizedDescription)", code: "3")
|
|
526
487
|
}
|
|
527
488
|
} else {
|
|
528
|
-
throw
|
|
529
|
-
domain: "ExpoIapModule", code: 4,
|
|
530
|
-
userInfo: [NSLocalizedDescriptionKey: "Can't find latest transaction for sku \(sku)"])
|
|
489
|
+
throw Exception(name: "ExpoIapModule", description: "Can't find latest transaction for sku \(sku)", code: "4")
|
|
531
490
|
}
|
|
532
491
|
} else {
|
|
533
|
-
throw
|
|
534
|
-
domain: "ExpoIapModule", code: 5,
|
|
535
|
-
userInfo: [NSLocalizedDescriptionKey: "Can't find product for sku \(sku)"])
|
|
492
|
+
throw Exception(name: "ExpoIapModule", description: "Can't find product for sku \(sku)", code: "5")
|
|
536
493
|
}
|
|
537
494
|
}
|
|
538
495
|
|
|
@@ -542,9 +499,7 @@ public class ExpoIapModule: Module {
|
|
|
542
499
|
self.transactions.removeValue(forKey: transactionIdentifier)
|
|
543
500
|
return true
|
|
544
501
|
} else {
|
|
545
|
-
throw
|
|
546
|
-
domain: "ExpoIapModule", code: 8,
|
|
547
|
-
userInfo: [NSLocalizedDescriptionKey: "Invalid transaction ID"])
|
|
502
|
+
throw Exception(name: "ExpoIapModule", description: "Invalid transaction ID", code: "8")
|
|
548
503
|
}
|
|
549
504
|
}
|
|
550
505
|
|
|
@@ -557,12 +512,10 @@ public class ExpoIapModule: Module {
|
|
|
557
512
|
try await AppStore.sync()
|
|
558
513
|
return true
|
|
559
514
|
} catch {
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
"Error synchronizing with the AppStore: \(error.localizedDescription)"
|
|
565
|
-
])
|
|
515
|
+
if error is Exception {
|
|
516
|
+
throw error
|
|
517
|
+
}
|
|
518
|
+
throw Exception(name: "ExpoIapModule", description: "Error synchronizing with the AppStore: \(error.localizedDescription)", code: "9")
|
|
566
519
|
}
|
|
567
520
|
}
|
|
568
521
|
|
|
@@ -571,21 +524,14 @@ public class ExpoIapModule: Module {
|
|
|
571
524
|
SKPaymentQueue.default().presentCodeRedemptionSheet()
|
|
572
525
|
return true
|
|
573
526
|
#else
|
|
574
|
-
throw
|
|
575
|
-
domain: "ExpoIapModule", code: 10,
|
|
576
|
-
userInfo: [NSLocalizedDescriptionKey: "This method is not available on tvOS"])
|
|
527
|
+
throw Exception(name: "ExpoIapModule", description: "This method is not available on tvOS", code: "10")
|
|
577
528
|
#endif
|
|
578
529
|
}
|
|
579
530
|
|
|
580
531
|
AsyncFunction("showManageSubscriptions") { () -> Bool in
|
|
581
532
|
#if !os(tvOS)
|
|
582
533
|
guard let windowScene = await self.currentWindowScene() else {
|
|
583
|
-
throw
|
|
584
|
-
domain: "ExpoIapModule", code: 11,
|
|
585
|
-
userInfo: [
|
|
586
|
-
NSLocalizedDescriptionKey:
|
|
587
|
-
"Cannot find window scene or not available on macOS"
|
|
588
|
-
])
|
|
534
|
+
throw Exception(name: "ExpoIapModule", description: "Cannot find window scene or not available on macOS", code: "11")
|
|
589
535
|
}
|
|
590
536
|
// Get all subscription products before showing the management UI
|
|
591
537
|
let subscriptionSkus = await self.getAllSubscriptionProductIds()
|
|
@@ -596,9 +542,7 @@ public class ExpoIapModule: Module {
|
|
|
596
542
|
self.pollForSubscriptionStatusChanges()
|
|
597
543
|
return true
|
|
598
544
|
#else
|
|
599
|
-
throw
|
|
600
|
-
domain: "ExpoIapModule", code: 12,
|
|
601
|
-
userInfo: [NSLocalizedDescriptionKey: "This method is not available on tvOS"])
|
|
545
|
+
throw Exception(name: "ExpoIapModule", description: "This method is not available on tvOS", code: "12")
|
|
602
546
|
#endif
|
|
603
547
|
}
|
|
604
548
|
|
|
@@ -610,6 +554,9 @@ public class ExpoIapModule: Module {
|
|
|
610
554
|
await transaction.finish()
|
|
611
555
|
self.transactions.removeValue(forKey: String(transaction.id))
|
|
612
556
|
} catch {
|
|
557
|
+
if error is Exception {
|
|
558
|
+
throw error
|
|
559
|
+
}
|
|
613
560
|
print("Failed to finish transaction")
|
|
614
561
|
}
|
|
615
562
|
}
|
|
@@ -621,44 +568,26 @@ public class ExpoIapModule: Module {
|
|
|
621
568
|
guard let product = await self.productStore?.getProduct(productID: sku),
|
|
622
569
|
let result = await product.latestTransaction
|
|
623
570
|
else {
|
|
624
|
-
throw
|
|
625
|
-
domain: "ExpoIapModule", code: 5,
|
|
626
|
-
userInfo: [
|
|
627
|
-
NSLocalizedDescriptionKey:
|
|
628
|
-
"Can't find product or transaction for sku \(sku)"
|
|
629
|
-
])
|
|
571
|
+
throw Exception(name: "ExpoIapModule", description: "Can't find product or transaction for sku \(sku)", code: "5")
|
|
630
572
|
}
|
|
631
573
|
|
|
632
574
|
do {
|
|
633
575
|
let transaction = try self.checkVerified(result)
|
|
634
576
|
guard let windowScene = await self.currentWindowScene() else {
|
|
635
|
-
throw
|
|
636
|
-
domain: "ExpoIapModule", code: 11,
|
|
637
|
-
userInfo: [
|
|
638
|
-
NSLocalizedDescriptionKey:
|
|
639
|
-
"Cannot find window scene or not available on macOS"
|
|
640
|
-
])
|
|
577
|
+
throw Exception(name: "ExpoIapModule", description: "Cannot find window scene or not available on macOS", code: "11")
|
|
641
578
|
}
|
|
642
579
|
let refundStatus = try await transaction.beginRefundRequest(in: windowScene)
|
|
643
580
|
return serialize(refundStatus)
|
|
644
581
|
} catch StoreError.failedVerification {
|
|
645
|
-
throw
|
|
646
|
-
domain: "ExpoIapModule", code: 2,
|
|
647
|
-
userInfo: [
|
|
648
|
-
NSLocalizedDescriptionKey: "Failed to verify transaction for sku \(sku)"
|
|
649
|
-
])
|
|
582
|
+
throw Exception(name: "ExpoIapModule", description: "Failed to verify transaction for sku \(sku)", code: "2")
|
|
650
583
|
} catch {
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
"Failed to refund purchase: \(error.localizedDescription)"
|
|
656
|
-
])
|
|
584
|
+
if error is Exception {
|
|
585
|
+
throw error
|
|
586
|
+
}
|
|
587
|
+
throw Exception(name: "ExpoIapModule", description: "Failed to refund purchase: \(error.localizedDescription)", code: "3")
|
|
657
588
|
}
|
|
658
589
|
#else
|
|
659
|
-
throw
|
|
660
|
-
domain: "ExpoIapModule", code: 12,
|
|
661
|
-
userInfo: [NSLocalizedDescriptionKey: "This method is not available on tvOS"])
|
|
590
|
+
throw Exception(name: "ExpoIapModule", description: "This method is not available on tvOS", code: "12")
|
|
662
591
|
#endif
|
|
663
592
|
}
|
|
664
593
|
|
|
@@ -673,9 +602,7 @@ public class ExpoIapModule: Module {
|
|
|
673
602
|
|
|
674
603
|
AsyncFunction("isTransactionVerified") { (sku: String) -> Bool in
|
|
675
604
|
guard let productStore = self.productStore else {
|
|
676
|
-
throw
|
|
677
|
-
domain: "ExpoIapModule", code: 1,
|
|
678
|
-
userInfo: [NSLocalizedDescriptionKey: "Connection not initialized"])
|
|
605
|
+
throw Exception(name: "ExpoIapModule", description: "Connection not initialized", code: "1")
|
|
679
606
|
}
|
|
680
607
|
|
|
681
608
|
if let product = await productStore.getProduct(productID: sku),
|
|
@@ -693,26 +620,20 @@ public class ExpoIapModule: Module {
|
|
|
693
620
|
|
|
694
621
|
AsyncFunction("getTransactionJws") { (sku: String) -> String? in
|
|
695
622
|
guard let productStore = self.productStore else {
|
|
696
|
-
throw
|
|
697
|
-
domain: "ExpoIapModule", code: 1,
|
|
698
|
-
userInfo: [NSLocalizedDescriptionKey: "Connection not initialized"])
|
|
623
|
+
throw Exception(name: "ExpoIapModule", description: "Connection not initialized", code: "1")
|
|
699
624
|
}
|
|
700
625
|
|
|
701
626
|
if let product = await productStore.getProduct(productID: sku),
|
|
702
627
|
let result = await product.latestTransaction {
|
|
703
628
|
return result.jwsRepresentation
|
|
704
629
|
} else {
|
|
705
|
-
throw
|
|
706
|
-
domain: "ExpoIapModule", code: 5,
|
|
707
|
-
userInfo: [NSLocalizedDescriptionKey: "Can't find transaction for sku \(sku)"])
|
|
630
|
+
throw Exception(name: "ExpoIapModule", description: "Can't find transaction for sku \(sku)", code: "5")
|
|
708
631
|
}
|
|
709
632
|
}
|
|
710
633
|
|
|
711
634
|
AsyncFunction("validateReceiptIos") { (sku: String) -> [String: Any] in
|
|
712
635
|
guard let productStore = self.productStore else {
|
|
713
|
-
throw
|
|
714
|
-
domain: "ExpoIapModule", code: 1,
|
|
715
|
-
userInfo: [NSLocalizedDescriptionKey: "Connection not initialized"])
|
|
636
|
+
throw Exception(name: "ExpoIapModule", description: "Connection not initialized", code: "1")
|
|
716
637
|
}
|
|
717
638
|
|
|
718
639
|
// Get receipt data
|
|
@@ -897,17 +818,10 @@ public class ExpoIapModule: Module {
|
|
|
897
818
|
let receiptData = try Data(contentsOf: appStoreReceiptURL, options: .alwaysMapped)
|
|
898
819
|
return receiptData.base64EncodedString(options: [])
|
|
899
820
|
} catch {
|
|
900
|
-
throw
|
|
901
|
-
domain: "ExpoIapModule", code: 13,
|
|
902
|
-
userInfo: [
|
|
903
|
-
NSLocalizedDescriptionKey:
|
|
904
|
-
"Error reading receipt data: \(error.localizedDescription)"
|
|
905
|
-
])
|
|
821
|
+
throw Exception(name: "ExpoIapModule", description: "Error reading receipt data: \(error.localizedDescription)", code: "13")
|
|
906
822
|
}
|
|
907
823
|
} else {
|
|
908
|
-
throw
|
|
909
|
-
domain: "ExpoIapModule", code: 14,
|
|
910
|
-
userInfo: [NSLocalizedDescriptionKey: "App Store receipt not found"])
|
|
824
|
+
throw Exception(name: "ExpoIapModule", description: "App Store receipt not found", code: "14")
|
|
911
825
|
}
|
|
912
826
|
}
|
|
913
827
|
}
|