Esempio n. 1
0
 public DonationDto UpdateDonationStatusFromPushpay(PushpayWebhook webhook, bool retry = false)
 {
     try {
         var pushpayPayment = _pushpayClient.GetPayment(webhook);
         // PushPay creates the donation a variable amount of time after the webhook comes in
         //   so it still may not be available
         var donation = _donationService.GetDonationByTransactionCode(pushpayPayment.TransactionId);
         if (pushpayPayment.IsStatusNew || pushpayPayment.IsStatusProcessing)
         {
             donation.DonationStatusId = _mpDonationStatusPending;
         }
         else if (pushpayPayment.IsStatusSuccess)
         {
             donation.DonationStatusId = _mpDonationStatusSucceeded;
         }
         else if (pushpayPayment.IsStatusFailed)
         {
             donation.DonationStatusId = _mpDonationStatusDeclined;
         }
         _donationService.Update(donation);
         return(donation);
     } catch (Exception e) {
         // donation not created by pushpay yet
         var now         = DateTime.UtcNow;
         var webhookTime = webhook.IncomingTimeUtc;
         // if it's been less than ten minutes, try again in a minute
         if ((now - webhookTime).TotalMinutes < maxRetryMinutes && retry)
         {
             AddUpdateDonationStatusFromPushpayJob(webhook);
             // dont throw an exception as Hangfire tries to handle it
             _logger.Error($"Payment: {webhook.Events[0].Links.Payment} not found in MP. Trying again in a minute.", e);
             return(null);
         }
         // it's been more than 10 minutes, let's chalk it up as PushPay
         //   ain't going to create it and call it a day
         else
         {
             // dont throw an exception as Hangfire tries to handle it
             _logger.Error($"Payment: {webhook.Events[0].Links.Payment} not found in MP after 10 minutes of trying. Giving up.", e);
             return(null);
         }
     }
 }
Esempio n. 2
0
        public void ShouldGetDonationByTransactionCode()
        {
            // Arrange
            var transactionCode = "111aaa222bbb";

            var donationDto = new DonationDto
            {
            };

            var mpDonation = new MpDonation()
            {
            };

            _mapper.Setup(m => m.Map <MpDonation>(It.IsAny <DonationDto>())).Returns(mpDonation);
            _mapper.Setup(m => m.Map <DonationDto>(It.IsAny <MpDonation>())).Returns(donationDto);
            _donationRepository.Setup(m => m.GetDonationByTransactionCode(It.IsAny <string>())).Returns(mpDonation);

            // Act
            var result = _fixture.GetDonationByTransactionCode(transactionCode);

            // Assert
            Assert.NotNull(result);
        }