feat: request apply subscription mutation (#13844)
This commit is contained in:
@@ -71,6 +71,7 @@ struct PurchaseFooterView: View {
|
||||
.foregroundStyle(AffineColors.textSecondary.color)
|
||||
.opacity(viewModel.products.isEmpty ? 0 : 1)
|
||||
.disabled(isPurchased)
|
||||
.disabled(viewModel.updating)
|
||||
|
||||
Text("The Monthly and Annual plans renew automatically, but you’re free to cancel at any time if it’s not right for you.")
|
||||
.font(.system(size: 12))
|
||||
|
||||
@@ -31,8 +31,18 @@ extension ViewModel {
|
||||
switch result {
|
||||
case .pending:
|
||||
break
|
||||
case let .success(transaction):
|
||||
print("purchase success", transaction)
|
||||
case let .success(verificationResult):
|
||||
switch verificationResult {
|
||||
case .verified(let transaction):
|
||||
print("purchase success", transaction)
|
||||
try await self.applySubscription(transactionID: .init(transaction.id))
|
||||
case .unverified:
|
||||
#if DEBUG
|
||||
break
|
||||
#else
|
||||
throw NSError() // should not happening
|
||||
#endif
|
||||
}
|
||||
shouldDismiss = true
|
||||
case .userCancelled:
|
||||
break
|
||||
@@ -93,6 +103,21 @@ extension ViewModel {
|
||||
|
||||
associatedController?.dismiss(animated: true)
|
||||
}
|
||||
|
||||
func applySubscription(transactionID: String) async throws {
|
||||
print(#function, transactionID)
|
||||
|
||||
if let context = associatedWebContext {
|
||||
_ = try await context.callAsyncJavaScript(
|
||||
"return await window.requestApplySubscription('\(transactionID)');",
|
||||
contentWorld: .page
|
||||
)
|
||||
print("requestApplySubscription success")
|
||||
} else {
|
||||
assertionFailure()
|
||||
throw NSError()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nonisolated extension ViewModel {
|
||||
|
||||
Reference in New Issue
Block a user