createLink method
Gets or creates the current user's referral link and code. Needs
Clikgate.identifyUser.
The link saved on the phone for the signed-in customer answers at once
(offline too) and is refreshed in the background; links are prepared
after Clikgate.identifyUser once Engage is used, and cleared on
sign-out or when another customer signs in.
Implementation
Future<ReferralLink> createLink(
{required String programId, String? displayName}) async {
_requireId(programId, 'program_id');
final saved = await _savedLinks.saved(programId);
final link = saved.link;
if (displayName == null && link != null) {
unawaited(_fetch(programId, null, saved.token).then((_) {}, onError: (_) {}));
return ReferralLink.fromJson(link);
}
return _fetch(programId, displayName, saved.token);
}