Exemple #1
0
        public virtual GetCustomerProfileResponse GetCustomerProfile(GetCustomerProfileRequest request)
        {
            Ensure.That(request, "request").IsNotNull();

            var httpRequest  = GetCustomerProfileHttpRequestFactory.Create(request);
            var httpResponse = Connection.Send(httpRequest);

            return(ResponseFactory.Create <GetCustomerProfileResponse>(httpResponse));
        }
        public async Task <GetCustomerProfileResponse> GetAsync(string referenceId, string customerProfileId, bool unmaskExpDate)
        {
            var getCustomerProfileRequest = new GetCustomerProfileRequest
            {
                GetProfileTransactionRequest = new GetProfileTransactionRequest
                {
                    MerchantAuthentication = new MerchantAuthentication
                    {
                        LoginId        = _apiLoginId,
                        TransactionKey = _transactionKey
                    },
                    ReferenceId          = referenceId,
                    CustomerProfileId    = customerProfileId,
                    UnmaskExpirationDate = unmaskExpDate
                }
            };

            return(await GetAsync(getCustomerProfileRequest));
        }
 public Task <GetCustomerProfileResponse> GetAsync(
     GetCustomerProfileRequest request,
     CancellationToken cancellationToken = default)
 {
     return(_get.PostAsync(request, cancellationToken));
 }
 public async Task <GetCustomerProfileResponse> GetAsync(GetCustomerProfileRequest getCustomerProfileRequest)
 {
     return(await new AuthorizeNetResult(_authorizeNetUrl).PostAsync <GetCustomerProfileRequest, GetCustomerProfileResponse>(getCustomerProfileRequest));
 }
Exemple #5
0
    public async Task TestCustomerProfileAsync(CustomerProfile profile, CancellationToken cancellationToken)
    {
        // 1. create customer / payment profile with validation enabled.
        var paymentProfiles = new Collection <CustomerPaymentProfileType>
        {
            new CustomerPaymentProfileType
            {
                CustomerType = profile.CustomerType,
                Payment      = new PaymentType
                {
                    CreditCard = new CreditCardType
                    {
                        CardNumber     = profile.CardNumber,
                        ExpirationDate = profile.ExpirationDate,
                        CardCode       = profile.CardCode
                    }
                },
                BillTo = new CustomerAddressType
                {
                    FirstName = profile.FirstName,
                    LastName  = profile.LastName,
                    Address   = profile.StreetLine,
                    Company   = profile.Company,
                    City      = profile.City,
                    State     = profile.StateOrProvice,
                    Zip       = profile.ZipCode,
                    Country   = profile.Country
                }
            }
        };

        var createRequest = new CreateCustomerProfileRequest
        {
            RefId          = profile.ReferenceId,
            ValidationMode = _options.ValidationMode,
            Profile        = new CustomerProfileType
            {
                Description        = profile.Description,
                Email              = profile.Email,
                MerchantCustomerId = profile.CustomerId,
                ProfileType        = profile.CustomerProfileType,
                PaymentProfiles    = paymentProfiles,
            },
        };

        var createResponse = await _customerProfileClient.CreateAsync(createRequest, cancellationToken);

        // validation list is in the same order as it has been submitted by the client code
        var parsedCreation = new PaymentGatewayResponse(createResponse.ValidationDirectResponseList[0]);

        // creation for the profile was successful
        if (createResponse.Messages.ResultCode == MessageTypeEnum.Ok)
        {
            var customerProfileId        = createResponse.CustomerProfileId;
            var customerPaymentProfileId = createResponse.CustomerPaymentProfileIdList[0];

            _logger.LogInformation(
                "CreateResponse - {customerProfileId} - {paymentProfile} - {asvCode}",
                customerProfileId,
                createResponse.CustomerPaymentProfileIdList[0],
                parsedCreation.AVSResponseText);

            DisplayResponse("CreateResponse", createResponse);

            // 2. create another payment profile
            var secondaryProfile = _sampleData.GetCustomerProfiles()[1];

            var secondaryProfileRequest = new CreateCustomerPaymentProfileRequest
            {
                RefId             = profile.ReferenceId,
                ValidationMode    = _options.ValidationMode,
                CustomerProfileId = customerProfileId,
                PaymentProfile    = new CustomerPaymentProfileType
                {
                    Payment = new PaymentType
                    {
                        CreditCard = new CreditCardType
                        {
                            CardCode       = secondaryProfile.CardCode,
                            CardNumber     = secondaryProfile.CardNumber,
                            ExpirationDate = secondaryProfile.ExpirationDate,
                        }
                    },
                    CustomerType = CustomerTypeEnum.Business,
                    BillTo       = new CustomerAddressType
                    {
                        FirstName = secondaryProfile.FirstName,
                        LastName  = secondaryProfile.LastName,
                        Address   = secondaryProfile.StreetLine,
                        Company   = secondaryProfile.Company,
                        City      = secondaryProfile.City,
                        State     = secondaryProfile.StateOrProvice,
                        Zip       = secondaryProfile.ZipCode,
                        Country   = secondaryProfile.Country
                    }
                }
            };

            var secondaryPaymentResponse = await _customerPaymentProfileClient.CreateAsync(secondaryProfileRequest, cancellationToken);

            var secondaryProfileId = secondaryPaymentResponse.CustomerPaymentProfileId;

            if (secondaryPaymentResponse.Messages.ResultCode == MessageTypeEnum.Ok)
            {
                var validateRequest = new ValidateCustomerPaymentProfileRequest
                {
                    CustomerPaymentProfileId = secondaryProfileId,
                    CustomerProfileId        = customerProfileId,
                    ValidationMode           = _options.ValidationMode,
                    RefId = profile.ReferenceId
                };

                var validateResponse = await _customerPaymentProfileClient.ValidateAsync(validateRequest, cancellationToken);

                var parsedValidation = new PaymentGatewayResponse(validateResponse?.DirectResponse !);

                if (validateResponse?.Messages.ResultCode == MessageTypeEnum.Error)
                {
                    _logger.LogWarning("{cardNumber}-{expDate}-{ccv}-{zip}-{parsed}", profile.CardNumber, profile.ExpirationDate, profile.CardCode, profile.ZipCode, parsedValidation.ResponseReasonText);
                    _logger.LogWarning(validateResponse.DirectResponse);
                }

                DisplayResponse("ValidationResponse", validateResponse !);

                // get customer profile
                var customerRequest = new GetCustomerProfileRequest
                {
                    CustomerProfileId = customerProfileId
                };

                var customerResponse = await _customerProfileClient.GetAsync(customerRequest, cancellationToken);

                DisplayResponse(" GetCustomerProfileResponse", customerResponse);

                var paymentRequest = new GetCustomerPaymentProfileRequest
                {
                    CustomerPaymentProfileId = customerPaymentProfileId,
                    CustomerProfileId        = customerProfileId,
                    UnmaskExpirationDate     = true
                };

                var paymentResponse = await _customerPaymentProfileClient.GetAsync(paymentRequest, cancellationToken);

                DisplayResponse(" GetCustomerPaymentProfileResponse", paymentResponse);
            }
        }

        _logger.LogWarning("CreateResponse - {responseCode}", parsedCreation.ResponseCode);

        // delete
        var deleteResponse = await _customerProfileClient.DeleteAsync(
            new DeleteCustomerProfileRequest
        {
            CustomerProfileId = createResponse.CustomerProfileId,
            RefId             = profile.ReferenceId
        },
            cancellationToken);

        DisplayResponse("DeleteResponse", deleteResponse);
    }