Exemplo n.º 1
0
        /// <summary>
        /// Adds the described card to MasterCard.
        /// </summary>
        /// <param name="doEnrollmentRequest">
        /// Description of the card to add.
        /// </param>
        /// <returns>
        /// The response from MasterCard for the add card attempt.
        /// </returns>
        public async Task <DoEnrollmentResp> AddCard(doEnrollment doEnrollmentRequest)
        {
            DoEnrollmentResp result = null;

            using (masterCardMRSServiceClient registrationClient = new masterCardMRSServiceClient("mastercardregistrationserviceSoap11"))
            {
                Stopwatch sprocTimer = Stopwatch.StartNew();
                try
                {
                    doEnrollmentResponse1 response1 = await registrationClient.doEnrollmentAsync(doEnrollmentRequest).ConfigureAwait(false);

                    result = response1.doEnrollmentResponse.doEnrollmentResult;
                }
                finally
                {
                    sprocTimer.Stop();
                    PerformanceInformation.Add("MasterCard DoEnrollment (add card)",
                                               String.Format("{0} ms", sprocTimer.ElapsedMilliseconds));
                }
            }

            return(result);
        }
Exemplo n.º 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);
        }