Esempio n. 1
0
 public async Task <IActionResult> GetAll()
 {
     return(Json(await _merchantOrderRequestRepository.GetAllAsync()));
 }
Esempio n. 2
0
        private async Task ProcessOrders()
        {
            var orders = await _merchantOrderRepo.GetAllAsync();


            foreach (var r in orders)
            {
                bool needSave = false;
                if ((r.MerchantPayRequestNotification & MerchantPayRequestNotification.Success) ==
                    MerchantPayRequestNotification.Success &&
                    !string.IsNullOrEmpty(r.SuccessUrl))
                {
                    await PostInfo(r.SuccessUrl, JsonConvert.SerializeObject(new PaymentSuccessReturn
                    {
                        PaymentResponse = new PaymentSuccessResponse
                        {
                            TransactionId        = r.TransactionId,
                            Currency             = r.AssetId,
                            NumberOfConfirmation = GetNumberOfConfirmation(r.SourceAddress, r.TransactionId),
                            TimeStamp            = DateTime.UtcNow.Ticks,
                            Url = $"{_settings.LykkePayBaseUrl}transaction/{r.TransactionId}"
                        }
                    }
                                                                             ), BroadcastType.Order, BroadcastMessageType.Success);

                    needSave = true;
                    r.MerchantPayRequestNotification &= ~MerchantPayRequestNotification.Success;
                }

                if ((r.MerchantPayRequestNotification & MerchantPayRequestNotification.InProgress) ==
                    MerchantPayRequestNotification.InProgress &&
                    !string.IsNullOrEmpty(r.ProgressUrl))
                {
                    await PostInfo(r.ProgressUrl, JsonConvert.SerializeObject(new PaymentInProgressReturn
                    {
                        PaymentResponse = new PaymentInProgressResponse
                        {
                            Settlement    = Settlement.TRANSACTION_DETECTED,
                            TimeStamp     = DateTime.UtcNow.Ticks,
                            Currency      = r.AssetId,
                            TransactionId = r.TransactionId
                        }
                    }), BroadcastType.Order, BroadcastMessageType.Process);

                    needSave = true;
                    r.MerchantPayRequestNotification &= ~MerchantPayRequestNotification.InProgress;
                }

                if ((r.MerchantPayRequestNotification & MerchantPayRequestNotification.Error) ==
                    MerchantPayRequestNotification.Error &&
                    !string.IsNullOrEmpty(r.ErrorUrl))
                {
                    var transferStatus = string.IsNullOrEmpty(r.TransactionStatus)
                        ? InvoiceStatus.Unpaid
                        : r.TransactionStatus.ParsePayEnum <InvoiceStatus>();
                    PaymentError paymentError;
                    switch (transferStatus)
                    {
                    case InvoiceStatus.Draft:
                    case InvoiceStatus.InProgress:
                    case InvoiceStatus.Paid:
                    case InvoiceStatus.Removed:
                        paymentError = PaymentError.TRANSACTION_NOT_DETECTED;
                        break;

                    case InvoiceStatus.LatePaid:
                    case InvoiceStatus.Unpaid:
                        paymentError = PaymentError.PAYMENT_EXPIRED;
                        break;

                    case InvoiceStatus.Overpaid:
                        paymentError = PaymentError.AMOUNT_ABOVE;
                        break;

                    case InvoiceStatus.Underpaid:
                        paymentError = PaymentError.AMOUNT_BELOW;
                        break;

                    default:
                        paymentError = PaymentError.TRANSACTION_NOT_DETECTED;
                        break;
                    }
                    await PostInfo(r.ErrorUrl, JsonConvert.SerializeObject(
                                       new PaymentErrorReturn
                    {
                        PaymentResponse = new PaymentErrorResponse
                        {
                            PaymentError = paymentError,
                            TimeStamp    = DateTime.UtcNow.Ticks
                        }
                    }), BroadcastType.Order, BroadcastMessageType.Error);

                    needSave = true;
                    r.MerchantPayRequestNotification &= ~MerchantPayRequestNotification.Error;
                }

                if (needSave)
                {
                    await _merchantOrderRepo.SaveRequestAsync(r);
                }
            }
        }