/// <summary> /// Captures the payment. /// </summary> /// <returns>A task.</returns> public async Task ExecuteAsync() { if (string.IsNullOrEmpty(AuthorizationCode)) { AuthorizationCode = AcquireInput.Invoke(); } await PaymentGateway.CaptureAsync(AuthorizationCode).ConfigureAwait(false); }
/// <summary> /// Records all the resulting subscriptions as well as their initial purchase history into persistence. /// </summary> /// <returns>A task.</returns> public async Task ExecuteAsync() { Tuple <Order, IEnumerable <PurchaseLineItemWithOffer> > inputs = AcquireInput.Invoke(); Order partnerCenterPurchaseOrder = inputs.Item1; IEnumerable <PurchaseLineItemWithOffer> purchaseLineItems = inputs.Item2; ICollection <TransactionResultLineItem> transactionResultLineItems = new List <TransactionResultLineItem>(); ICollection <IBusinessTransaction> persistenceTransactions = new List <IBusinessTransaction>(); DateTime rightNow = DateTime.UtcNow; foreach (OrderLineItem orderLineItem in partnerCenterPurchaseOrder.LineItems) { PartnerOffer matchingPartnerOffer = purchaseLineItems.ElementAt(orderLineItem.LineItemNumber).PartnerOffer; // add a record new customer subscription transaction for the current line item persistenceTransactions.Add(new RecordNewCustomerSubscription( CustomerSubscriptionsRepository, new CustomerSubscriptionEntity(CustomerId, orderLineItem.SubscriptionId, matchingPartnerOffer.Id, rightNow.AddYears(1)))); // add a record purchase history for the current line item persistenceTransactions.Add(new RecordPurchase( CustomerPurchasesRepository, new CustomerPurchaseEntity(CommerceOperationType.NewPurchase, Guid.NewGuid().ToString(), CustomerId, orderLineItem.SubscriptionId, orderLineItem.Quantity, matchingPartnerOffer.Price, rightNow))); // build the transaction result line item transactionResultLineItems.Add(new TransactionResultLineItem( orderLineItem.SubscriptionId, matchingPartnerOffer.Id, orderLineItem.Quantity, matchingPartnerOffer.Price, matchingPartnerOffer.Price * orderLineItem.Quantity)); } // bundle up all the transactions together bulkSubscriptionPersistenceTransaction = new SequentialAggregateTransaction(persistenceTransactions); // execute it! await bulkSubscriptionPersistenceTransaction.ExecuteAsync().ConfigureAwait(false); // store the reuslting transaction line items Result = transactionResultLineItems; }