Last active
October 21, 2020 14:52
-
-
Save StefanRiedmann/2bf0a9cf2c761c03e4e6493263f1a3dd to your computer and use it in GitHub Desktop.
BillingApiController.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
[ApiController] | |
[Route("api/[controller]")] | |
public class BillingController : ControllerBase | |
{ | |
private readonly IBillingApiService service; | |
public BillingController(IBillingApiService service) | |
{ | |
this.service = service; | |
} | |
[HttpGet("[action]")] | |
public async Task<MicrosoftSubscription> ResolvePurchase([FromQuery] string mktplaceToken) | |
{ | |
var p = await service.ResolvePurchase(mktplaceToken); | |
var subsription = await service.GetSubscription(p.SubscriptionId); | |
return subsription; | |
} | |
[HttpPost("[action]")] | |
public async Task ActivateSubscription([FromQuery] string mktplaceToken) | |
{ | |
var purchase = await service.ResolvePurchase(mktplaceToken); | |
var subscription = await service.GetSubscription(purchase.SubscriptionId); | |
// ToDo: Before activing the subscription on Microsoft side, you | |
// have to configure your users account accordingly | |
// ... | |
await service.ActivateSubscription(subscription.SubscriptionId); | |
} | |
[HttpGet("[action]")] | |
public async Task<List<MicrosoftSubscription>> GetAllSubscriptions([FromQuery] bool mock = false) | |
{ | |
var result = await service.GetAllSubscriptions(mock); | |
return result; | |
} | |
[HttpPost("[action]")] | |
public async Task SubscriptionWebhook([FromBody] MicrosoftWebhookPayload payload) | |
{ | |
// ToDo: Perform the changes described in the payload on your user's account | |
// Alternative: Get the full operation for more details | |
var operation = await service.GetOperationStatus(payload.SubscriptionId, payload.OperationId); | |
await service.UpdateOperationStatus(payload.SubscriptionId, payload.OperationId, "Success"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment