-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves #821 Web API: add endpoints for RecurringPayment and Recurri…
…ngPaymentHistory
- Loading branch information
Showing
6 changed files
with
218 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...store.Modules/Smartstore.WebApi/Controllers/Checkout/RecurringPaymentHistoryController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using Smartstore.Core.Checkout.Payment; | ||
|
||
namespace Smartstore.Web.Api.Controllers | ||
{ | ||
/// <summary> | ||
/// The endpoint for operations on RecurringPaymentHistory entity. | ||
/// </summary> | ||
public class RecurringPaymentHistoryController : WebApiController<RecurringPaymentHistory> | ||
{ | ||
[HttpGet("RecurringPaymentHistory"), ApiQueryable] | ||
[Permission(Permissions.Order.Read)] | ||
public IQueryable<RecurringPaymentHistory> Get() | ||
{ | ||
return Entities.AsNoTracking(); | ||
} | ||
|
||
[HttpGet("RecurringPaymentHistory({key})"), ApiQueryable] | ||
[Permission(Permissions.Order.Read)] | ||
public SingleResult<RecurringPaymentHistory> Get(int key) | ||
{ | ||
return GetById(key); | ||
} | ||
|
||
[HttpGet("RecurringPaymentHistory({key})/RecurringPayment"), ApiQueryable] | ||
[Permission(Permissions.Order.Read)] | ||
public SingleResult<RecurringPayment> GetRecurringPayment(int key) | ||
{ | ||
return GetRelatedEntity(key, x => x.RecurringPayment); | ||
} | ||
|
||
[HttpPost] | ||
[Permission(Permissions.Order.EditRecurringPayment)] | ||
public Task<IActionResult> Post([FromBody] RecurringPaymentHistory model) | ||
{ | ||
return PostAsync(model); | ||
} | ||
|
||
[HttpPut] | ||
[Permission(Permissions.Order.EditRecurringPayment)] | ||
public Task<IActionResult> Put(int key, Delta<RecurringPaymentHistory> model) | ||
{ | ||
return PutAsync(key, model); | ||
} | ||
|
||
[HttpPatch] | ||
[Permission(Permissions.Order.EditRecurringPayment)] | ||
public Task<IActionResult> Patch(int key, Delta<RecurringPaymentHistory> model) | ||
{ | ||
return PatchAsync(key, model); | ||
} | ||
|
||
[HttpDelete] | ||
[Permission(Permissions.Order.EditRecurringPayment)] | ||
public Task<IActionResult> Delete(int key) | ||
{ | ||
return DeleteAsync(key); | ||
} | ||
} | ||
} |
132 changes: 132 additions & 0 deletions
132
src/Smartstore.Modules/Smartstore.WebApi/Controllers/Checkout/RecurringPaymentsController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
using Smartstore.Core.Checkout.Orders; | ||
using Smartstore.Core.Checkout.Payment; | ||
|
||
namespace Smartstore.Web.Api.Controllers | ||
{ | ||
/// <summary> | ||
/// The endpoint for operations on RecurringPayment entity. | ||
/// </summary> | ||
public class RecurringPaymentsController : WebApiController<RecurringPayment> | ||
{ | ||
private readonly Lazy<IOrderProcessingService> _orderProcessingService; | ||
|
||
public RecurringPaymentsController(Lazy<IOrderProcessingService> orderProcessingService) | ||
{ | ||
_orderProcessingService = orderProcessingService; | ||
} | ||
|
||
[HttpGet("RecurringPayments"), ApiQueryable] | ||
[Permission(Permissions.Order.Read)] | ||
public IQueryable<RecurringPayment> Get() | ||
{ | ||
return Entities.AsNoTracking(); | ||
} | ||
|
||
[HttpGet("RecurringPayments({key})"), ApiQueryable] | ||
[Permission(Permissions.Order.Read)] | ||
public SingleResult<RecurringPayment> Get(int key) | ||
{ | ||
return GetById(key); | ||
} | ||
|
||
[HttpGet("RecurringPayments({key})/RecurringPaymentHistory"), ApiQueryable] | ||
[Permission(Permissions.Order.Read)] | ||
public IQueryable<RecurringPaymentHistory> GetRecurringPaymentHistory(int key) | ||
{ | ||
return GetRelatedQuery(key, x => x.RecurringPaymentHistory); | ||
} | ||
|
||
[HttpGet("RecurringPayments({key})/InitialOrder"), ApiQueryable] | ||
[Permission(Permissions.Order.Read)] | ||
public SingleResult<Order> GetInitialOrder(int key) | ||
{ | ||
return GetRelatedEntity(key, x => x.InitialOrder); | ||
} | ||
|
||
[HttpPost] | ||
[Permission(Permissions.Order.EditRecurringPayment)] | ||
public Task<IActionResult> Post([FromBody] RecurringPayment model) | ||
{ | ||
return PostAsync(model); | ||
} | ||
|
||
[HttpPut] | ||
[Permission(Permissions.Order.EditRecurringPayment)] | ||
public Task<IActionResult> Put(int key, Delta<RecurringPayment> model) | ||
{ | ||
return PutAsync(key, model); | ||
} | ||
|
||
[HttpPatch] | ||
[Permission(Permissions.Order.EditRecurringPayment)] | ||
public Task<IActionResult> Patch(int key, Delta<RecurringPayment> model) | ||
{ | ||
return PatchAsync(key, model); | ||
} | ||
|
||
[HttpDelete] | ||
[Permission(Permissions.Order.EditRecurringPayment)] | ||
public Task<IActionResult> Delete(int key) | ||
{ | ||
return DeleteAsync(key); | ||
} | ||
|
||
#region Actions and functions | ||
|
||
/// <summary> | ||
/// Processes the next recurring payment. | ||
/// </summary> | ||
[HttpPost("RecurringPayments({key})/ProcessNextRecurringPayment"), ApiQueryable] | ||
[Permission(Permissions.Order.EditRecurringPayment)] | ||
[Produces(Json)] | ||
[ProducesResponseType(typeof(RecurringPayment), Status200OK)] | ||
[ProducesResponseType(Status404NotFound)] | ||
[ProducesResponseType(Status422UnprocessableEntity)] | ||
public async Task<IActionResult> ProcessNextRecurringPayment(int key) | ||
{ | ||
try | ||
{ | ||
var entity = await GetRequiredById(key, q => q | ||
.Include(x => x.InitialOrder) | ||
.ThenInclude(x => x.Customer)); | ||
|
||
await _orderProcessingService.Value.ProcessNextRecurringPaymentAsync(entity); | ||
|
||
return Ok(entity); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return ErrorResult(ex); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Cancels a recurring payment. | ||
/// </summary> | ||
[HttpPost("RecurringPayments({key})/CancelRecurringPayment"), ApiQueryable] | ||
[Permission(Permissions.Order.EditRecurringPayment)] | ||
[Produces(Json)] | ||
[ProducesResponseType(typeof(RecurringPayment), Status200OK)] | ||
[ProducesResponseType(Status404NotFound)] | ||
[ProducesResponseType(Status422UnprocessableEntity)] | ||
public async Task<IActionResult> CancelRecurringPayment(int key) | ||
{ | ||
try | ||
{ | ||
var entity = await GetRequiredById(key, q => q | ||
.Include(x => x.InitialOrder) | ||
.ThenInclude(x => x.Customer)); | ||
|
||
await _orderProcessingService.Value.CancelRecurringPaymentAsync(entity); | ||
|
||
return Ok(entity); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return ErrorResult(ex); | ||
} | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters