public async Task <IActionResult> GetUserImage([FromRoute, SwaggerParameter("匯款申請單id", Required = true)] long remitId,
                                                       [FromRoute, SwaggerParameter("0:及時照,1:簽名照", Required = true)] byte type)
        {
            RemitRecord record        = remitRecordService.GetRemitRecordById(remitId);
            string      imageFileName = null;

            switch (type)
            {
            case (byte)PictureTypeEnum.Instant:
                imageFileName = record.RealTimePic;
                break;

            case (byte)PictureTypeEnum.Signature:
                imageFileName = record.ESignature;
                break;
            }

            var image = await uploadPicService.LoadImage(null, type, imageFileName);

            if (image == null)
            {
                return(NotFound());
            }

            return(File(image, "image/jpeg"));
        }
예제 #2
0
        public ActionResult <MessageModel <RemitRecordDTO> > GetRemitRecordById([FromRoute, SwaggerParameter("交易紀錄id", Required = true)] long id)
        {
            var         userId  = long.Parse(User.FindFirstValue("id"));
            UserArc     userArc = userService.GetUserArcById(userId);
            RemitRecord record  = remitRecordService.GetRemitRecordById(id);

            if (record != null && record.UserId != userId)
            {
                return(Unauthorized(new MessageModel <RemitRecordDTO>
                {
                    Status = (int)HttpStatusCode.Unauthorized,
                    Success = false,
                    Msg = NOT_AUTHORIZED
                }));
            }


            List <ReceiveBank> banks          = bankService.GetReceiveBanks();
            ReceiveBank        bank           = banks.Find(bank => bank.Id == record.Beneficiary.ReceiveBankId);
            RemitRecordDTO     remitRecordDTO = _mapper.Map <RemitRecordDTO>(record);

            remitRecordDTO.BankEnName   = bank.EnName;
            remitRecordDTO.BankTwName   = bank.TwName;
            remitRecordDTO.BankVietName = bank.VietName;

            return(Ok(new MessageModel <RemitRecordDTO>()
            {
                Data = remitRecordDTO
            }));
        }
예제 #3
0
        public ActionResult <MessageModel <RemitRecordDTO> > ApplyRemitRecord([FromBody] RemitRequest remitRequest, [FromRoute, SwaggerParameter("草稿匯款的id", Required = true)] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            // KYC passed?
            var     userId  = long.Parse(User.FindFirstValue("id"));
            UserArc userArc = userService.GetUserArcById(userId);

            if (!helper.CheckIfKYCPassed(userArc))
            {
                return(BadRequest(new MessageModel <RemitRecordDTO>
                {
                    Status = (int)HttpStatusCode.BadRequest,
                    Success = false,
                    Msg = KYC_NOT_PASSED
                }));
            }

            // get draft remit
            RemitRecord record = remitRecordService.GetRemitRecordById(id);

            if (record == null || record.TransactionStatus != (short)RemitTransactionStatusEnum.Draft)
            {
                return(BadRequest(new MessageModel <RemitRecordDTO>
                {
                    Status = (int)HttpStatusCode.BadRequest,
                    Success = false,
                    Msg = "This Draft Remit doesn't exit or wrong status"
                }));
            }

            string validationResult = helper.ValidateFormalRemitRequestAndUpdateRemitRecord(remitRequest, record, userArc, remitRequest.Country ?? "TW");

            if (validationResult != null)
            {
                return(BadRequest(new MessageModel <RemitRecordDTO>
                {
                    Status = (int)HttpStatusCode.BadRequest,
                    Success = false,
                    Msg = validationResult
                }));
            }

            DateTime       now            = DateTime.UtcNow;
            RemitRecord    modifiedRecord = remitRecordService.ModifyRemitRecord(record, now);
            RemitRecordDTO recordDTO      = _mapper.Map <RemitRecordDTO>(modifiedRecord);

            // 系統掃ARC No.
            BackgroundJob.Enqueue(() => remitRecordService.SystemVerifyArcForRemitProcess(modifiedRecord, userId));

            return(Ok(new MessageModel <RemitRecordDTO>
            {
                Data = recordDTO
            }));
        }
예제 #4
0
        public ActionResult <MessageModel <RemitRecordDTO> > CreateDraftRemitRecord([FromBody] DraftRemitRequest draftRemitRequest)
        {
            if (!ModelState.IsValid)
            {
                var errors = ModelState.Select(x => x.Value.Errors)
                             .Where(y => y.Count > 0)
                             .ToList();

                return(BadRequest(new MessageModel <RemitRecordDTO>
                {
                    Status = (int)HttpStatusCode.BadRequest,
                    Success = false,
                    Msg = string.Join(",", errors)
                }));
            }
            // KYC passed?
            var     userId  = long.Parse(User.FindFirstValue("id"));
            UserArc userArc = userService.GetUserArcById(userId);

            if (!helper.CheckIfKYCPassed(userArc))
            {
                return(BadRequest(new MessageModel <RemitRecordDTO>
                {
                    Status = (int)HttpStatusCode.BadRequest,
                    Success = false,
                    Msg = KYC_NOT_PASSED
                }));
            }
            // Get draft
            RemitRecord draftRemitRecord = remitRecordService.GetDraftRemitRecordByUserArc(userArc);

            if (draftRemitRecord != null)
            {
                remitRecordService.DeleteRmitRecord(draftRemitRecord);
            }

            draftRemitRecord = new RemitRecord();
            string error = helper.CheckAndSetDraftRemitProperty(userArc, draftRemitRecord, draftRemitRequest, draftRemitRequest.Country ?? "TW");

            if (error != null)
            {
                return(BadRequest(new MessageModel <RemitRecordDTO>
                {
                    Status = (int)HttpStatusCode.BadRequest,
                    Success = false,
                    Msg = error
                }));
            }
            draftRemitRecord = remitRecordService.CreateRemitRecordByUserArc(userArc, draftRemitRecord, PayeeTypeEnum.Bank);


            return(Ok(new MessageModel <RemitRecordDTO>
            {
                Data = _mapper.Map <RemitRecordDTO>(draftRemitRecord)
            }));
        }
        public ActionResult <MessageModel <RemitRecordAdminDTO> > GetRemitListById([FromRoute, SwaggerParameter("交易紀錄id", Required = true)] long id)
        {
            RemitRecord         record = remitRecordService.GetRemitRecordById(id);
            ReceiveBank         bank   = bankService.GetReceiveBanks().Find(bank => bank.Id == record.Beneficiary.ReceiveBankId);
            RemitRecordAdminDTO remitRecordAdminDTO = _mapper.Map <RemitRecordAdminDTO>(record);

            remitRecordAdminDTO.Bank = bank.TwName;
            return(Ok(new MessageModel <RemitRecordAdminDTO>
            {
                Data = remitRecordAdminDTO
            }));
        }
예제 #6
0
        public RemitRecord GetRemitRecordById(long id)
        {
            RemitRecord record = dbContext.RemitRecord.Find(id);

            if (record != null)
            {
                dbContext.Entry(record).Reference(record => record.Beneficiary).Query()
                .Include(Beneficiary => Beneficiary.PayeeRelation)
                .Load();
                dbContext.Entry(record).Reference(record => record.ToCurrency).Load();
            }
            return(record);
        }
예제 #7
0
        public async Task SystemVerifyArcForRemitProcess(RemitRecord remitRecord, long userId)
        {
            UserArc userArc = userService.GetUserArcById(userId);

            if (userArc.ArcIssueDate == null || userArc.ArcExpireDate == null)
            {
                throw new Exception("ARC Data not sufficient");
            }
            ArcValidationResult arcValidationResult = arcValidationTask.Validate(workingRootPath, userArc.ArcNo, ((DateTime)userArc.ArcIssueDate).ToString("yyyyMMdd"), ((DateTime)userArc.ArcExpireDate).ToString("yyyyMMdd"), userArc.BackSequence).Result;

            if (arcValidationResult.IsSuccessful)
            {
                ArcScanRecord record = new ArcScanRecord()
                {
                    ArcStatus   = (short)SystemArcVerifyStatusEnum.PASS,
                    ScanTime    = DateTime.UtcNow,
                    Description = arcValidationResult.Result,
                    Event       = (byte)ArcScanEvent.Remit
                };

                remitRecord.TransactionStatus = (short)RemitTransactionStatusEnum.SuccessfulArcVerification;
                // for demo
                if (configuration["IsDemo"] != null && bool.Parse(configuration["IsDemo"]) == true)
                {
                    remitRecord.TransactionStatus = (short)RemitTransactionStatusEnum.SuccessfulAmlVerification;
                }
                //
                AddScanRecordAndUpdateUserKycStatus(record, userArc, remitRecord);
                // send mail
                await SendMailForRemitArc(true, receivers, userId);
            }
            else
            {
                ArcScanRecord record = new ArcScanRecord()
                {
                    ArcStatus   = (short)SystemArcVerifyStatusEnum.FAIL,
                    ScanTime    = DateTime.UtcNow,
                    Description = arcValidationResult.Result,
                    Event       = (byte)ArcScanEvent.Remit
                };
                remitRecord.TransactionStatus = (short)RemitTransactionStatusEnum.FailedVerified;
                userArc.KycStatus             = (short)KycStatusEnum.FAILED_KYC;
                userArc.KycStatusUpdateTime   = DateTime.UtcNow;
                AddScanRecordAndUpdateUserKycStatus(record, userArc, remitRecord);
                // send mail
                await SendMailForRemitArc(false, receivers, userId);

                // push notification
                await notificationService.SaveAndSendNotification((int)userId, "Unsuccessful Remit", "You do not pass The KYC procedure", "en-US");
            }
        }
예제 #8
0
        public void UpdatePicFileNameOfDraftRemit(RemitRecord remitRecord, PictureTypeEnum pictureType, String fileName)
        {
            switch (pictureType)
            {
            case PictureTypeEnum.Instant:
                remitRecord.RealTimePic = fileName;
                break;

            case PictureTypeEnum.Signature:
                remitRecord.ESignature = fileName;
                break;
            }
            ModifyRemitRecord(remitRecord, null);
        }
예제 #9
0
        public List <string> GeneratePaymentCode(RemitRecord modifiedRemitRecord)
        {
            List <string> codeList = new List <string>();

            codeList.Add("100302C72");
            codeList.Add("1231231231000000");
            codeList.Add("090673000020000");
            string codeStr = String.Join(",", codeList.ToArray());

            modifiedRemitRecord.UpdateTime  = DateTime.UtcNow;
            modifiedRemitRecord.PaymentCode = codeStr;
            dbContext.RemitRecord.Update(modifiedRemitRecord);
            dbContext.SaveChanges();

            return(codeList);
        }
예제 #10
0
        public RemitRecord ModifyRemitRecord(RemitRecord modifiedRemitRecord, DateTime?applyTime)
        {
            if (applyTime != null)
            {
                modifiedRemitRecord.FormalApplyTime = applyTime;
            }

            modifiedRemitRecord.UpdateTime = DateTime.UtcNow;
            dbContext.RemitRecord.Update(modifiedRemitRecord);
            dbContext.SaveChanges();
            dbContext.Entry(modifiedRemitRecord).Reference(record => record.Beneficiary).Query()
            .Include(Beneficiary => Beneficiary.PayeeRelation)
            .Load();
            dbContext.Entry(modifiedRemitRecord).Reference(record => record.ToCurrency).Load();
            return(modifiedRemitRecord);
        }
예제 #11
0
        public RemitRecord CreateRemitRecordByUserArc(UserArc userArc, RemitRecord remitRecord, PayeeTypeEnum payeeTypeEnum)
        {
            remitRecord.UserId    = userArc.UserId;
            remitRecord.ArcName   = userArc.ArcName;
            remitRecord.ArcNo     = userArc.ArcNo;
            remitRecord.PayeeType = (byte)payeeTypeEnum;

            dbContext.RemitRecord.Add(remitRecord);
            dbContext.SaveChanges();
            dbContext.Entry(remitRecord).Reference(record => record.Beneficiary).Query()
            .Include(Beneficiary => Beneficiary.PayeeRelation)
            .Load();
            dbContext.Entry(remitRecord).Reference(record => record.ToCurrency).Load();

            return(remitRecord);
        }
        public string CheckAndSetDraftRemitProperty(UserArc userArc, RemitRecord remitRecord, DraftRemitRequest draftRemitRequest, String country)
        {
            string error = null;

            if (draftRemitRequest.FromAmount != null)
            {
                error = CheckIfAmountOutOfRange(userArc.UserId, (int)draftRemitRequest.FromAmount, country);
                if (error != null)
                {
                    return(error);
                }
                remitRecord.FromAmount = (double)draftRemitRequest.FromAmount;
            }

            if (draftRemitRequest.BeneficiaryId != null)
            {
                error = CheckBenificiarExistence((int)draftRemitRequest.BeneficiaryId);
                if (error != null)
                {
                    return(error);
                }
                remitRecord.BeneficiaryId = draftRemitRequest.BeneficiaryId;
            }


            if (draftRemitRequest.DiscountId != null)
            {
                error = CheckDiscountExistence((int)draftRemitRequest.DiscountId);
                if (error != null)
                {
                    return(error);
                }
                remitRecord.DiscountId = draftRemitRequest.DiscountId;
            }

            if (draftRemitRequest.ToCurrencyId != null)
            {
                error = CheckCurrencyExistence((int)draftRemitRequest.ToCurrencyId);
                if (error != null)
                {
                    return(error);
                }
                remitRecord.ToCurrencyId = draftRemitRequest.ToCurrencyId;
            }
            return(null);
        }
        public MessageModel <string> AmlReview(AmlReviewModifyRequest request)
        {
            RemitRecord record = remitRecordService.GetRemitRecordById(request.RecordId);

            if (request.IsAmlPass)
            {
                amlReviewer.AmlReviewPass(request.RecordId, request.Comment);
                notificationService.SaveAndSendNotification((int)record.UserId, "To be Paid", "Your remit application is waiting for payment", "en-US");
            }
            else
            {
                amlReviewer.AmlReviewFail(request.RecordId, request.Comment);
                notificationService.SaveAndSendNotification((int)record.UserId, "Remit had been rejected", "Your remit application was rejected", "en-US");
            }

            return(new MessageModel <string>()
            {
                Data = "Aml status update"
            });
        }
        public MessageModel <string> TransSuccess(TransactionStatusModifyRequest request)
        {
            RemitRecord record = remitRecordService.GetRemitRecordById(request.RecordId);

            if (request.IsComplete)
            {
                statusModifier.RemitSuccess(request.RecordId, request.Comment);
                notificationService.SaveAndSendNotification((int)record.UserId, "Remit Complete", "Your remit application completes", "en-US");
            }
            else
            {
                statusModifier.RemitFail(request.RecordId, request.Comment);
                notificationService.SaveAndSendNotification((int)record.UserId, "Unsuccessful Remit", "Your remit application was rejected", "en-US");
            }

            return(new MessageModel <string>()
            {
                Data = "transaction status update"
            });
        }
        public async Task <ActionResult <MessageModel <UploadedFileDTO> > > UploadPicture([FromForm] CommonFileRequest file)
        {
            //Logger.LogInformation(file.ImageType.ToString());
            var     userId   = long.Parse(User.FindFirstValue("id"));
            string  fileName = null;
            UserArc userArc  = userService.GetUserArcById(userId);

            // for member register process
            if (file.ImageType == (byte)PictureTypeEnum.Front || file.ImageType == (byte)PictureTypeEnum.Back)
            {
                if (userArc.KycStatus != (short)KycStatusEnum.DRAFT_MEMBER)
                {
                    return(BadRequest(new MessageModel <UploadedFileDTO>
                    {
                        Status = (int)HttpStatusCode.BadRequest,
                        Success = false,
                        Msg = "Can not upload!"
                    }));
                }

                fileName = await uploadPic.SavePic(userArc, file.ImageType, file.Image);

                // pic for register process

                userService.UpdatePicFileNameOfUserInfo(userArc, (PictureTypeEnum)file.ImageType, fileName);
            }
            // for draft remit apply
            if (file.ImageType == (byte)PictureTypeEnum.Instant || file.ImageType == (byte)PictureTypeEnum.Signature)
            {
                if (userArc.KycStatus != (short)KycStatusEnum.PASSED_KYC_FORMAL_MEMBER)
                {
                    return(BadRequest(new MessageModel <UploadedFileDTO>
                    {
                        Status = (int)HttpStatusCode.BadRequest,
                        Success = false,
                        Msg = "You are not formal member,can not upload!"
                    }));
                }
                // check draft remit record exist
                if (file.DraftRemitRecordId == null)
                {
                    return(BadRequest(new MessageModel <UploadedFileDTO>
                    {
                        Status = (int)HttpStatusCode.BadRequest,
                        Success = false,
                        Msg = "draftRemitRecordId is required!"
                    }));
                }
                RemitRecord draftRemitRecord = remitRecordService.GetRemitRecordById((long)file.DraftRemitRecordId);
                if (draftRemitRecord == null || draftRemitRecord.TransactionStatus != (short)RemitTransactionStatusEnum.Draft)
                {
                    return(BadRequest(new MessageModel <UploadedFileDTO>
                    {
                        Status = (int)HttpStatusCode.BadRequest,
                        Success = false,
                        Msg = "the draft Remit Record does not exist!"
                    }));
                }

                fileName = await uploadPic.SavePic(userArc, file.ImageType, file.Image);

                remitRecordService.UpdatePicFileNameOfDraftRemit(draftRemitRecord, (PictureTypeEnum)file.ImageType, fileName);
            }


            return(Ok(new MessageModel <Object>
            {
                Data = new UploadedFileDTO
                {
                    FileName = fileName
                }
            }));
        }
예제 #16
0
 private void AddScanRecordAndUpdateUserKycStatus(ArcScanRecord record, UserArc userArc, RemitRecord remitRecord)
 {
     using var transaction = dbContext.Database.BeginTransaction();
     try
     {
         // for demo
         if (configuration["IsDemo"] != null && bool.Parse(configuration["IsDemo"]) == true)
         {
             var demoArcArray = configuration.GetSection("DemoArc").Get <string[]>();
             if (Array.IndexOf(demoArcArray, userArc.ArcNo) > -1)
             {
                 remitRecord.TransactionStatus = (short)RemitTransactionStatusEnum.SuccessfulAmlVerification;
                 userArc.KycStatus             = (short)KycStatusEnum.PASSED_KYC_FORMAL_MEMBER;
             }
         }
         //
         arcScanRecordService.AddScanRecord(record);
         userArc.LastArcScanRecordId = record.Id;
         userArc.UpdateTime          = DateTime.UtcNow;
         dbContext.UserArc.Update(userArc);
         dbContext.SaveChanges();
         remitRecord.ArcScanRecordId = record.Id;
         dbContext.RemitRecord.Update(remitRecord);
         dbContext.SaveChanges();
         transaction.Commit();
         return;
     }
     catch (Exception ex)
     {
         logger.LogError(ex, null);
         transaction.Rollback();
     }
 }
        public string ValidateFormalRemitRequestAndUpdateRemitRecord(RemitRequest remitRequest, RemitRecord remitRecord, UserArc userArc, String country)
        {
            string error = null;

            // check ToCurrency
            error = CheckCurrencyExistence(remitRequest);
            if (error != null)
            {
                return(error);
            }
            remitRecord.FeeType      = remitRequest.FeeType;
            remitRecord.Fee          = remitRequest.Fee;
            remitRecord.ToCurrencyId = remitRequest.ToCurrencyId;

            // check amount
            error = CheckIfAmountOutOfRange(userArc.UserId, remitRequest.FromAmount, "TW");
            if (error != null)
            {
                return(error);
            }
            ExchangeRate applyExchangeRate = exchangeRateService.GetExchangeRateByCurrencyName(remitRequest.ToCurrency);

            remitRecord.FromAmount        = remitRequest.FromAmount;
            remitRecord.ApplyExchangeRate = applyExchangeRate.Rate;
            remitRecord.FromCurrencyId    = currencyService.GetCurrencyByCountry(country)[0].Id;

            // check Beneficiary
            error = CheckBenificiarExistence(remitRequest.BeneficiaryId);
            if (error != null)
            {
                return(error);
            }
            remitRecord.BeneficiaryId = remitRequest.BeneficiaryId;

            // check uploaded picture
            error = CheckPhotoFileExistence(userArc, remitRecord.RealTimePic);
            if (error != null)
            {
                return(error);
            }
            error = CheckSignatureFileExistence(userArc, remitRecord.ESignature);
            if (error != null)
            {
                return(error);
            }

            // check discount
            if (remitRequest.DiscountId != null)
            {
                error = CheckDiscountExistence(remitRequest);
                if (error != null)
                {
                    return(error);
                }
                remitRecord.DiscountId     = remitRequest.DiscountId;
                remitRecord.DiscountAmount = remitRequest.DiscountAmount;
            }

            remitRecord.TransactionStatus = (short)RemitTransactionStatusEnum.WaitingArcVerifying;

            return(error);
        }
예제 #18
0
 public void DeleteRmitRecord(RemitRecord record)
 {
     dbContext.RemitRecord.Remove(record);
     dbContext.SaveChanges();
 }