private async Task <IPaymentRequest> TryCheckoutAsync(IPaymentRequest paymentRequest, bool force) { bool locked = await _checkoutLocksService.TryAcquireLockAsync( paymentRequest.Id, paymentRequest.MerchantId, paymentRequest.DueDate); if (!locked) { throw new DistributedLockAcquireException(paymentRequest.Id); } try { await _walletsManager.EnsureBcnAddressAllocated(paymentRequest.MerchantId, paymentRequest.WalletAddress, paymentRequest.PaymentAssetId); IOrder order = await _orderService.GetLatestOrCreateAsync(paymentRequest, force); if (paymentRequest.OrderId != order.Id) { paymentRequest.OrderId = order.Id; await _paymentRequestRepository.UpdateAsync(paymentRequest); } } finally { await _checkoutLocksService.ReleaseLockAsync(paymentRequest.Id, paymentRequest.MerchantId); } return(paymentRequest); }
public async Task <IPaymentRequest> CheckoutAsync(string merchantId, string paymentRequestId, bool force) { IPaymentRequest paymentRequest = await _paymentRequestRepository.GetAsync(merchantId, paymentRequestId); if (paymentRequest == null) { throw new PaymentRequestNotFoundException(merchantId, paymentRequestId); } // Don't create new order if payment reqest status not new. if (paymentRequest.Status != PaymentRequestStatus.New) { return(paymentRequest); } await _walletsManager.EnsureBcnAddressAllocated(paymentRequest.MerchantId, paymentRequest.WalletAddress, paymentRequest.PaymentAssetId); IOrder order = await _orderService.GetLatestOrCreateAsync(paymentRequest, force); if (paymentRequest.OrderId != order.Id) { paymentRequest.OrderId = order.Id; await _paymentRequestRepository.UpdateAsync(paymentRequest); await _log.WriteInfoAsync(nameof(PaymentRequestService), nameof(CheckoutAsync), paymentRequest.ToJson(), "Payment request order updated."); } return(paymentRequest); }