Skip to content

Commit

Permalink
Send notification to donor when certificate provider signs
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx committed Jan 3, 2025
1 parent 303a205 commit 0e73251
Show file tree
Hide file tree
Showing 4 changed files with 455 additions and 4 deletions.
65 changes: 61 additions & 4 deletions cmd/event-received/lpastore_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ func (h *lpastoreEventHandler) Handle(ctx context.Context, factory factory, clou

return handleCreate(ctx, factory.DynamoClient(), lpaStoreClient, notifyClient, bundle, v)

case "CERTIFICATE_PROVIDER_SIGN":
lpaStoreClient, err := factory.LpaStoreClient()
if err != nil {
return fmt.Errorf("could not create LpaStoreClient: %w", err)
}

bundle, err := factory.Bundle()
if err != nil {
return fmt.Errorf("could not load Bundle: %w", err)
}

notifyClient, err := factory.NotifyClient(ctx)
if err != nil {
return fmt.Errorf("could not create NotifyClient: %w", err)
}

return handleCertificateProviderSign(ctx, factory.DynamoClient(), lpaStoreClient, notifyClient, bundle, v)

case "REGISTER":
lpaStoreClient, err := factory.LpaStoreClient()
if err != nil {
Expand Down Expand Up @@ -78,10 +96,12 @@ func handleCreate(ctx context.Context, client dynamodbClient, lpaStoreClient Lpa
localizer := bundle.For(lpa.Donor.ContactLanguagePreference)

if lpa.Donor.Channel.IsPaper() {
if err := notifyClient.SendActorSMS(ctx, notify.ToLpaDonor(lpa), v.UID, notify.PaperDonorLpaSubmittedSMS{
LpaType: localizer.T(lpa.Type.String()),
}); err != nil {
return fmt.Errorf("error sending sms: %w", err)
if lpa.Donor.Mobile != "" {
if err := notifyClient.SendActorSMS(ctx, notify.ToLpaDonor(lpa), v.UID, notify.PaperDonorLpaSubmittedSMS{
LpaType: localizer.T(lpa.Type.String()),
}); err != nil {
return fmt.Errorf("error sending sms: %w", err)
}
}

return nil
Expand All @@ -102,6 +122,43 @@ func handleCreate(ctx context.Context, client dynamodbClient, lpaStoreClient Lpa
return nil
}

func handleCertificateProviderSign(ctx context.Context, client dynamodbClient, lpaStoreClient LpaStoreClient, notifyClient NotifyClient, bundle Bundle, v lpaUpdatedEvent) error {
lpa, err := lpaStoreClient.Lpa(ctx, v.UID)
if err != nil {
return fmt.Errorf("error getting lpa: %w", err)
}

localizer := bundle.For(lpa.Donor.ContactLanguagePreference)

if lpa.Donor.Channel.IsPaper() {
if lpa.Donor.Mobile != "" {
if err := notifyClient.SendActorSMS(ctx, notify.ToLpaDonor(lpa), v.UID, notify.PaperDonorCertificateProvidedSMS{
CertificateProviderFullName: lpa.CertificateProvider.FullName(),
LpaType: localizer.T(lpa.Type.String()),
}); err != nil {
return fmt.Errorf("error sending sms: %w", err)
}
}

return nil
}

donor, err := getDonorByLpaUID(ctx, client, v.UID)
if err != nil {
return fmt.Errorf("error getting donor: %w", err)
}

if err := notifyClient.SendActorEmail(ctx, notify.ToDonor(donor), v.UID, notify.DigitalDonorCertificateProvidedEmail{
Greeting: notifyClient.EmailGreeting(lpa),
CertificateProviderFullName: lpa.CertificateProvider.FullName(),
LpaType: localizer.T(lpa.Type.String()),
}); err != nil {
return fmt.Errorf("error sending email: %w", err)
}

return nil
}

func handleRegister(ctx context.Context, client dynamodbClient, lpaStoreClient LpaStoreClient, eventClient EventClient, v lpaUpdatedEvent) error {
lpa, err := lpaStoreClient.Lpa(ctx, v.UID)
if err != nil {
Expand Down
Loading

0 comments on commit 0e73251

Please sign in to comment.