Пример #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
        /// <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);
        }