예제 #1
0
        /// <summary>
        /// Decrease sequence number, in case file submission failed
        /// </summary>
        internal void DecrementSequence()
        {
            Context[Key.SequenceName] = "AmexOfferRegistrationSequence";
            SharedSequenceLogic sequenceLogic = new SharedSequenceLogic(Context, CommerceOperationsFactory.SequenceOperations(Context));

            sequenceLogic.DecrementSequence();
        }
예제 #2
0
        /// <summary>
        /// create request file
        /// </summary>
        /// <returns>
        /// Async task wrapper
        /// </returns>
        private async Task <string> CreateNewRequestFileIfNeededAsync()
        {
            ICollection <string> recordNames = DetailRecordsBloblClient.RetrieveFilesToProcess();
            Collection <string>  records     = new Collection <string>();
            string fileToUpload = null;

            if (recordNames != null)
            {
                foreach (string recordName in recordNames)
                {
                    MemoryStream memStream = new MemoryStream();
                    memStream.Position = 0;
                    await DetailRecordsBloblClient.DownloadAsync(memStream, recordName).ConfigureAwait(false);;

                    memStream.Position = 0;
                    using (StreamReader streamReader = new StreamReader(memStream))
                    {
                        string record = streamReader.ReadToEnd();
                        records.Add(record);
                    }

                    await DetailRecordsBloblClient.MarkAsProcessedAsync(recordName).ConfigureAwait(false);;
                }
            }

            if (records.Count > 0)
            {
                Context[Key.SequenceName] = "AmexOfferRegistrationSequence";
                SharedSequenceLogic sequenceLogic = new SharedSequenceLogic(Context, CommerceOperationsFactory.SequenceOperations(Context));
                int sequenceNumber = sequenceLogic.RetrieveNextValueInSequence();
                fileToUpload = OfferRegistrationFileBuilder.Build(records, sequenceNumber, DateTime.UtcNow);
            }

            return(fileToUpload);
        }
예제 #3
0
        /// <summary>
        /// Build the statement credit file
        /// </summary>
        /// <param name="result">
        /// Collection of records to build credit for
        /// </param>
        /// <returns>
        /// Instance of StatmentCreditFile <see cref="StatementCreditFile"/>
        /// </returns>
        internal StatementCreditFile BuildCreditFile(Collection <OutstandingRedeemedDealInfo> result)
        {
            StatementCreditFile file = null;

            if (result.Count > 0)
            {
                Context[Key.SequenceName] = "AmexStatementCreditSequence";
                SharedSequenceLogic sequenceLogic = new SharedSequenceLogic(Context, CommerceOperationsFactory.SequenceOperations(Context));
                int sequenceNumber = sequenceLogic.RetrieveNextValueInSequence();

                file = new StatementCreditFile()
                {
                    Header = new StatementCreditHeader()
                    {
                        Date           = DateTime.UtcNow,
                        SequenceNumber = sequenceNumber
                    }
                };
                int totalAmount = 0;
                foreach (OutstandingRedeemedDealInfo outstandingRedeemedDealInfo in result)
                {
                    totalAmount += outstandingRedeemedDealInfo.DiscountAmount;
                    StatementCreditDetail detail = new StatementCreditDetail()
                    {
                        CampaignName        = outstandingRedeemedDealInfo.MerchantName,
                        CardToken           = outstandingRedeemedDealInfo.Token,
                        DiscountAmount      = (decimal)outstandingRedeemedDealInfo.DiscountAmount / 100,
                        OfferId             = outstandingRedeemedDealInfo.OfferId,
                        StatementDescriptor = StatmentDescriptor(outstandingRedeemedDealInfo.MerchantName),
                        TransactionId       = outstandingRedeemedDealInfo.ReferenceNumber.ToString(CultureInfo.InvariantCulture)
                    };
                    file.StatementCreditRecords.Add(detail);
                }
                file.Trailer = new StatementCreditTrailer()
                {
                    TrailerAmount = (decimal)totalAmount / 100,
                    TrailerCount  = file.StatementCreditRecords.Count
                };
            }


            return(file);
        }
예제 #4
0
        /// <summary>
        /// Create a new offer Id for registering a deal with Amex
        /// </summary>
        /// <param name="context">
        /// Incoming Commerce Context
        /// </param>
        /// <returns>
        /// The Id of the new offer
        /// </returns>
        public static int GenerateNewOfferId(CommerceContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context", "Parameter context cannot be null.");
            }

            context[Key.SequenceName] = "AmexOfferIdSequence";
            SharedSequenceLogic sharedSequenceLogic = new SharedSequenceLogic(context, CommerceOperationsFactory.SequenceOperations(context));

            return(sharedSequenceLogic.RetrieveNextValueInSequence());
        }