syncAttributesAndOfferingsIfNeeded method
Implementation
@override
Future<InappifySdkResult<OfferingsModel>>
syncAttributesAndOfferingsIfNeeded() {
if (!_supportsTargetingSync) {
return Future.value(
InappifySdkResult<OfferingsModel>.failure(
InappifyFailure.unsupported('syncAttributesAndOfferingsIfNeeded'),
snapshot: _snapshot,
),
);
}
return _run<OfferingsModel>(
'syncAttributesAndOfferingsIfNeeded',
action: () async {
final identityRevision = _identityRevision;
try {
final raw = await _bridge.call('syncAttributesAndOfferingsIfNeeded');
if (identityRevision != _identityRevision) {
throw const InappifyWebBridgeException(
code: 'CUSTOMER_INFO_REQUEST_SUPERSEDED',
kind: 'configuration',
);
}
final offerings = InappifyWebPayloadCodec.offerings(raw);
_commitOfferings(offerings);
_failedToLoadOfferings = false;
return offerings;
} catch (_) {
if (identityRevision == _identityRevision) {
_failedToLoadOfferings = true;
}
rethrow;
} finally {
// This also keeps a successful customer refresh when the following
// offerings read fails. Never fetch again or fall back to success.
if (identityRevision == _identityRevision) {
_readCustomerPropertyBestEffort();
}
}
},
);
}