Purpl Docs
권한과 복원
현재 고객의 활성 권한을 확인하고 Google Play 구매 내역을 복원합니다.
권한 확인
Kotlin
val customerInfo = purchases.customerInfo()
if (customerInfo.isEntitlementActive("plus")) {
enablePremiumFeatures()
}Google Play 모드의 CustomerInfo는 현재 Play 구매의 서명을 검증하고 PurchaseConfiguration의 상품과 매칭해 계산합니다. 기기 검증만으로는 구독 만료일과 현재 기본 요금제를 알 수 없어 expiresAt, basePlanIdentifier와 offerIdentifier는 null입니다.
Compose에서 권한 상태 관찰
customerInfoFlow는 구매, 복원과 앱 복귀로 권한이 바뀔 때마다 새 CustomerInfo를 전달하는 StateFlow입니다. Compose에서는 collectAsStateWithLifecycle로 관찰합니다.
Compose
@Composable
fun PlusScreen(purchases: Purchases) {
val customerInfo by purchases.customerInfoFlow.collectAsStateWithLifecycle()
val hasPlusAccess = customerInfo?.isEntitlementActive("plus") == true
ContentScreen(hasPlusAccess = hasPlusAccess)
}구매 복원
Kotlin
val customerInfo = purchases.restorePurchases()