Exemplo n.º 1
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);
        }
        private async Task HandleNewCustomerSubscriptionWithEmailAlreadyMember(string subscriptionId, decimal paymentAmount)
        {
            var customerId = _paymentHandlerSubscription.GetCustomerId(subscriptionId);
            var email      = _paymentHandlerCustomer.GetCustomerEmail(customerId);

            await AddNewSubscriberBillingActivity(subscriptionId, email, paymentAmount);

            var subscriptionDateTimeRange = _paymentHandlerSubscription.GetDateTimeRange(subscriptionId);

            var userId = await _userLookupService.FindUserIdByEmailAsync(email);

            var spec   = new MemberByUserIdSpec(userId);
            var member = await _repository.GetBySpecAsync(spec);

            if (member != null)
            {
                member.AddSubscription(subscriptionDateTimeRange);
            }
        }
    private async Task HandleNewCustomerSubscriptionWithEmailAlreadyMember(string subscriptionId, decimal paymentAmount)
    {
        var customerId             = _paymentHandlerSubscription.GetCustomerId(subscriptionId);
        var paymentHandlerCustomer = _paymentHandlerCustomerService.GetCustomer(customerId);

        await AddNewSubscriberBillingActivity(subscriptionId, paymentHandlerCustomer.Email, paymentAmount);

        var subscriptionDateTimeRange = _paymentHandlerSubscription.GetDateTimeRange(subscriptionId);

        var userId = await _userLookupService.FindUserIdByEmailAsync(paymentHandlerCustomer.Email);

        var spec   = new MemberByUserIdSpec(userId);
        var member = await _repository.GetBySpecAsync(spec);

        if (member != null)
        {
            // TODO this should take in the subscription plan id - currently hard-coded to monthly
            member.AddSubscription(subscriptionDateTimeRange, 1);
        }
    }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
    }