feat: iap (#1996)
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { AppleIAPProductId } from './../Subscription/AppleIAPProductId'
|
||||
import { DeviceInterface } from './DeviceInterface'
|
||||
import { Environment, Platform, RawKeychainValue } from '@standardnotes/models'
|
||||
import { AppleIAPReceipt } from '../Subscription/AppleIAPReceipt'
|
||||
|
||||
export interface MobileDeviceInterface extends DeviceInterface {
|
||||
environment: Environment.Mobile
|
||||
@@ -22,4 +24,5 @@ export interface MobileDeviceInterface extends DeviceInterface {
|
||||
isUrlComponentUrl(url: string): boolean
|
||||
getAppState(): Promise<'active' | 'background' | 'inactive' | 'unknown' | 'extension'>
|
||||
getColorScheme(): Promise<'light' | 'dark' | null | undefined>
|
||||
purchaseSubscriptionIAP(plan: AppleIAPProductId): Promise<AppleIAPReceipt | undefined>
|
||||
}
|
||||
|
||||
@@ -64,4 +64,5 @@ export enum ApplicationEvent {
|
||||
CompletedInitialSync = 30,
|
||||
BiometricsSoftLockEngaged = 31,
|
||||
BiometricsSoftLockDisengaged = 32,
|
||||
DidPurchaseSubscription = 33,
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export enum FeaturesEvent {
|
||||
UserRolesChanged = 'UserRolesChanged',
|
||||
FeaturesUpdated = 'FeaturesUpdated',
|
||||
DidPurchaseSubscription = 'DidPurchaseSubscription',
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
export enum AppleIAPProductId {
|
||||
ProPlanYearly = 'pro_plan_yearly',
|
||||
PlusPlanYearly = 'plus_plan_yearly',
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { AppleIAPProductId } from './AppleIAPProductId'
|
||||
|
||||
export type AppleIAPReceipt = {
|
||||
productId: AppleIAPProductId
|
||||
transactionDate: string
|
||||
transactionId: string
|
||||
transactionReceipt: string
|
||||
}
|
||||
@@ -1,9 +1,14 @@
|
||||
import { Uuid } from '@standardnotes/common'
|
||||
import { Invitation } from '@standardnotes/models'
|
||||
import { AppleIAPReceipt } from './AppleIAPReceipt'
|
||||
|
||||
export interface SubscriptionClientInterface {
|
||||
listSubscriptionInvitations(): Promise<Invitation[]>
|
||||
inviteToSubscription(inviteeEmail: string): Promise<boolean>
|
||||
cancelInvitation(inviteUuid: Uuid): Promise<boolean>
|
||||
acceptInvitation(inviteUuid: Uuid): Promise<{ success: true } | { success: false; message: string }>
|
||||
confirmAppleIAP(
|
||||
receipt: AppleIAPReceipt,
|
||||
subscriptionToken: string,
|
||||
): Promise<{ success: true } | { success: false; message: string }>
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { InternalEventBusInterface } from '../Internal/InternalEventBusInterface
|
||||
import { AbstractService } from '../Service/AbstractService'
|
||||
import { SubscriptionClientInterface } from './SubscriptionClientInterface'
|
||||
import { Uuid } from '@standardnotes/common'
|
||||
import { AppleIAPReceipt } from './AppleIAPReceipt'
|
||||
|
||||
export class SubscriptionManager extends AbstractService implements SubscriptionClientInterface {
|
||||
constructor(
|
||||
@@ -56,4 +57,24 @@ export class SubscriptionManager extends AbstractService implements Subscription
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
async confirmAppleIAP(
|
||||
params: AppleIAPReceipt,
|
||||
subscriptionToken: string,
|
||||
): Promise<{ success: true } | { success: false; message: string }> {
|
||||
try {
|
||||
const result = await this.subscriptionApiService.confirmAppleIAP({
|
||||
...params,
|
||||
subscription_token: subscriptionToken,
|
||||
})
|
||||
|
||||
if (result.data.error) {
|
||||
return { success: false, message: result.data.error.message }
|
||||
}
|
||||
|
||||
return result.data
|
||||
} catch (error) {
|
||||
return { success: false, message: 'Could not confirm IAP.' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,8 @@ export * from './Strings/InfoStrings'
|
||||
export * from './Strings/Messages'
|
||||
export * from './Subscription/SubscriptionClientInterface'
|
||||
export * from './Subscription/SubscriptionManager'
|
||||
export * from './Subscription/AppleIAPProductId'
|
||||
export * from './Subscription/AppleIAPReceipt'
|
||||
export * from './Sync/SyncMode'
|
||||
export * from './Sync/SyncOptions'
|
||||
export * from './Sync/SyncQueueStrategy'
|
||||
|
||||
Reference in New Issue
Block a user