private async Task ShouldRequestSessionCreateSessionAcceptedResponse()
        {
            var request = new SessionRequest {
                Source = new SessionIdSource {
                    Id = "id"
                }
            };
            var response = new CreateSessionAcceptedResponse
            {
                AuthenticationDate = DateTime.Now,
                ChallengeIndicator = ChallengeIndicatorType.ChallengeRequestedMandate
            };

            _apiClient.Setup(apiClient =>
                             apiClient.Post <HttpMetadata>(Sessions,
                                                           _sdkCredentials.Object.GetSdkAuthorization(SdkAuthorizationType.OAuth),
                                                           SessionResponseMappings, request,
                                                           CancellationToken.None, null))
            .ReturnsAsync(() => response);

            _sessionsClient = new SessionsClient(_apiClient.Object, _configuration.Object);

            var getSessionResponse = await _sessionsClient.RequestSession(request, CancellationToken.None);

            getSessionResponse.ShouldNotBeNull();
            getSessionResponse.Accepted.ShouldNotBeNull();
            getSessionResponse.Accepted.AuthenticationDate.ShouldNotBeNull();
            getSessionResponse.Accepted.ChallengeIndicator.ShouldNotBeNull();
            getSessionResponse.Created.ShouldBeNull();
        }
Ejemplo n.º 2
0
        private async Task <SessionResponse> CreateSession(SessionRequest sessionRequest,
                                                           CancellationToken cancellationToken = default)
        {
            var resource = await ApiClient.Post <HttpMetadata>(SessionsPath, SdkAuthorization(), SessionResponseMappings,
                                                               sessionRequest, cancellationToken);

            switch (resource)
            {
            case CreateSessionOkResponse createSessionOkResponse:
                return(new SessionResponse(createSessionOkResponse));

            case CreateSessionAcceptedResponse createSessionAcceptedResponse:
                return(new SessionResponse(createSessionAcceptedResponse));

            default:
                throw new InvalidOperationException("Unexpected mapping type " + resource.GetType());
            }
        }
        private async Task ShouldRequestSessionCreateSessionOkResponse()
        {
            var request = new SessionRequest
            {
                Source = new SessionNetworkTokenSource
                {
                    Token = "token", ExpiryMonth = 12, ExpiryYear = 2024, Name = "name"
                }
            };
            var response = new CreateSessionOkResponse
            {
                Acs = new Acs {
                    ChallengeCancelReasonCode = "code"
                },
                SchemeInfo = new SchemeInfo
                {
                    Name = SessionScheme.CartesBancaires, Score = "score", Avalgo = "avalgo"
                }
            };

            _apiClient.Setup(apiClient =>
                             apiClient.Post <HttpMetadata>(Sessions,
                                                           _sdkCredentials.Object.GetSdkAuthorization(SdkAuthorizationType.OAuth),
                                                           SessionResponseMappings, request,
                                                           CancellationToken.None, null))
            .ReturnsAsync(() => response);

            _sessionsClient = new SessionsClient(_apiClient.Object, _configuration.Object);

            var getSessionResponse = await _sessionsClient.RequestSession(request, CancellationToken.None);

            getSessionResponse.ShouldNotBeNull();
            getSessionResponse.Accepted.ShouldBeNull();
            getSessionResponse.Created.ShouldNotBeNull();
            getSessionResponse.Created.Acs.ChallengeCancelReasonCode.ShouldNotBeNull();
            getSessionResponse.Created.SchemeInfo.ShouldNotBeNull();
            getSessionResponse.Created.SchemeInfo.Name.ShouldNotBeNull();
            getSessionResponse.Created.SchemeInfo.Score.ShouldNotBeNull();
            getSessionResponse.Created.SchemeInfo.Avalgo.ShouldNotBeNull();
        }
        protected async Task <SessionResponse> CreateHostedSession()
        {
            var shippingAddress = new SessionAddress
            {
                AddressLine1 = "Checkout.com",
                AddressLine2 = "90 Tottenham Court Road",
                City         = "London",
                State        = "ENG",
                Country      = CountryCode.GB,
                Zip          = "W1T 4TJ"
            };

            var sessionRequest = new SessionRequest
            {
                Source = new SessionCardSource {
                    ExpiryMonth = 1, ExpiryYear = 2030, Number = "4485040371536584"
                },
                Amount                 = 100L,
                Currency               = Currency.USD,
                ProcessingChannelId    = "pc_5jp2az55l3cuths25t5p3xhwru",
                AuthenticationType     = AuthenticationType.Regular,
                AuthenticationCategory = Category.Payment,
                ChallengeIndicator     = ChallengeIndicatorType.NoPreference,
                Reference              = "ORD-5023-4E89",
                TransactionType        = TransactionType.GoodsService,
                ShippingAddress        = shippingAddress,
                Completion             = new HostedCompletionInfo
                {
                    FailureUrl = "https://example.com/sessions/fail",
                    SuccessUrl = "https://example.com/sessions/success",
                }
            };

            return(await Retriable(
                       async() => await DefaultApi.SessionsClient().RequestSession(sessionRequest, CancellationToken.None),
                       HasSessionAccepted));
        }
Ejemplo n.º 5
0
 public async Task <SessionResponse> RequestSession(SessionRequest sessionRequest,
                                                    CancellationToken cancellationToken = default)
 {
     CheckoutUtils.ValidateParams("sessionRequest", sessionRequest);
     return(await CreateSession(sessionRequest, cancellationToken));
 }
        protected async Task <SessionResponse> CreateNonHostedSession(ChannelData channelData,
                                                                      Category authenticationCategory,
                                                                      ChallengeIndicatorType challengeIndicator,
                                                                      TransactionType transactionType)
        {
            var billingAddress = new SessionAddress
            {
                AddressLine1 = "CheckoutSdk.com",
                AddressLine2 = "90 Tottenham Court Road",
                City         = "London",
                State        = "ENG",
                Country      = CountryCode.GB
            };

            var source = new SessionCardSource
            {
                Number         = TestCardSource.Visa.Number,
                ExpiryMonth    = TestCardSource.Visa.ExpiryMonth,
                ExpiryYear     = TestCardSource.Visa.ExpiryYear,
                Name           = "John Doe",
                Email          = GenerateRandomEmail(),
                BillingAddress = billingAddress,
                HomePhone      = GetPhone(),
                MobilePhone    = GetPhone(),
                WorkPhone      = GetPhone()
            };

            var shippingAddress = new SessionAddress
            {
                AddressLine1 = "Checkout.com",
                AddressLine2 = "ABC building",
                AddressLine3 = "14 Wells Mews",
                City         = "London",
                State        = "ENG",
                Zip          = "W1T 4TJ",
                Country      = CountryCode.GB
            };

            var sessionRequest = new SessionRequest
            {
                Source              = source,
                Amount              = 6540L,
                Currency            = Currency.USD,
                ProcessingChannelId = "pc_5jp2az55l3cuths25t5p3xhwru",
                Marketplace         = new SessionMarketplaceData {
                    SubEntityId = "ent_ocw5i74vowfg2edpy66izhts2u"
                },
                AuthenticationCategory = authenticationCategory,
                ChallengeIndicator     = challengeIndicator,
                BillingDescriptor      = new SessionsBillingDescriptor {
                    Name = "SUPERHEROES.COM"
                },
                Reference       = "ORD-5023-4E89",
                TransactionType = transactionType,
                ShippingAddress = shippingAddress,
                Completion      = new NonHostedCompletionInfo {
                    CallbackUrl = "https://merchant.com/callback"
                },
                ChannelData = channelData
            };

            return(await Retriable(
                       async() => await DefaultApi.SessionsClient().RequestSession(sessionRequest, CancellationToken.None),
                       HasSessionCreated));
        }