예제 #1
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);
        }
예제 #2
0
        /// <summary>
        /// Build the string representation of the file.
        /// </summary>
        /// <returns>
        /// String representation of the file or null
        /// </returns>
        public async Task Build(Func <string, Task> onStatementCreditFileBuildFunc)
        {
            Collection <OutstandingRedeemedDealInfo> redeemedDealRecords = WorkerActions.RetrieveOutstandingPartnerRedeemedDealRecords(Partner.Amex,
                                                                                                                                       RedeemedDealOperations, Context);

            if (onStatementCreditFileBuildFunc != null)
            {
                // this will ftp the data and store it in blob
                StatementCreditFile file = BuildCreditFile(redeemedDealRecords);
                string result            = ConvertFileToString(file);
                await onStatementCreditFileBuildFunc(result).ConfigureAwait(false);

                // Commenting the earlier implementation of marking the transactions as StatementCreditRequested
                //WorkerActions.UpdatePendingRedeemedDeals(redeemedDealRecords, CreditStatus.StatementCreditRequested, RedeemedDealOperations, Context);

                // follow the master card pattern to mark as settled unless we get an error from amex
                WorkerActions.MarkSettledAsRedeemed(redeemedDealRecords, RedeemedDealOperations, Context);
            }
        }
예제 #3
0
        internal static string ConvertFileToString(StatementCreditFile file)
        {
            if (file == null)
            {
                return(null);
            }

            // convert file to string representation here
            StringBuilder fileBuilder = new StringBuilder();

            fileBuilder.Append(file.Header.BuildFileHeader());
            fileBuilder.Append("\n");
            foreach (StatementCreditDetail statementCreditRecord in file.StatementCreditRecords)
            {
                fileBuilder.Append(statementCreditRecord.BuildFileDetailRecord());
                fileBuilder.Append("\n");
            }
            fileBuilder.Append(file.Trailer.BuildFileTrailer());
            return(fileBuilder.ToString());
        }