예제 #1
0
        /// <summary>
        /// Removes the card in the context for the user in the context from this partner.
        /// </summary>
        /// <returns>
        /// A task that will yield the result code for the operation.
        /// </returns>
        public async Task <ResultCode> RemoveCardAsync()
        {
            ResultCode result = ResultCode.None;

            // Build a account update request object to cancel card registration.
            CustomerAccountField[] customerAccountFieldFields = new CustomerAccountField[1]
            {
                new CustomerAccountField
                {
                    fieldName = MasterCardConstants.AccountStatusCodeFieldName,
                    data      = MasterCardConstants.AccountStatusCanceled
                }
            };

            doCustomerAccountUpdate accountUpdate = new doCustomerAccountUpdate
            {
                sourceId              = MasterCardConstants.SourceId,
                bankCustomerNumber    = ((User)Context[Key.User]).GetPartnerUserId(Partner.MasterCard),
                customerAccountFields = customerAccountFieldFields
            };
            doCustomerAccountUpdateRequest accountUpdateRequest = new doCustomerAccountUpdateRequest
            {
                doCustomerAccountUpdate = accountUpdate
            };

            LogRemoveCardRequestParameters(accountUpdateRequest);

            // Invoke the partner to remove the card.
            result = await PartnerUtilities.InvokePartner(Context, async() =>
            {
                Context.Log.Verbose("Invoking partner RemoveCardAsync API.");
                CustomerAccountUpdateResp response = await MasterCardInvoker.RemoveCard(accountUpdate).ConfigureAwait(false);
                Context.Log.Verbose("Partner RemoveCardAsync API returned: {0}: {1}.", response.returnCode, response.returnMsg);
                LogUpdateCardResponseParameters(response);

                // Determine the ResultCode from the response code.
                switch (response.returnCode)
                {
                case MasterCardResponseCode.Success:
                case MasterCardResponseCode.InvalidCard:
                    result = ResultCode.Success;
                    break;

                case MasterCardResponseCode.UnknownError:
                    result = ResultCode.UnknownError;
                    break;
                }

                // Log a warning if result was not a success.
                if (result != ResultCode.Success)
                {
                    Context.Log.Warning("MasterCard call failed. returnCode: {0}. returnMsg: {1}.",
                                        (int)DefaultLogEntryEventId.PartnerErrorWarning, response.returnCode, response.returnMsg);
                }

                return(result);
            }).ConfigureAwait(false);

            return(result);
        }
예제 #2
0
        public async Task <ResultCode> SaveStatementCreditAsync()
        {
            var result                    = ResultCode.None;
            var cardId                    = (string)Context[Key.CardToken];
            var creditAmount              = (float)((int)Context[Key.DealDiscountAmount] / 100.0);
            var transactionId             = (string)Context[Key.Transaction];
            var transactionSettlementDate = (DateTime)Context[Key.TransactionSettlementDate];
            var partnerUserId             = (string)Context[Key.PartnerUserId];

            var request = VisaRtmDataManager.GetSaveStatementCreditAsync(cardId, creditAmount, transactionId, transactionSettlementDate, partnerUserId, VisaConstants.CommunityCodeClLevel);

            LogRequest("SaveStatementCreditAsync", request);

            result = await PartnerUtilities.InvokePartner(Context, async() =>
            {
                var response = await VisaInvoker.SaveStatementCreditAsync(request).ConfigureAwait(false);
                LogRequestResponse("SaveStatementCreditAsync", request, response, response.StatementCreditSubmitStatus);

                result = ResultCode.UnknownError;
                if (response.StatementCreditSubmitStatus)
                {
                    result = ResultCode.Created;
                }
                else if (response.HasError())
                {
                    //TODO: once we are ready to log these error messages in Db - map the error returned by Visa
                    //into our error codes and log in Db
                    result = visaErrorUtility.GetResultCode(response, null);
                }

                return(result);
            }, null, Partner.None, true).ConfigureAwait(false);

            return(result);
        }
예제 #3
0
        /// <summary>
        ///  Enroll new user to Visa
        /// </summary>
        /// <returns></returns>
        private async Task <ResultCode> CreateEnrollment(string userKey)
        {
            ResultCode result = ResultCode.None;

            var newCardNumber     = ((NewCardInfo)Context[Key.NewCardInfo]).Number;
            var lastFourOfNewCard = newCardNumber.Substring(12);

            // Build a card register request object.
            var request = VisaRtmDataManager.GetCreateEnrollmentRequest(
                community: VisaConstants.CommunityName,
                userkey: userKey,
                cardnumbers: new List <string> {
                newCardNumber
            }
                );

            LogRequest("CreateEnrollment", request, newCardNumber, lastFourOfNewCard);
            // Invoke the partner to add the card.
            result = await PartnerUtilities.InvokePartner(Context, async() =>
            {
                var response = await VisaInvoker.CreateEnrollment(request).ConfigureAwait(false);
                LogRequestResponse("CreateEnrollment", request, response, response.Success, newCardNumber, lastFourOfNewCard);

                result = ResultCode.UnknownError;
                if (response.Success)
                {
                    result = ResultCode.Created;
                }
                else if (response.HasError())
                {
                    result = visaErrorUtility.GetResultCode(response, null);
                }

                if (result == ResultCode.Created)
                {
                    PartnerCardInfo partnerCardInfo   = GetVisaCardInfo((Card)Context[Key.Card]);
                    partnerCardInfo.PartnerCardId     = response.EnrollmentRecord.CardDetails[0].CardId.ToString();
                    partnerCardInfo.PartnerCardSuffix = "00";

                    var partnerUserId = response.EnrollmentRecord.UserProfileId;
                    User user         = (User)Context[Key.User];
                    user.AddOrUpdatePartnerUserId(Partner.Visa, partnerUserId.ToString(), true);

                    //add partner user information to the database
                    var userOperations = CommerceOperationsFactory.UserOperations(Context);
                    userOperations.AddOrUpdateUser();
                }

                return(result);
            }, null, Partner.None, true).ConfigureAwait(false);

            return(result);
        }
예제 #4
0
        /// <summary>
        /// Add a card to Visa
        /// </summary>
        /// <param name="userkey"></param>
        /// <returns></returns>
        private async Task <ResultCode> SaveCardAsync(string userkey)
        {
            ResultCode result = ResultCode.None;

            var newCardNumber     = ((NewCardInfo)Context[Key.NewCardInfo]).Number;
            var lastFourOfNewCard = newCardNumber.Substring(12);

            // Build a card register request object.
            var request = VisaRtmDataManager.GetSaveCardRequest(userkey, VisaConstants.CommunityName, newCardNumber);

            LogRequest("AddCard", request, newCardNumber, lastFourOfNewCard);

            // Invoke the partner to add the card.
            result = await PartnerUtilities.InvokePartner(Context, async() =>
            {
                var response = await VisaInvoker.AddCard(request).ConfigureAwait(false);
                LogRequestResponse("AddCard", request, response, response.Success, newCardNumber, lastFourOfNewCard);

                result = ResultCode.UnknownError;
                if (response.Success)
                {
                    result = ResultCode.Created;
                }
                else if (response.HasError())
                {
                    result = visaErrorUtility.GetResultCode(response, null);
                }

                if (result == ResultCode.Created)
                {
                    PartnerCardInfo partnerCardInfo   = GetVisaCardInfo((Card)Context[Key.Card]);
                    partnerCardInfo.PartnerCardId     = response.CardInfoResponse.CardId.ToString();
                    partnerCardInfo.PartnerCardSuffix = "00";
                }

                return(result);
            }, null, Partner.None, true).ConfigureAwait(false);

            return(result);
        }
예제 #5
0
        /// <summary>
        /// Remove a card from Visa
        /// </summary>
        /// <returns></returns>
        public async Task <ResultCode> RemoveCardAsync()
        {
            ResultCode result        = ResultCode.None;
            var        card          = (Card)Context[Key.Card];
            var        partnerCardId = card.PartnerCardInfoList.Where(p => p.PartnerId == Partner.Visa).Select(p => p.PartnerCardId).First();
            // Build a card register request object.
            var request = VisaRtmDataManager.GetDeleteCardRequest(GetVisaExternalUserId(), VisaConstants.CommunityName, partnerCardId);

            LogRequest("RemoveCard", request);

            // Invoke the partner to add the card.
            result = await PartnerUtilities.InvokePartner(Context, async() =>
            {
                var response = await VisaInvoker.RemoveCard(request);
                LogRequestResponse("RemoveCard", request, response, response.Success);

                // Determine the ResultCode from the response code.
                result = response.Success ? ResultCode.Success : ResultCode.UnknownError;

                return(result);
            }, null, Partner.None, true).ConfigureAwait(false);

            return(result);
        }
예제 #6
0
        /// <summary>
        /// Adds the card in the context for the user in the context to this partner.
        /// </summary>
        /// <returns>
        /// A task that will yield the result code for the operation.
        /// </returns>
        public async Task <ResultCode> AddCardAsync()
        {
            ResultCode result = ResultCode.None;

            // Build request
            AmexCardSyncRequest amexCardSyncRequest = new AmexCardSyncRequest
            {
                CardToken1 = Guid.NewGuid().ToString("N"),
                CardNumber = ((NewCardInfo)Context[Key.NewCardInfo]).Number
            };

            Context.Log.Verbose("Amex AddCardAsync suggested card token: {0}", amexCardSyncRequest.CardToken1);

            HashSet <ResultCode> terminalCodes = new HashSet <ResultCode>
            {
                ResultCode.Created,
                ResultCode.Success,
                ResultCode.InvalidCardNumber,
                ResultCode.CorporateOrPrepaidCardError
            };

            result = await PartnerUtilities.InvokePartner(Context, async() =>
            {
                Context.Log.Verbose("Invoking Amex add card partner API.");
                AmexCardResponse response = await AmexInvoker.AddCardAsync(amexCardSyncRequest);
                Context.Log.Verbose("Amex add card partner API returned.\r\n {0}", JsonConvert.SerializeObject(response));

                string code = null;
                string text = null;

                if (response != null && response.ResponseCode != null)
                {
                    code = response.ResponseCode;
                    text = response.ResponseDescription;

                    switch (code)
                    {
                    case AmexCardSyncResponseCode.AddCardSuccess:
                    case AmexCardSyncResponseCode.CardAndTokenPairAlreadyExists:
                        result = ResultCode.Created;
                        PartnerCardInfo partnerCardInfo   = GetAmexCardInfo((Card)Context[Key.Card]);
                        partnerCardInfo.PartnerCardId     = response.CardToken1;
                        partnerCardInfo.PartnerCardSuffix = "00";
                        break;

                    case AmexCardSyncResponseCode.CardExistsWithDifferentToken:
                        result = ResultCode.CardDoesNotBelongToUser;
                        break;

                    case AmexCardSyncResponseCode.CorporateOrPrepaidCardError:
                        result = ResultCode.CorporateOrPrepaidCardError;
                        break;

                    case AmexCardSyncResponseCode.InvalidCardNumber:
                    case AmexCardSyncResponseCode.NotAmexCard:
                        result = ResultCode.InvalidCardNumber;
                        break;

                    default:
                        result = ResultCode.UnknownError;
                        break;
                    }
                }
                else
                {
                    result = ResultCode.UnknownError;
                }

                // Log a warning if result was not a success.
                if (result != ResultCode.Created)
                {
                    Context.Log.Warning("Amex call failed. respCode: {0}. respText: {1}.",
                                        (int)DefaultLogEntryEventId.PartnerErrorWarning, code, text);
                }

                return(result);
            }, terminalCodes);

            return(result);
        }
예제 #7
0
        /// <summary>
        /// Removes the card in the context for the user in the context from this partner.
        /// </summary>
        /// <returns>
        /// A task that will yield the result code for the operation.
        /// </returns>
        public async Task <ResultCode> RemoveCardAsync()
        {
            ResultCode result = ResultCode.None;

            Card            card         = (Card)Context[Key.Card];
            PartnerCardInfo amexCardInfo = card.PartnerCardInfoList.SingleOrDefault(partnerCardInfo =>
                                                                                    partnerCardInfo.PartnerId == Partner.Amex);

            if (amexCardInfo != null)
            {
                // Build request
                AmexCardUnSyncRequest amexCardUnSyncRequest = new AmexCardUnSyncRequest
                {
                    CardToken1 = amexCardInfo.PartnerCardId
                };

                result = await PartnerUtilities.InvokePartner(Context, async() =>
                {
                    Context.Log.Verbose("Invoking partner RemoveCardAsync API.");
                    AmexCardResponse response = await AmexInvoker.RemoveCardAsync(amexCardUnSyncRequest);
                    Context.Log.Verbose("Partner RemoveCardAsync API returned: {0}: {1}.", response.ResponseCode, response.ResponseDescription);

                    string code = null;
                    string text = null;

                    if (response != null && response.ResponseCode != null)
                    {
                        code = response.ResponseCode;
                        text = response.ResponseDescription;

                        switch (code)
                        {
                        case AmexCardUnSyncResponseCode.RemoveCardSuccess:
                        case AmexCardUnSyncResponseCode.CardDoesNotExist:
                        case AmexCardUnSyncResponseCode.NoLinkedCards:
                            result = ResultCode.Success;
                            break;

                        default:
                            result = ResultCode.UnknownError;
                            break;
                        }
                    }
                    else
                    {
                        result = ResultCode.UnknownError;
                    }

                    // Log a warning if result was not a success.
                    if (result != ResultCode.Success)
                    {
                        Context.Log.Warning("Amex Data call failed. respCode: {0}. respText: {1}.",
                                            (int)DefaultLogEntryEventId.PartnerErrorWarning, code, text);
                    }

                    return(result);
                });
            }

            return(result);
        }
예제 #8
0
        /// <summary>
        /// Adds the card in the context for the user in the context to this partner.
        /// </summary>
        /// <returns>
        /// A task that will yield the result code for the operation.
        /// </returns>
        public async Task <ResultCode> AddCardAsync()
        {
            ResultCode result = ResultCode.None;

            // Build customer fields.
            string partnerCardId = General.GenerateShortGuid();

            HashStringElement[] customerFieldsElements = new HashStringElement[2]
            {
                new HashStringElement
                {
                    fieldName = MasterCardConstants.BankCustomerNumberFieldName,
                    data      = partnerCardId
                },
                new HashStringElement
                {
                    fieldName = MasterCardConstants.MemberIcaFieldName,
                    data      = MasterCardConstants.MemberIca
                }
            };

            // Build the customer account fields.
            HashStringElement[] customerAccountFieldsElements = new HashStringElement[4]
            {
                new HashStringElement
                {
                    fieldName = MasterCardConstants.BankAccountNumberFieldName,
                    data      = ((NewCardInfo)Context[Key.NewCardInfo]).Number
                },
                new HashStringElement
                {
                    fieldName = MasterCardConstants.BankProductCodeFieldName,
                    data      = MasterCardConstants.BankProductCode
                },
                new HashStringElement
                {
                    fieldName = MasterCardConstants.AccountStatusCodeFieldName,
                    data      = MasterCardConstants.AccountStatusActive
                },
                new HashStringElement
                {
                    fieldName = MasterCardConstants.ProgramIdentifierFieldName,
                    data      = MasterCardConstants.ProgramIdentifier
                }
            };

            // Build a card register request object.
            doEnrollment cardEnrollment = new doEnrollment
            {
                sourceId              = MasterCardConstants.SourceId,
                enrollmentTypeCode    = MasterCardConstants.EnrollmentTypeCode,
                customerFields        = customerFieldsElements,
                customerAccountFields = customerAccountFieldsElements
            };
            doEnrollmentRequest cardEnrollmentRequest = new doEnrollmentRequest
            {
                doEnrollment = cardEnrollment
            };

            LogAddCardRequestParameters(cardEnrollmentRequest);

            // Invoke the partner to add the card.
            result = await PartnerUtilities.InvokePartner(Context, async() =>
            {
                Context.Log.Verbose("Invoking partner AddCard API.");
                DoEnrollmentResp response = await MasterCardInvoker.AddCard(cardEnrollment).ConfigureAwait(false);
                Context.Log.Verbose("Partner AddCard API returned: {0}: {1}.", response.returnCode, response.returnMsg);
                LogAddCardResponseParameters(response);

                // Determine the ResultCode from the response code.
                PartnerCardInfo partnerCardInfo = GetMasterCardCardInfo((Card)Context[Key.Card]);
//TODO: Move PartnerCardSuffix into First Data-specific construct.
                partnerCardInfo.PartnerCardSuffix = "00";
                switch (response.returnCode)
                {
                case MasterCardResponseCode.Success:
                    result = ResultCode.Created;
                    partnerCardInfo.PartnerCardId = partnerCardId;
                    break;

                case MasterCardResponseCode.BankAccountNumberExists:
                    result = ResultCode.Created;
                    partnerCardInfo.PartnerCardId = response.bankCustomerNumber;
                    break;

                case MasterCardResponseCode.UnsupportedBin:
                case MasterCardResponseCode.MessageNotFound:
                    result = ResultCode.UnsupportedBin;
                    break;

                case MasterCardResponseCode.InvalidCard:
                    result = ResultCode.InvalidCard;
                    break;

                case MasterCardResponseCode.InvalidParameters:
                case MasterCardResponseCode.UnknownError:
                    result = ResultCode.UnknownError;
                    break;
                }

                // Log a warning if result was not a success.
                if (result != ResultCode.Created)
                {
                    Context.Log.Warning("MasterCard call failed. returnCode: {0}. returnMsg: {1}.",
                                        (int)DefaultLogEntryEventId.PartnerErrorWarning, response.returnCode, response.returnMsg);
                }

                return(result);
            }).ConfigureAwait(false);

            return(result);
        }