private void purchaseReturned(PurchaseOperation operation, HttpResponse httpResponse) { PurchaseResponse purchaseResponse = operation.PurchaseResponse; Service.Get <EventDispatcher>().DispatchEvent(new IAPServiceEvents.PurchaseReturned(purchaseResponse)); refreshSFSRights(purchaseResponse.rights); }
public APICall <PurchaseOperation> Purchase(PurchaseRequest purchase) { PurchaseOperation operation = new PurchaseOperation(purchase); return(new APICall <PurchaseOperation>(clubPenguinClient, operation)); }
private void purchaseError(PurchaseOperation operation, HttpResponse httpResponse) { Service.Get <EventDispatcher>().DispatchEvent(default(IAPServiceErrors.PurchaseError)); }
public async Task <PurchaseOperationResult> ExecuteAsync(PurchaseOperation operation) { try { // 1 - We store the purchase into the DB. await _purchaseRepository.Upsert(operation.Purchase); //2 - We ask the Stock System to start his own process. var stockOperationRequest = new StockOperationRequest() { Product = operation.Purchase.Product, Count = operation.Purchase.Count }; var stockOperationResult = await _stockSystemAdapter.RegisterPurchase(stockOperationRequest); if (!stockOperationResult.IsCorrect) { throw new Exception("Not able to do the Stock Operation."); } operation.Purchase.StockSystemOperationId = stockOperationResult.Id; _changesToRollback.Add(RegisteredStockOperation, operation.Purchase); // 3 - We ask to the Delivery System to start his own process with the Stock Operation Id var packageOperationRequest = new PackageOperationRequest() { Purchase = operation.Purchase, StockOperationId = operation.Purchase.StockSystemOperationId }; var packageOperationResult = await _packageSystemAdapter.RegisterPurchaseToDeliver(packageOperationRequest); if (!packageOperationResult.IsCorrect) { throw new Exception("Not able to do the Delivery Operation."); } operation.Purchase.DeliverySystemOperationId = packageOperationResult.Id; _changesToRollback.Add(RegisteredDeliveryOperation, operation.Purchase); // 4 - We trigger the notifications await _notificationSystemAdapter.NotifyPurchase(operation.Purchase); await _purchaseRepository.Upsert(operation.Purchase); if (!await CommitAsync()) { // ToDo: Mark a flag or something to execute a FallBack Job. } return(new PurchaseOperationResult()); } catch (Exception e) { if (!await RollbackAsync()) { // ToDo: Mark a flag or something to execute a FallBack Job. } throw e; } }