Esempio n. 1
0
    public async Task <Result <string> > VerifyValidEmailAndInviteCodeAsync(string email, string inviteCode)
    {
        var spec = new InvitationByInviteCodeSpec(inviteCode);

        string ValidEmailAndInviteCode = "success";

        try
        {
            var storedInviteCode = await _invitationRepository.GetBySpecAsync(spec);

            if (storedInviteCode == null)
            {
                throw new InvitationNotFoundException(inviteCode);
            }
            if (!storedInviteCode.Active)
            {
                throw new InvitationNotActiveException();
            }
            if (string.IsNullOrEmpty(storedInviteCode.Email))
            {
                throw new InvalidEmailException();
            }
        }
        catch (Exception e)
        {
            ValidEmailAndInviteCode = "Invalid email or invite code: " + e.GetType().ToString();
        }

        return(Result <string> .Success(ValidEmailAndInviteCode));
    }
Esempio n. 2
0
        public async Task <Member> MemberSetupAsync(string userId, string firstName, string lastName, string inviteCode)
        {
            Member member = await CreateNewMemberAsync(userId, firstName, lastName);

            await AddUserToMemberRoleAsync(userId);

            var spec = new InvitationByInviteCodeSpec(inviteCode);

            var invite = await _invitationRepository.GetBySpecAsync(spec);

            if (invite is null)
            {
                throw new InvitationNotFoundException(inviteCode);
            }
            var subscriptionId = invite.PaymentHandlerSubscriptionId;

            var subscriptionDateTimeRange = _paymentHandlerSubscription.GetDateTimeRange(subscriptionId);

            member.AddSubscription(subscriptionDateTimeRange);

            // Member has now been created and set up from the invite used. Invite should now be deactivated
            invite.Deactivate();
            await _invitationRepository.UpdateAsync(invite);

            return(member);
        }
Esempio n. 3
0
        public async Task <Member> MemberSetupAsync(string userId, string firstName, string lastName, string inviteCode)
        {
            Member member = CreateNewMember(userId, firstName, lastName);

            await AddUserToMemberRoleAsync(userId);

            var spec = new InvitationByInviteCodeSpec(inviteCode);

            var invite = await _repository.GetAsync(spec);

            var subscriptionId = invite.PaymentHandlerSubscriptionId;

            var subscriptionDateTimeRange = _paymentHandlerSubscription.GetDateTimeRange(subscriptionId);

            CreateSubscriptionForMember(member.Id, subscriptionDateTimeRange);

            // Member has now been created and set up from the invite used. Invite should now be deactivated
            invite.Deactivate();

            return(member);
        }
Esempio n. 4
0
    public async Task <Member> MemberSetupAsync(string userId,
                                                string firstName, string lastName, string inviteCode, string email)
    {
        Guard.Against.NullOrEmpty(inviteCode, nameof(inviteCode));
        Member member = await CreateNewMemberAsync(userId, firstName, lastName);

        await AddUserToMemberRoleAsync(userId);

        var spec   = new InvitationByInviteCodeSpec(inviteCode);
        var invite = await _invitationRepository.GetBySpecAsync(spec);

        _logger.LogInformation($"Looking up invitation with code {inviteCode}");
        if (invite is null)
        {
            throw new InvitationNotFoundException($"Could not find invitation with code {inviteCode}.");
        }
        var paymentHandlerSubscriptionId = invite.PaymentHandlerSubscriptionId;

        var subscriptionDateTimeRange = _paymentHandlerSubscription.GetDateTimeRange(paymentHandlerSubscriptionId);

        var billingPeriod = _paymentHandlerSubscription.GetBillingPeriod(paymentHandlerSubscriptionId);

        int devBetterSubscriptionPlanId = 1; // monthly

        if (billingPeriod == Enums.BillingPeriod.Year)
        {
            devBetterSubscriptionPlanId = 2; // yearly
        }

        member.AddSubscription(subscriptionDateTimeRange, devBetterSubscriptionPlanId);

        // Member has now been created and set up from the invite used. Invite should now be deactivated
        await DeactivateInviteAndDuplicates(invite);

        await AddNewSubscriberBillingActivity(invite.PaymentHandlerSubscriptionId, email);

        return(member);
    }