Prevent IAP once a payment has been made

This commit is contained in:
Hillel Coren 2023-07-12 17:47:35 +03:00
parent 9877533ca8
commit 161a0864d2
3 changed files with 34 additions and 6 deletions

View File

@ -35,6 +35,7 @@ abstract class AccountEntity
setReactAsDefaultAP: false, setReactAsDefaultAP: false,
trialDaysLeft: 0, trialDaysLeft: 0,
hasIapPlan: false, hasIapPlan: false,
paymentId: '',
); );
} }
@ -107,6 +108,9 @@ abstract class AccountEntity
@BuiltValueField(wireName: 'has_iap_plan') @BuiltValueField(wireName: 'has_iap_plan')
bool get hasIapPlan; bool get hasIapPlan;
@BuiltValueField(wireName: 'payment_id')
String get paymentId;
bool get isUpdateAvailable { bool get isUpdateAvailable {
if (disableAutoUpdate) { if (disableAutoUpdate) {
return false; return false;
@ -141,7 +145,8 @@ abstract class AccountEntity
..hostedClientCount = 0 ..hostedClientCount = 0
..hostedCompanyCount = 1 ..hostedCompanyCount = 1
..accountSmsVerified = true ..accountSmsVerified = true
..setReactAsDefaultAP = false; ..setReactAsDefaultAP = false
..paymentId = '';
static Serializer<AccountEntity> get serializer => _$accountEntitySerializer; static Serializer<AccountEntity> get serializer => _$accountEntitySerializer;
} }

View File

@ -82,6 +82,9 @@ class _$AccountEntitySerializer implements StructuredSerializer<AccountEntity> {
'has_iap_plan', 'has_iap_plan',
serializers.serialize(object.hasIapPlan, serializers.serialize(object.hasIapPlan,
specifiedType: const FullType(bool)), specifiedType: const FullType(bool)),
'payment_id',
serializers.serialize(object.paymentId,
specifiedType: const FullType(String)),
]; ];
return result; return result;
@ -187,6 +190,10 @@ class _$AccountEntitySerializer implements StructuredSerializer<AccountEntity> {
result.hasIapPlan = serializers.deserialize(value, result.hasIapPlan = serializers.deserialize(value,
specifiedType: const FullType(bool)) as bool; specifiedType: const FullType(bool)) as bool;
break; break;
case 'payment_id':
result.paymentId = serializers.deserialize(value,
specifiedType: const FullType(String)) as String;
break;
} }
} }
@ -239,6 +246,8 @@ class _$AccountEntity extends AccountEntity {
final int trialDaysLeft; final int trialDaysLeft;
@override @override
final bool hasIapPlan; final bool hasIapPlan;
@override
final String paymentId;
factory _$AccountEntity([void Function(AccountEntityBuilder) updates]) => factory _$AccountEntity([void Function(AccountEntityBuilder) updates]) =>
(new AccountEntityBuilder()..update(updates))._build(); (new AccountEntityBuilder()..update(updates))._build();
@ -265,7 +274,8 @@ class _$AccountEntity extends AccountEntity {
this.setReactAsDefaultAP, this.setReactAsDefaultAP,
this.accountSmsVerified, this.accountSmsVerified,
this.trialDaysLeft, this.trialDaysLeft,
this.hasIapPlan}) this.hasIapPlan,
this.paymentId})
: super._() { : super._() {
BuiltValueNullFieldError.checkNotNull(id, r'AccountEntity', 'id'); BuiltValueNullFieldError.checkNotNull(id, r'AccountEntity', 'id');
BuiltValueNullFieldError.checkNotNull(key, r'AccountEntity', 'key'); BuiltValueNullFieldError.checkNotNull(key, r'AccountEntity', 'key');
@ -308,6 +318,8 @@ class _$AccountEntity extends AccountEntity {
trialDaysLeft, r'AccountEntity', 'trialDaysLeft'); trialDaysLeft, r'AccountEntity', 'trialDaysLeft');
BuiltValueNullFieldError.checkNotNull( BuiltValueNullFieldError.checkNotNull(
hasIapPlan, r'AccountEntity', 'hasIapPlan'); hasIapPlan, r'AccountEntity', 'hasIapPlan');
BuiltValueNullFieldError.checkNotNull(
paymentId, r'AccountEntity', 'paymentId');
} }
@override @override
@ -342,7 +354,8 @@ class _$AccountEntity extends AccountEntity {
setReactAsDefaultAP == other.setReactAsDefaultAP && setReactAsDefaultAP == other.setReactAsDefaultAP &&
accountSmsVerified == other.accountSmsVerified && accountSmsVerified == other.accountSmsVerified &&
trialDaysLeft == other.trialDaysLeft && trialDaysLeft == other.trialDaysLeft &&
hasIapPlan == other.hasIapPlan; hasIapPlan == other.hasIapPlan &&
paymentId == other.paymentId;
} }
int __hashCode; int __hashCode;
@ -372,6 +385,7 @@ class _$AccountEntity extends AccountEntity {
_$hash = $jc(_$hash, accountSmsVerified.hashCode); _$hash = $jc(_$hash, accountSmsVerified.hashCode);
_$hash = $jc(_$hash, trialDaysLeft.hashCode); _$hash = $jc(_$hash, trialDaysLeft.hashCode);
_$hash = $jc(_$hash, hasIapPlan.hashCode); _$hash = $jc(_$hash, hasIapPlan.hashCode);
_$hash = $jc(_$hash, paymentId.hashCode);
_$hash = $jf(_$hash); _$hash = $jf(_$hash);
return __hashCode ??= _$hash; return __hashCode ??= _$hash;
} }
@ -400,7 +414,8 @@ class _$AccountEntity extends AccountEntity {
..add('setReactAsDefaultAP', setReactAsDefaultAP) ..add('setReactAsDefaultAP', setReactAsDefaultAP)
..add('accountSmsVerified', accountSmsVerified) ..add('accountSmsVerified', accountSmsVerified)
..add('trialDaysLeft', trialDaysLeft) ..add('trialDaysLeft', trialDaysLeft)
..add('hasIapPlan', hasIapPlan)) ..add('hasIapPlan', hasIapPlan)
..add('paymentId', paymentId))
.toString(); .toString();
} }
} }
@ -506,6 +521,10 @@ class AccountEntityBuilder
bool get hasIapPlan => _$this._hasIapPlan; bool get hasIapPlan => _$this._hasIapPlan;
set hasIapPlan(bool hasIapPlan) => _$this._hasIapPlan = hasIapPlan; set hasIapPlan(bool hasIapPlan) => _$this._hasIapPlan = hasIapPlan;
String _paymentId;
String get paymentId => _$this._paymentId;
set paymentId(String paymentId) => _$this._paymentId = paymentId;
AccountEntityBuilder() { AccountEntityBuilder() {
AccountEntity._initializeBuilder(this); AccountEntity._initializeBuilder(this);
} }
@ -535,6 +554,7 @@ class AccountEntityBuilder
_accountSmsVerified = $v.accountSmsVerified; _accountSmsVerified = $v.accountSmsVerified;
_trialDaysLeft = $v.trialDaysLeft; _trialDaysLeft = $v.trialDaysLeft;
_hasIapPlan = $v.hasIapPlan; _hasIapPlan = $v.hasIapPlan;
_paymentId = $v.paymentId;
_$v = null; _$v = null;
} }
return this; return this;
@ -588,7 +608,8 @@ class AccountEntityBuilder
setReactAsDefaultAP: BuiltValueNullFieldError.checkNotNull(setReactAsDefaultAP, r'AccountEntity', 'setReactAsDefaultAP'), setReactAsDefaultAP: BuiltValueNullFieldError.checkNotNull(setReactAsDefaultAP, r'AccountEntity', 'setReactAsDefaultAP'),
accountSmsVerified: BuiltValueNullFieldError.checkNotNull(accountSmsVerified, r'AccountEntity', 'accountSmsVerified'), accountSmsVerified: BuiltValueNullFieldError.checkNotNull(accountSmsVerified, r'AccountEntity', 'accountSmsVerified'),
trialDaysLeft: BuiltValueNullFieldError.checkNotNull(trialDaysLeft, r'AccountEntity', 'trialDaysLeft'), trialDaysLeft: BuiltValueNullFieldError.checkNotNull(trialDaysLeft, r'AccountEntity', 'trialDaysLeft'),
hasIapPlan: BuiltValueNullFieldError.checkNotNull(hasIapPlan, r'AccountEntity', 'hasIapPlan')); hasIapPlan: BuiltValueNullFieldError.checkNotNull(hasIapPlan, r'AccountEntity', 'hasIapPlan'),
paymentId: BuiltValueNullFieldError.checkNotNull(paymentId, r'AccountEntity', 'paymentId'));
replace(_$result); replace(_$result);
return _$result; return _$result;
} }

View File

@ -389,7 +389,9 @@ class _AccountOverview extends StatelessWidget {
), ),
), ),
onPressed: () { onPressed: () {
if (supportsInAppPurchase() && !account.hasIapPlan) { if (supportsInAppPurchase() &&
!account.hasIapPlan &&
account.paymentId.isEmpty) {
showDialog<void>( showDialog<void>(
context: context, context: context,
builder: (context) => UpgradeDialog(), builder: (context) => UpgradeDialog(),