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); }
public async Task <IPaymentRequest> CreateAsync(IPaymentRequest paymentRequest) { paymentRequest.Status = PaymentRequestStatus.New; paymentRequest.Timestamp = DateTime.UtcNow; DateTime walletDueDate = paymentRequest.DueDate.Add(_expirationPeriods.WalletExtra); IVirtualWallet wallet = await _walletsManager.CreateAsync(paymentRequest.MerchantId, walletDueDate); paymentRequest.WalletAddress = wallet.Id; IPaymentRequest createdPaymentRequest = await _paymentRequestRepository.InsertAsync(paymentRequest); _log.Info("Payment request created", paymentRequest.ToJson()); return(createdPaymentRequest); }