private async Task TryUpdatePayment(string referenceCode, string paymentId, PaymentStatuses status) { var payments = await _context.Payments .Where(p => p.ReferenceCode == referenceCode) .ToListAsync(); var payment = payments.Where(p => { var data = JsonConvert.DeserializeObject <CreditCardPaymentInfo>(p.Data); return(data.ExternalId == paymentId); }) .SingleOrDefault(); // Payment not found if (payment is null) { return; } // Payment status not changed if (status == payment.Status) { return; } // Payment already captured if (status == PaymentStatuses.Authorized && payment.Status == PaymentStatuses.Captured) { return; } _logger.LogNGeniusWebhookPaymentUpdate(); await _paymentService.SetStatus(payment, status); }
private OrderStates SetPaymentStatus(PaymentStatuses paymentStatus) { return(paymentStatus switch { PaymentStatuses.Completed => OrderStates.PaymentCompleted, PaymentStatuses.Failed => OrderStates.PaymentFailed, _ => throw new ArgumentOutOfRangeException(nameof(paymentStatus), paymentStatus, null) });
public async Task <Result> SetStatus(Payment payment, PaymentStatuses status) { payment.Status = status; payment.Modified = _dateTimeProvider.UtcNow(); _context.Update(payment); await _context.SaveChangesAsync(); await _bookingPaymentCallbackService.ProcessPaymentChanges(payment); return(Result.Success()); }
/// <summary> /// Deserializes the response into an object of the specified type. /// </summary> public void Deserialize(Type type, string input, object objectToDeserializeInto) { if (string.IsNullOrEmpty(input)) { return; } var bits = input.Split(new[] { "&" }, StringSplitOptions.RemoveEmptyEntries); foreach (var nameValuePairCombined in bits) { int index = nameValuePairCombined.IndexOf('='); if (index < 0) { Logging.LogMessage("Could not deserialize NameValuePair: " + nameValuePairCombined); continue; } string name = nameValuePairCombined.Substring(0, index); string value = nameValuePairCombined.Substring(index + 1); PropertyInfo prop = type.GetProperty(name, BindingFlags.Public | BindingFlags.Instance); if (prop == null) { // Ignore any additional NVPs that we don't have properties for instead of throwing exception // This does mean we only capture the first of any errors returned into L_ERRORCODE0 etc continue; // throw new InvalidOperationException(string.Format("Could not find a property on Type '{0}' named '{1}'", type.Name, name)); } object convertedValue; if (prop.PropertyType == typeof(ResponseType)) { convertedValue = ResponseTypes.ConvertStringToPayPalResponseType(value); } else if (prop.PropertyType == typeof(CheckoutStatus)) { convertedValue = CheckoutStatuses.ConvertStringToPayPalCheckoutStatus(value); } else if (prop.PropertyType == typeof(PaymentStatus)) { convertedValue = PaymentStatuses.ConvertStringToPayPalCheckoutStatus(value); } else { convertedValue = Convert.ChangeType(value, prop.PropertyType); } prop.SetValue(objectToDeserializeInto, convertedValue, null); } }
private async Task TryUpdatePaymentLink(string referenceCode, PaymentStatuses status) { var paymentLink = await _context.PaymentLinks .Where(l => l.ReferenceCode == referenceCode) .SingleOrDefaultAsync(); if (paymentLink is null) { return; } // Only Captured status processed if (status is not PaymentStatuses.Captured) { return; } _logger.LogNGeniusWebhookPaymentLinkUpdate(); await _paymentLinksProcessingService.ProcessNGeniusWebhook(paymentLink.Code, CreditCardPaymentStatuses.Success); }