/// <summary> /// Executes processing of the amex auth request. /// </summary> public ResultCode Execute() { ResultCode result = ResultCode.None; SharedAuthorizationLogic sharedAuthorizationLogic = new SharedAuthorizationLogic(Context, CommerceOperationsFactory.AuthorizationOperations(Context)); Authorization authorization = new Authorization(); Context[Key.Authorization] = authorization; Amex amex = new Amex(Context); amex.MarshalAuthorization(); result = sharedAuthorizationLogic.AddAuthorization(); // Build the response to send back to Amex based on the result of adding the Authorization. Context[Key.ResultCode] = result; amex.BuildAuthorizationResponse(); if (result == ResultCode.Created) { Context.Log.Verbose("Authorization successfully persisted, now send notification"); // Send notification. NotifyAuthorization notifyAuthorization = new NotifyAuthorization(Context); Context[Key.CardBrand] = CardBrand.AmericanExpress; notifyAuthorization.SendNotification(); Context.Log.Verbose("Authorization notification sent"); } return(result); }
/// <summary> /// Executes processing of the authorization event info. /// </summary> public ResultCode Execute() { ResultCode result = ResultCode.None; SharedAuthorizationLogic sharedAuthorizationLogic = new SharedAuthorizationLogic(Context, CommerceOperationsFactory.AuthorizationOperations(Context)); // Marshal MasterCard Authorization request object into partner-agnostic model. Authorization authorization = new Authorization(); Context[Key.Authorization] = authorization; MasterCard masterCard = new MasterCard(Context); masterCard.MarshalAuthorization(); // Add the authorization even to the data store. result = sharedAuthorizationLogic.AddAuthorization(); // Build the response to send back to MasterCard based on the result of adding the Authorization. Context[Key.ResultCode] = result; masterCard.BuildAuthorizationResponse(); // If the authorization event was successfully committed to the data store, send user notifications. if (result == ResultCode.Created) { Context.Log.Verbose("MasterCard Authorization successfully persisted. Sending notifications asynchronously."); NotifyAuthorization notifyAuthorization = new NotifyAuthorization(Context); Context[Key.CardBrand] = CardBrand.MasterCard; Task.Run(new Action(notifyAuthorization.SendNotification)); } return(result); }
/// <summary> /// Executes processing of the deal redemption request. /// </summary> public ResultCode Execute() { ResultCode result; // Marshal the First Data redeem deal request into a RedeemedDeal object. RedeemedDeal redeemedDeal = new RedeemedDeal() { AnalyticsEventId = Guid.NewGuid() }; Context[Key.RedeemedDeal] = redeemedDeal; FirstData firstData = new FirstData(Context); firstData.MarshalRedeemDeal(); // If the purchase date and time was valid, Add the RedeemedDeal to the data store. if (redeemedDeal.PurchaseDateTime != DateTime.MinValue) { string disallowedReason = Context[Key.DisallowedReason] as string; if (String.IsNullOrWhiteSpace(disallowedReason) == true) { result = AddRedeemedDeal(); } else { Context.Log.Warning("Transaction is disallowed because tender type was: {0}.", disallowedReason); Context[Key.RedeemedDealInfo] = new RedeemedDealInfo { PartnerDealId = (string)Context[Key.PartnerDealId], PartnerClaimedDealId = (string)Context[Key.PartnerClaimedDealId] }; result = ResultCode.TransactionDisallowed; } } else { result = ResultCode.InvalidPurchaseDateTime; } // Build the response to send back to First Data based on the result of adding the RedeemedDeal. Context[Key.ResultCode] = result; firstData.BuildRedeemedDealResponse(); // If the deal was successfully redeemed, send user notification and update analytics. if (result == ResultCode.Created) { RedeemedDealInfo redeemedDealInfo = (RedeemedDealInfo)Context[Key.RedeemedDealInfo]; // Send notification. NotifyAuthorization notifyAuthorization = new NotifyAuthorization(Context); Task.Run(new Action(notifyAuthorization.SendNotification)); // Update analytics. SharedUserLogic sharedUserLogic = new SharedUserLogic(Context, CommerceOperationsFactory.UserOperations(Context)); Context[Key.GlobalUserId] = redeemedDealInfo.GlobalUserId; User user = sharedUserLogic.RetrieveUser(); Analytics.AddRedemptionEvent(redeemedDealInfo.GlobalUserId, redeemedDeal.AnalyticsEventId, user.AnalyticsEventId, redeemedDealInfo.ParentDealId, redeemedDealInfo.Currency, redeemedDeal.AuthorizationAmount, redeemedDealInfo.DiscountAmount, redeemedDealInfo.GlobalId, (string)Context[Key.PartnerMerchantId]); } return(result); }
/// <summary> /// Executes processing of the request. /// </summary> public ResultCode Execute() { ResultCode result = ResultCode.None; EndPointMessageRequest request = (EndPointMessageRequest)Context[Key.Request]; Dictionary <String, String> messageElementCollectionDictionary = new Dictionary <string, string>(); foreach (MessageElementsCollection c in request.MessageElementsCollection) { messageElementCollectionDictionary.Add(c.Key, c.Value); } String requestType = messageElementCollectionDictionary[VisaEPMConstants.EventEventType]; if (!string.Equals(requestType, VisaEPMConstants.OnAuthEventTypeValue, StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException("Wrong request message"); } Dictionary <String, String> userDefinedFieldsCollectionDictionary = new Dictionary <string, string>(); foreach (UserDefinedFieldsCollection c in request.UserDefinedFieldsCollection) { userDefinedFieldsCollectionDictionary.Add(c.Key, c.Value); } String cardId = request.CardId; String merchantId = messageElementCollectionDictionary[VisaEPMConstants.TransactionVisaMerchantId]; String storeId = messageElementCollectionDictionary[VisaEPMConstants.TransactionVisaStoreId]; SharedAuthorizationLogic sharedAuthorizationLogic = new SharedAuthorizationLogic(Context, CommerceOperationsFactory.AuthorizationOperations(Context)); Authorization authorization = new Authorization(); Context[Key.Authorization] = authorization; // Populate the Authorization. String amount = messageElementCollectionDictionary[VisaEPMConstants.TransactionTransactionAmount]; authorization.AuthorizationAmount = AmexUtilities.ParseAuthAmount(amount); authorization.Currency = VisaConstants.CurrencyUSD; authorization.TransactionScopeId = messageElementCollectionDictionary[VisaEPMConstants.TransactionVipTransactionId]; authorization.TransactionId = messageElementCollectionDictionary[VisaEPMConstants.TransactionTransactionID]; String time = messageElementCollectionDictionary[VisaEPMConstants.TransactionTimeStampYYMMDD]; // UTC time: 2013-12-05T07:25:06 authorization.PurchaseDateTime = DateTime.Parse(time); authorization.PurchaseDateTime = DateTime.SpecifyKind(authorization.PurchaseDateTime, DateTimeKind.Utc); // Populate the Auth Info. Context[Key.PartnerCardId] = cardId; Context[Key.PartnerMerchantId] = string.Format("{0};{1}", merchantId, storeId); string merchantCity = messageElementCollectionDictionary.NullIfNotExist(VisaEPMConstants.MerchantCityString); string merchantState = messageElementCollectionDictionary.NullIfNotExist(VisaEPMConstants.MerchantStateString); string merchantPostalCode = messageElementCollectionDictionary.NullIfNotExist(VisaEPMConstants.MerchantPostalCodeString); KeyTransactionData keyTransactionData = new KeyTransactionData { MerchantCity = merchantCity, MerchantState = merchantState, MerchantPostalCode = merchantPostalCode }; Context[Key.PartnerData] = keyTransactionData.XmlSerialize(); LogAuthorizationRequest(authorization, Context); result = sharedAuthorizationLogic.AddAuthorization(); Context[Key.ResultCode] = result; if (result == ResultCode.Created) { // Send notification. var notifyAuthorization = new NotifyAuthorization(Context); Context[Key.CardBrand] = CardBrand.Visa; Task.Run(new Action(notifyAuthorization.SendNotification)); } return(result); }