From bbb3001544469c99cd1a4cb2471b8ca0ab5f8dde Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Mon, 23 May 2022 19:05:31 -0400 Subject: [PATCH] tweak on receipt check --- internal/api/receipt.go | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/internal/api/receipt.go b/internal/api/receipt.go index 0de9177..bd74075 100644 --- a/internal/api/receipt.go +++ b/internal/api/receipt.go @@ -36,22 +36,19 @@ func (a *api) checkReceiptHandler(w http.ResponseWriter, r *http.Request) { } if iapr.DeleteDevice { - if dev.GracePeriodExpiresAt.After(time.Now()) { - w.WriteHeader(http.StatusOK) - return - } + if dev.GracePeriodExpiresAt.Before(time.Now()) { + accs, err := a.accountRepo.GetByAPNSToken(ctx, apns) + if err != nil { + a.errorResponse(w, r, 500, err) + return + } - accs, err := a.accountRepo.GetByAPNSToken(ctx, apns) - if err != nil { - a.errorResponse(w, r, 500, err) - return - } + for _, acc := range accs { + _ = a.accountRepo.Disassociate(ctx, &acc, &dev) + } - for _, acc := range accs { - _ = a.accountRepo.Disassociate(ctx, &acc, &dev) + _ = a.deviceRepo.Delete(ctx, apns) } - - _ = a.deviceRepo.Delete(ctx, apns) } else { dev.ExpiresAt = time.Now().Add(domain.DeviceActiveAfterReceitCheckDuration) dev.GracePeriodExpiresAt = dev.ExpiresAt.Add(domain.DeviceGracePeriodAfterReceiptExpiry)