Skip to content

Commit

Permalink
Implemented GetPaymentDetailsByPaymentId().
Browse files Browse the repository at this point in the history
Implemented /payment/id view.
  • Loading branch information
bonesoul committed Oct 2, 2014
1 parent fa95656 commit 27672de
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/CoiniumServ/Payments/IPaymentRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ public interface IPaymentRepository
IList<IPaymentDetails> GetPaymentDetailsForBlock(uint height);

IPaymentDetails GetPaymentDetailsByTransactionId(uint id);

IPaymentDetails GeyPaymentDetailsByPaymentId(uint id);
}
}
5 changes: 5 additions & 0 deletions src/CoiniumServ/Payments/PaymentRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,10 @@ public IPaymentDetails GetPaymentDetailsByTransactionId(uint id)
{
return _storageLayer.GetPaymentDetailsByTransactionId(id);
}

public IPaymentDetails GeyPaymentDetailsByPaymentId(uint id)
{
return _storageLayer.GetPaymentDetailsByPaymentId(id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ public IPaymentDetails GetPaymentDetailsByTransactionId(uint id)
t.Amount as SentAmount, t.Currency, t.TxHash, p.CreatedAt as PaymentDate, t.CreatedAt as TransactionDate, p.Completed
FROM Payment p
INNER JOIN Account as a ON p.AccountId = a.Id
LEFT OUTER JOIN Transaction t On p.Id = t.PaymentId Where t.Id = @id",
LEFT OUTER JOIN Transaction t On p.Id = t.PaymentId
Where t.Id = @id",
new {id}).Single();
}
}
Expand All @@ -203,6 +204,36 @@ public IPaymentDetails GetPaymentDetailsByTransactionId(uint id)
}
}

public IPaymentDetails GetPaymentDetailsByPaymentId(uint id)
{
try
{
if (!IsEnabled)
return null;

using (var connection = new MySqlConnection(_mySqlProvider.ConnectionString))
{
return connection.Query<PaymentDetails>(
@"SELECT p.Id as PaymentId, t.Id as TransactionId, p.AccountId, a.Address, p.Block, p.Amount as Amount,
t.Amount as SentAmount, t.Currency, t.TxHash, p.CreatedAt as PaymentDate, t.CreatedAt as TransactionDate, p.Completed
FROM Payment p
INNER JOIN Account as a ON p.AccountId = a.Id
LEFT OUTER JOIN Transaction t On p.Id = t.PaymentId
Where p.Id = @id",
new { id }).Single();
}
}
catch (InvalidOperationException) // fires when no result is found.
{
return null;
}
catch (Exception e)
{
_logger.Error("An exception occured while gettin transaction: {0:l}", e.Message);
return null;
}
}

public void AddTransaction(ITransaction transaction)
{
try
Expand Down
2 changes: 2 additions & 0 deletions src/CoiniumServ/Persistance/Layers/IStorageLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ public interface IStorageLayer

IPaymentDetails GetPaymentDetailsByTransactionId(uint id);

IPaymentDetails GetPaymentDetailsByPaymentId(uint id);

/// <summary>
/// Adds a transaction.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public IPaymentDetails GetPaymentDetailsByTransactionId(uint id)
throw new NotImplementedException();
}

public IPaymentDetails GetPaymentDetailsByPaymentId(uint id)
{
throw new NotImplementedException();
}

public void AddTransaction(ITransaction transaction)
{
// this function is not supported as this functionality is only required by payment processors which mpos itself is already one so and handles itself.
Expand Down
11 changes: 8 additions & 3 deletions src/CoiniumServ/Persistance/Layers/Null/NullStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,22 @@ public IList<IPayment> GetPendingPayments()

public IList<IPaymentDetails> GetPaymentsForBlock(uint height)
{
throw new System.NotImplementedException();
return new List<IPaymentDetails>();
}

public IList<IPaymentDetails> GetPaymentsForAccount(int id, IPaginationQuery paginationQuery)
{
throw new System.NotImplementedException();
return new List<IPaymentDetails>();
}

public IPaymentDetails GetPaymentDetailsByTransactionId(uint id)
{
throw new System.NotImplementedException();
return null;
}

public IPaymentDetails GetPaymentDetailsByPaymentId(uint id)
{
return null;
}

public void AddTransaction(ITransaction transaction)
Expand Down
39 changes: 39 additions & 0 deletions src/CoiniumServ/Server/Web/Modules/PoolModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,45 @@ public PoolModule(IPoolManager poolManager)
return View["paymentdetails", model];
};

Get["/{slug}/payment/{id:int}"] = _ =>
{
var pool = (IPool)poolManager.Get(HttpUtility.HtmlEncode(_.slug)); // find the requested pool.
if (pool == null) // make sure queried pool exists.
{
return View["error", new ErrorViewModel
{
Details = string.Format("The requested pool does not exist: {0}", _.slug)
}];
}
var details = pool.PaymentRepository.GeyPaymentDetailsByPaymentId((uint)_.id);
if (details == null)
{
return View["error", new ErrorViewModel
{
Details = string.Format("The requested payment does not exist.")
}];
}
var account = pool.AccountManager.GetAccountById(details.AccountId);
var block = pool.BlockRepository.Get((uint)details.Block);
ViewBag.Header = string.Format("Payment Details");
ViewBag.SubHeader = string.Format("{0}", details.PaymentId);
var model = new PaymentDetailsModel
{
Details = details,
Account = account,
Block = block,
Coin = pool.Config.Coin
};
return View["paymentdetails", model];
};

Get["/{slug}/account/address/{address:length(26,34)}/{page?1}"] = _ =>
{
var pool = (IPool)poolManager.Get(HttpUtility.HtmlEncode(_.slug)); // find the requested pool.
Expand Down
4 changes: 2 additions & 2 deletions src/CoiniumServ/web/default/views/pool/paymentdetails.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
<div class="list-group">
<div class="list-group-item" title="Payment address for the account">
<div class="row">
<div class="col-xs-6"><i class="fa fa-inbox"></i> Address</div>
<div class="col-xs-6 text-right"><a href="/pool/@Model.Coin.Symbol/account/address/@Model.Account.Address">@Model.Account.Address</a></div>
<div class="col-xs-3"><i class="fa fa-inbox"></i> Address</div>
<div class="col-xs-9 text-right"><a href="/pool/@Model.Coin.Symbol/account/address/@Model.Account.Address">@Model.Account.Address</a></div>
</div>
</div>
</div>
Expand Down

0 comments on commit 27672de

Please sign in to comment.