public async Task <Guid> AddDonation(LiqPayCheckoutDto liqPayCheckoutDto) { var liqPayData = new LiqPayData(liqPayCheckoutDto.Data); var liqPaySignature = new LiqPaySignature(liqPayData, _liqPayKeys.PrivateKey); if (!await liqPaySignature.Validate(liqPayCheckoutDto.Signature)) { throw new InvalidArgumentException(nameof(liqPayCheckoutDto.Signature), "Invalid signature"); } var donation = liqPayData.Donation; var commissionModel = liqPayData.Commission; donation.Amount -= commissionModel.ReceiverCommission; donation.ProjectId = liqPayCheckoutDto.ProjectId; donation.SocietyId = liqPayCheckoutDto.SocietyId; donation.DonatorId = liqPayCheckoutDto.DonatorId; _unitOfWork.Repository <Donation>().Add(donation); await _unitOfWork.SaveChangesAsync(); return(donation.Id); }
public async Task TopUpBalance(LiqPayCheckoutDto liqPayCheckoutDto) { var liqPayData = new LiqPayData(liqPayCheckoutDto.Data); var liqPaySignature = new LiqPaySignature(liqPayData, _liqPayInfo.PrivateKey); if (!await liqPaySignature.Validate(liqPayCheckoutDto.Signature)) { throw new InvalidArgumentException(nameof(liqPayCheckoutDto.Signature), "Invalid signature"); } var user = await _unitOfWork.Repository <UserDetails>() .Get(i => i.UserDetailsId == liqPayCheckoutDto.MemberId); if (user == null) { throw new NotFoundException($"User with id {liqPayCheckoutDto.MemberId}"); } var donation = liqPayData.Donation; var commissionModel = liqPayData.Commission; donation.Amount -= commissionModel.ReceiverCommission; user.Balance += donation.Amount; var paymentHistory = new PaymentHistory() { Description = PaymentDescription.TopUp, Saldo = donation.Amount, UserId = (Guid)liqPayCheckoutDto.MemberId, CurrentBalance = user.Balance }; _unitOfWork.Repository <UserDetails>().Update(user); _unitOfWork.Repository <PaymentHistory>().Add(paymentHistory); await _unitOfWork.SaveChangesAsync(); }