public async Task HandleCustomerSubscriptionCancelledAtPeriodEndAsync(string json)
    {
        var paymentHandlerEvent    = _paymentHandlerEventService.FromJson(json);
        var customerId             = _paymentHandlerSubscription.GetCustomerId(paymentHandlerEvent.SubscriptionId);
        var paymentHandlerCustomer = _paymentHandlerCustomerService.GetCustomer(customerId);

        await _memberCancellationService.SendFutureCancellationEmailAsync(paymentHandlerCustomer.Email);

        var subscriptionPlanName = _paymentHandlerSubscription.GetAssociatedProductName(paymentHandlerEvent.SubscriptionId);
        var billingPeriod        = _paymentHandlerSubscription.GetBillingPeriod(paymentHandlerEvent.SubscriptionId);
        await _memberAddBillingActivityService.AddMemberSubscriptionCancellationBillingActivity(paymentHandlerCustomer.Email, subscriptionPlanName, billingPeriod);
    }
Пример #2
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);
    }