/// <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.OnClearEventTypeValue, StringComparison.OrdinalIgnoreCase))
            {
                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];

                // Marshal the redeem deal request into a RedeemedDeal object.
                RedeemedDeal redeemedDeal = new RedeemedDeal()
                {
                    AnalyticsEventId = Guid.NewGuid()
                };
                Context[Key.RedeemedDeal] = redeemedDeal;

                redeemedDeal.CallbackEvent = RedemptionEvent.Settlement;
                redeemedDeal.PartnerRedeemedDealScopeId = messageElementCollectionDictionary[VisaEPMConstants.TransactionVipTransactionId];
                redeemedDeal.PartnerRedeemedDealId      =
                    messageElementCollectionDictionary[VisaEPMConstants.TransactionTransactionID];
                String time = messageElementCollectionDictionary[VisaEPMConstants.TransactionTimeStampYYMMDD];
                // UTC Time: 2013-12-05T07:25:06
                redeemedDeal.PurchaseDateTime = DateTime.Parse(time);
                redeemedDeal.PurchaseDateTime = DateTime.SpecifyKind(redeemedDeal.PurchaseDateTime, DateTimeKind.Utc);
                String amount = messageElementCollectionDictionary[VisaEPMConstants.TransactionClearingAmount];
                redeemedDeal.AuthorizationAmount = AmexUtilities.ParseAuthAmount(amount);
                redeemedDeal.Currency            = VisaConstants.CurrencyUSD;

                Context[Key.PartnerCardId]           = cardId;
                Context[Key.PartnerClaimedDealId]    = null; // could be the BingOfferDealId
                Context[Key.PartnerMerchantId]       = string.Format("{0};{1}", merchantId, storeId);
                Context[Key.OutletPartnerMerchantId] = null; // storedId;
                Context[Key.CreditStatus]            = CreditStatus.ClearingReceived;

                string merchantCity       = messageElementCollectionDictionary.NullIfNotExist(VisaEPMConstants.MerchantCityString);
                string merchantState      = messageElementCollectionDictionary.NullIfNotExist(VisaEPMConstants.MerchantStateString);
                var    merchantPostalCode = messageElementCollectionDictionary.NullIfNotExist(VisaEPMConstants.MerchantPostalCodeString);

                KeyTransactionData keyTransactionData = new KeyTransactionData
                {
                    MerchantCity       = merchantCity,
                    MerchantState      = merchantState,
                    MerchantPostalCode = merchantPostalCode
                };

                Context[Key.PartnerData] = keyTransactionData.XmlSerialize();

                LogRedeedmedDealRequestParameters(redeemedDeal);

                result = AddRedeemedDeal();
                Context[Key.ResultCode] = result;

                // If the deal was successfully redeemed, apply any applicable rewards.
                if (result == ResultCode.Created)
                {
                    RedeemedDealInfo redeemedDealInfo = (RedeemedDealInfo)Context[Key.RedeemedDealInfo];
                    if (redeemedDealInfo != null)
                    {
                        // Update analytics.
                        SharedUserLogic sharedUserLogic = new SharedUserLogic(Context,
                                                                              CommerceOperationsFactory.UserOperations(
                                                                                  Context));
                        Context[Key.GlobalUserId] = redeemedDealInfo.GlobalUserId;
                        User user = sharedUserLogic.RetrieveUser();
                        if (user != null)
                        {
                            Analytics.AddRedemptionEvent(redeemedDealInfo.GlobalUserId, redeemedDeal.AnalyticsEventId,
                                                         user.AnalyticsEventId,
                                                         redeemedDealInfo.ParentDealId, redeemedDealInfo.Currency,
                                                         redeemedDeal.AuthorizationAmount,
                                                         redeemedDealInfo.DiscountAmount,
                                                         redeemedDealInfo.GlobalId, (string)Context[Key.PartnerMerchantId]);
                        }

                        // Add rewards for any active rewards program.
                        AddRedemptionRewards();
                    }
                }
            }
            return(result);
        }
예제 #2
0
        /// <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);
        }