public int Insert(PaymentLink link) { using (var connection = CreateConnection()) { var sql = $"INSERT INTO {PaymentLinkTableName}(Id, Amount, FollowId, ClusterId, Description, ExpireDays, CreateDate, LastCheckForUpdateDate, ResultDate, BankReferenceId, Url, Token, PaymentStatus)VALUES(@Id, @Amount, @FollowId, @ClusterId, @Description, @ExpireDays, @CreateDate, @LastCheckForUpdateDate, @ResultDate, @BankReferenceId, @Url, @Token, @PaymentStatus);"; return(connection.Execute(sql, link)); } }
public int Update(PaymentLink link) { using (var connection = CreateConnection()) { var sql = $"UPDATE {PaymentLinkTableName} SET Amount=@Amount, FollowId=@FollowId, ClusterId=@ClusterId, Description=@Description, ExpireDays=@ExpireDays, CreateDate=@CreateDate, LastCheckForUpdateDate=@LastCheckForUpdateDate, ResultDate=@ResultDate, BankReferenceId=@BankReferenceId, Url=@Url, Token=@Token, PaymentStatus=@PaymentStatus WHERE Id=@Id;"; return(connection.Execute(sql, link)); } }
public bool Delete(PaymentLink link) { int result = 0; using (var connection = CreateConnection()) { if (!string.IsNullOrEmpty(link.Token)) { var command = $"DELETE p FROM {PaymentLinkTableName} AS p WHERE p.[Token] = @Token"; result = connection.Execute(command, new { Token = link.Token }); } else if (!string.IsNullOrEmpty(link.FollowId)) { var command = $"DELETE p FROM {PaymentLinkTableName} AS p WHERE p.[FollowId] = @FollowId"; result = connection.Execute(command, new { FollowId = link.FollowId }); } } return(result > 0); }
public PaymentLink Create(decimal amount, string followId, string invoiceNumber, DateTime invoiceDate, ushort expireAfterDays, string description) { var service = PayRequestFactory.CreateV2(); var request = new EPayRequestModel(); request.Amount = amount; request.Description = description; request.ExpiresAfterDays = expireAfterDays; request.InvoiceNumber = invoiceNumber; request.InvoiceDate = invoiceDate; request.IsAutoRedirect = false; var result = service.Create(Options.ApiKey, Options.Password, request); if (result.Success) { var link = new PaymentLink(); link.Amount = amount; link.Description = description; link.ExpireDays = expireAfterDays; link.FollowId = followId; link.CreateDate = DateTime.Now; link.LastCheckForUpdateDate = DateTime.Now; link.PaymentStatus = (int)RequestStatus.Initiated; link.Token = result.RequestToken; link.Url = result.PaymentUrl; link.ResultDate = null; link.Id = Guid.NewGuid(); link.ClusterId = PaymentLinkNotificationService.ClusterId; PaymentLinkRepository.Insert(link); return(link); } else { throw new InvalidOperationException(result.Message); } }