Exemplo n.º 1
0
        /// <summary>
        /// send the cipher text to TokenEx to Obtain a token.
        /// http://docs.tokenex.com/#tokenex-api-token-services-tokenizefromencryptedvalue
        /// </summary>
        /// <param name="ciperText"></param>
        /// <returns></returns>
        static string Tokenize(string ciperText)
        {
            TokenizeRequest req = new TokenizeRequest();

            req.TokenExID    = Config.TokenExID;
            req.APIKey       = Config.APIKey;
            req.EcryptedData = ciperText;
            req.TokenScheme  = Config.TokenScheme;

            try
            {
                TokenizeResponse result = new TokenizeResponse();
                using (HttpClient client = new HttpClient())
                {
                    var HTTPresult = client.PostAsJsonAsync <TokenizeRequest>(Config.BBEURL, req).Result;

                    result = HTTPresult.Content.ReadAsAsync <TokenizeResponse>().Result;
                }

                if (result.Success)
                {
                    return(result.Token);
                }
                else
                {
                    return(result.Error);
                }
            }
            catch (Exception ex)
            {
                return($"An error occurred:  {ex.Message} ");
            }
        }
Exemplo n.º 2
0
        public static void Run()
        {
            var generateKeyResult = GenerateKey.Run();
            var keyId             = generateKeyResult.KeyId;
            var derFormat         = generateKeyResult.Der.Format;
            var derAlgo           = generateKeyResult.Der.Algorithm;
            var derPublicKey      = generateKeyResult.Der.PublicKey;

            var requestObj = new TokenizeRequest
            {
                KeyId    = keyId,
                CardInfo = new Flexv1tokensCardInfo()
                {
                    CardExpirationYear  = "2031",
                    CardNumber          = "5555555555554444",
                    CardType            = "002",
                    CardExpirationMonth = "03"
                }
            };

            try
            {
                var configDictionary = new Configuration().GetConfiguration();
                var clientConfig     = new CyberSource.Client.Configuration(merchConfigDictObj: configDictionary);
                var apiInstance      = new FlexTokenApi(clientConfig);

                var result = apiInstance.Tokenize(requestObj);
                Console.WriteLine(result);

                var flexPublicKey = new FlexPublicKey(keyId, new FlexServerSDK.Model.DerPublicKey(derFormat, derAlgo, derPublicKey), null);
                var flexToken     = new FlexToken()
                {
                    keyId                = result.KeyId,
                    token                = result.Token,
                    maskedPan            = result.MaskedPan,
                    cardType             = result.CardType,
                    timestamp            = (long)result.Timestamp,
                    signedFields         = result.SignedFields,
                    signature            = result.Signature,
                    discoverableServices = result.DiscoverableServices
                };

                IDictionary <string, string> postParameters = new Dictionary <string, string>();
                postParameters["signedFields"] = flexToken.signedFields;
                postParameters["signature"]    = flexToken.signature;
                postParameters["cardType"]     = flexToken.cardType;
                postParameters["keyId"]        = flexToken.keyId;
                postParameters["maskedPan"]    = flexToken.maskedPan;
                postParameters["token"]        = flexToken.token;
                postParameters["timestamp"]    = Convert.ToString(flexToken.timestamp);

                var tokenVerificationResult = Verify(flexPublicKey, postParameters);
                Console.WriteLine(tokenVerificationResult);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception on calling the API: " + e.Message);
            }
        }
        /// <summary>
        /// Flex Tokenize card Returns a token representing the supplied card details. The token replaces card data and can be used as the Subscription ID in the CyberSource Simple Order API or SCMP API. This is an unauthenticated call that you should initiate from your customer’s device or browser.
        /// </summary>
        /// <exception cref="CyberSource.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="tokenizeRequest"> (optional)</param>
        /// <returns>Task of ApiResponse (FlexV1TokensPost200Response)</returns>
        public async System.Threading.Tasks.Task <ApiResponse <FlexV1TokensPost200Response> > TokenizeAsyncWithHttpInfo(TokenizeRequest tokenizeRequest = null)
        {
            var    localVarPath         = $"/flex/v1/tokens/";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new Dictionary <String, String>();
            var    localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json;charset=utf-8"
            };
            String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "application/json"
            };
            String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (tokenizeRequest != null && tokenizeRequest.GetType() != typeof(byte[]))
            {
                localVarPostBody = Configuration.ApiClient.Serialize(tokenizeRequest); // http body (model) parameter
            }
            else
            {
                localVarPostBody = tokenizeRequest; // byte array
            }


            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)await Configuration.ApiClient.CallApiAsync(localVarPath,
                                                                                                       Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                       localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("Tokenize", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <FlexV1TokensPost200Response>(localVarStatusCode,
                                                                 localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                                                                 (FlexV1TokensPost200Response)Configuration.ApiClient.Deserialize(localVarResponse, typeof(FlexV1TokensPost200Response))));
        }
        /// <summary>
        /// Tokenize Card Returns a token representing the supplied card details. The token replaces card data and can be used as the Subscription ID in the CyberSource Simple Order API or SCMP API. This is an unauthenticated call that you should initiate from your customer’s device or browser.
        /// </summary>
        /// <exception cref="CyberSource.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="tokenizeRequest"></param>
        /// <returns>FlexV1TokensPost200Response</returns>
        public FlexV1TokensPost200Response Tokenize(TokenizeRequest tokenizeRequest)
        {
            logger.Debug("CALLING API \"Tokenize\" STARTED");
            this.SetStatusCode(null);
            ApiResponse <FlexV1TokensPost200Response> localVarResponse = TokenizeWithHttpInfo(tokenizeRequest);

            logger.Debug("CALLING API \"Tokenize\" ENDED");
            this.SetStatusCode(localVarResponse.StatusCode);
            return(localVarResponse.Data);
        }
        /// <summary>
        /// Flex Tokenize card Returns a token representing the supplied card details. The token replaces card data and can be used as the Subscription ID in the CyberSource Simple Order API or SCMP API. This is an unauthenticated call that you should initiate from your customer’s device or browser.
        /// </summary>
        /// <exception cref="CyberSource.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="tokenizeRequest"> (optional)</param>
        /// <returns>Task of FlexV1TokensPost200Response</returns>
        public async System.Threading.Tasks.Task <FlexV1TokensPost200Response> TokenizeAsync(TokenizeRequest tokenizeRequest = null)
        {
            ApiResponse <FlexV1TokensPost200Response> localVarResponse = await TokenizeAsyncWithHttpInfo(tokenizeRequest);

            return(localVarResponse.Data);
        }
        /// <summary>
        /// Flex Tokenize card Returns a token representing the supplied card details. The token replaces card data and can be used as the Subscription ID in the CyberSource Simple Order API or SCMP API. This is an unauthenticated call that you should initiate from your customer’s device or browser.
        /// </summary>
        /// <exception cref="CyberSource.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="tokenizeRequest"> (optional)</param>
        /// <returns>FlexV1TokensPost200Response</returns>
        public FlexV1TokensPost200Response Tokenize(TokenizeRequest tokenizeRequest = null)
        {
            ApiResponse <FlexV1TokensPost200Response> localVarResponse = TokenizeWithHttpInfo(tokenizeRequest);

            return(localVarResponse.Data);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Tokenize Card Returns a token representing the supplied card details. The token replaces card data and can be used as the Subscription ID in the CyberSource Simple Order API or SCMP API. This is an unauthenticated call that you should initiate from your customer’s device or browser.
        /// </summary>
        /// <exception cref="CyberSource.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="tokenizeRequest"></param>
        /// <returns>ApiResponse of FlexV1TokensPost200Response</returns>
        public ApiResponse <FlexV1TokensPost200Response> TokenizeWithHttpInfo(TokenizeRequest tokenizeRequest)
        {
            // verify the required parameter 'tokenizeRequest' is set
            if (tokenizeRequest == null)
            {
                throw new ApiException(400, "Missing required parameter 'tokenizeRequest' when calling TokenizationApi->Tokenize");
            }

            var    localVarPath         = $"/flex/v1/tokens";
            var    localVarPathParams   = new Dictionary <string, string>();
            var    localVarQueryParams  = new Dictionary <string, string>();
            var    localVarHeaderParams = new Dictionary <string, string>(Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <string, string>();
            var    localVarFileParams   = new Dictionary <string, FileParameter>();
            object localVarPostBody     = null;

            // to determine the Content-Type header
            string[] localVarHttpContentTypes = new string[] {
                "application/json;charset=utf-8"
            };
            string localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            string[] localVarHttpHeaderAccepts = new string[] {
                "application/json"
            };
            string localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (tokenizeRequest != null && tokenizeRequest.GetType() != typeof(byte[]))
            {
                localVarPostBody = Configuration.ApiClient.Serialize(tokenizeRequest); // http body (model) parameter
            }
            else
            {
                localVarPostBody = tokenizeRequest; // byte array
            }

            if (false)
            {
            }
            else
            {
            }


            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)Configuration.ApiClient.CallApi(localVarPath,
                                                                                            Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                            localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("Tokenize", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <FlexV1TokensPost200Response>(localVarStatusCode,
                                                                 localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                                                                 (FlexV1TokensPost200Response)Configuration.ApiClient.Deserialize(localVarResponse, typeof(FlexV1TokensPost200Response)))); // Return statement
        }
Exemplo n.º 8
0
        public static void Run(IReadOnlyDictionary <string, string> configDictionary)
        {
            var generateKeyResult = GenerateKey.GenerateKeyResult(configDictionary);
            var keyId             = generateKeyResult.KeyId;
            var derFormat         = generateKeyResult.Der.Format;
            var derAlgo           = generateKeyResult.Der.Algorithm;
            var derPublicKey      = generateKeyResult.Der.PublicKey;

            var requestObj = new TokenizeRequest
            {
                KeyId    = keyId,
                CardInfo = new Paymentsflexv1tokensCardInfo()
                {
                    CardExpirationYear  = "2031",
                    CardNumber          = "5555555555554444",
                    CardType            = "002",
                    CardExpirationMonth = "03"
                }
            };

            var merchantConfig = new MerchantConfig(configDictionary)
            {
                RequestType     = "POST",
                RequestTarget   = "/flex/v1/tokens",
                RequestJsonData = JsonConvert.SerializeObject(requestObj)
            };

            try
            {
                var configurationSwagger = new ApiClient().CallAuthenticationHeader(merchantConfig);
                var apiInstance          = new TokenizationApi(configurationSwagger);
                var result = apiInstance.Tokenize(requestObj);
                Console.WriteLine(result);

                var flexPublicKey = new FlexPublicKey(keyId, new FlexServerSDK.Model.DerPublicKey(derFormat, derAlgo, derPublicKey), null);
                var flexToken     = new FlexToken()
                {
                    keyId                = result.KeyId,
                    token                = result.Token,
                    maskedPan            = result.MaskedPan,
                    cardType             = result.CardType,
                    timestamp            = (long)result.Timestamp,
                    signedFields         = result.SignedFields,
                    signature            = result.Signature,
                    discoverableServices = result.DiscoverableServices
                };

                //var tokenVerificationResult = Verify(
                //    configDictionary["merchantID"],
                //    configDictionary["merchantKeyId"],
                //    configDictionary["merchantsecretKey"],
                //    flexPublicKey,
                //    flexToken);
                // Console.WriteLine(tokenVerificationResult);

                IDictionary <string, string> postParameters = new Dictionary <string, string>();
                postParameters["signedFields"] = flexToken.signedFields;
                postParameters["signature"]    = flexToken.signature;
                postParameters["cardType"]     = flexToken.cardType;
                postParameters["keyId"]        = flexToken.keyId;
                postParameters["maskedPan"]    = flexToken.maskedPan;
                postParameters["token"]        = flexToken.token;
                postParameters["timestamp"]    = Convert.ToString(flexToken.timestamp);

                var tokenVerificationResult = Verify(flexPublicKey, postParameters);
                Console.WriteLine(tokenVerificationResult);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception on calling the API: " + e.Message);
            }
        }
Exemplo n.º 9
0
        public static FlexV1TokensPost200Response Run()
        {
            var    generateKeyResult = GenerateKeyLegacyTokenFormat.Run();
            string keyId             = generateKeyResult.KeyId;
            var    derFormat         = generateKeyResult.Der.Format;
            var    derAlgo           = generateKeyResult.Der.Algorithm;
            var    derPublicKey      = generateKeyResult.Der.PublicKey;

            string cardInfoCardNumber          = "4111111111111111";
            string cardInfoCardExpirationMonth = "12";
            string cardInfoCardExpirationYear  = "2031";
            string cardInfoCardType            = "001";
            Flexv1tokensCardInfo cardInfo      = new Flexv1tokensCardInfo(
                CardNumber: cardInfoCardNumber,
                CardExpirationMonth: cardInfoCardExpirationMonth,
                CardExpirationYear: cardInfoCardExpirationYear,
                CardType: cardInfoCardType
                );

            var requestObj = new TokenizeRequest(
                KeyId: keyId,
                CardInfo: cardInfo
                );

            try
            {
                var configDictionary = new Configuration().GetConfiguration();
                var clientConfig     = new CyberSource.Client.Configuration(merchConfigDictObj: configDictionary);

                var apiInstance = new TokenizationApi(clientConfig);
                FlexV1TokensPost200Response result = apiInstance.Tokenize(requestObj);
                Console.WriteLine(result);

                TokenVerificationUtility tokenVerifier = new TokenVerificationUtility();

                var flexPublicKey = new FlexPublicKey(keyId, new FlexDerPublicKey(derFormat, derAlgo, derPublicKey), null);
                var flexToken     = new FlexToken()
                {
                    keyId                = result.KeyId,
                    token                = result.Token,
                    maskedPan            = result.MaskedPan,
                    cardType             = result.CardType,
                    timestamp            = (long)result.Timestamp,
                    signedFields         = result.SignedFields,
                    signature            = result.Signature,
                    discoverableServices = result.DiscoverableServices
                };

                IDictionary <string, string> postParameters = new Dictionary <string, string>();
                postParameters["signedFields"] = flexToken.signedFields;
                postParameters["signature"]    = flexToken.signature;
                postParameters["cardType"]     = flexToken.cardType;
                postParameters["keyId"]        = flexToken.keyId;
                postParameters["maskedPan"]    = flexToken.maskedPan;
                postParameters["token"]        = flexToken.token;
                postParameters["timestamp"]    = Convert.ToString(flexToken.timestamp);

                var tokenVerificationResult = tokenVerifier.Verify(flexPublicKey, postParameters);
                Console.WriteLine("TOKEN VERIFICATION : " + tokenVerificationResult);

                return(result);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception on calling the API : " + e.Message);
                return(null);
            }
        }
        /// <summary>
        /// Tokenize Card Returns a token representing the supplied card details. The token replaces card data and can be used as the Subscription ID in the CyberSource Simple Order API or SCMP API. This is an unauthenticated call that you should initiate from your customer’s device or browser.
        /// </summary>
        /// <exception cref="CyberSource.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="tokenizeRequest"></param>
        /// <returns>Task of ApiResponse (FlexV1TokensPost200Response)</returns>
        public async System.Threading.Tasks.Task <ApiResponse <FlexV1TokensPost200Response> > TokenizeAsyncWithHttpInfo(TokenizeRequest tokenizeRequest)
        {
            LogUtility logUtility = new LogUtility();

            // verify the required parameter 'tokenizeRequest' is set
            if (tokenizeRequest == null)
            {
                logger.Error("ApiException : Missing required parameter 'tokenizeRequest' when calling TokenizationApi->Tokenize");
                throw new ApiException(400, "Missing required parameter 'tokenizeRequest' when calling TokenizationApi->Tokenize");
            }

            var    localVarPath         = $"/flex/v1/tokens";
            var    localVarPathParams   = new Dictionary <string, string>();
            var    localVarQueryParams  = new Dictionary <string, string>();
            var    localVarHeaderParams = new Dictionary <string, string>(Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <string, string>();
            var    localVarFileParams   = new Dictionary <string, FileParameter>();
            object localVarPostBody     = null;

            // to determine the Content-Type header
            string[] localVarHttpContentTypes = new string[] {
                "application/json;charset=utf-8"
            };
            string localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            string[] localVarHttpHeaderAccepts = new string[] {
                "application/json"
            };
            string localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (tokenizeRequest != null && tokenizeRequest.GetType() != typeof(byte[]))
            {
                localVarPostBody = Configuration.ApiClient.Serialize(tokenizeRequest); // http body (model) parameter
            }
            else
            {
                localVarPostBody = tokenizeRequest; // byte array
            }

            if (logUtility.IsMaskingEnabled(logger))
            {
                logger.Debug($"HTTP Request Body :\n{logUtility.MaskSensitiveData(localVarPostBody.ToString())}");
            }
            else
            {
                logger.Debug($"HTTP Request Body :\n{localVarPostBody}");
            }


            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)await Configuration.ApiClient.CallApiAsync(localVarPath,
                                                                                                       Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                       localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("Tokenize", localVarResponse);
                if (exception != null)
                {
                    logger.Error($"Exception : {exception.Message}");
                    throw exception;
                }
            }

            return(new ApiResponse <FlexV1TokensPost200Response>(localVarStatusCode,
                                                                 localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                                                                 (FlexV1TokensPost200Response)Configuration.ApiClient.Deserialize(localVarResponse, typeof(FlexV1TokensPost200Response)))); // Return statement
        }
        /// <summary>
        /// Tokenize Card Returns a token representing the supplied card details. The token replaces card data and can be used as the Subscription ID in the CyberSource Simple Order API or SCMP API. This is an unauthenticated call that you should initiate from your customer’s device or browser.
        /// </summary>
        /// <exception cref="CyberSource.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="tokenizeRequest"></param>
        /// <returns>Task of FlexV1TokensPost200Response</returns>
        public async System.Threading.Tasks.Task <FlexV1TokensPost200Response> TokenizeAsync(TokenizeRequest tokenizeRequest)
        {
            logger.Debug("CALLING API \"TokenizeAsync\" STARTED");
            this.SetStatusCode(null);
            ApiResponse <FlexV1TokensPost200Response> localVarResponse = await TokenizeAsyncWithHttpInfo(tokenizeRequest);

            logger.Debug("CALLING API \"TokenizeAsync\" ENDED");
            this.SetStatusCode(localVarResponse.StatusCode);
            return(localVarResponse.Data);
        }
Exemplo n.º 12
0
        private async Task <TokenizedCreditCardResponse> Tokenize(CmtPaymentServiceClient cmtPaymentServiceClient, string nameOnCard,
                                                                  string accountNumber, DateTime expiryDate, string cvv, string kountSessionId, string zipCode, Account account)
        {
            try
            {
                var request = new TokenizeRequest
                {
                    AccountNumber     = accountNumber,
                    ExpiryDate        = expiryDate.ToString("yyMM", CultureInfo.InvariantCulture),
                    Cvv               = cvv,
                    SessionId         = kountSessionId,
                    Email             = account.Email,
                    BillingFullName   = nameOnCard,
                    CustomerId        = account.Id.ToString(),
                    CustomerIpAddress = _ipAddressManager.GetIPAddress()
                };

                if (zipCode.HasValue())
                {
                    request.ZipCode = zipCode;
                }

                var response = await cmtPaymentServiceClient.PostAsync(request);

                return(new TokenizedCreditCardResponse
                {
                    CardOnFileToken = response.CardOnFileToken,
                    IsSuccessful = response.ResponseCode == 1,
                    Message = response.ResponseMessage,
                    CardType = response.CardType,
                    LastFour = response.LastFour,
                });
            }
            catch (Exception e)
            {
                _logger.Maybe(x => x.LogMessage("Error during CMT tokenization"));

                var message = GetTokenizationErrorMessageFromCMT(e);
                if (message.HasValueTrimmed())
                {
                    return(new TokenizedCreditCardResponse
                    {
                        IsSuccessful = false,
                        Message = message
                    });
                }

                // the exception is not a cmt error, log the exception
                _logger.Maybe(x => x.LogError(e));

                message = e.Message;
                var exception = e as AggregateException;
                if (exception != null)
                {
                    message = exception.InnerException.Message;
                }

                return(new TokenizedCreditCardResponse
                {
                    IsSuccessful = false,
                    Message = message
                });
            }
        }
 public TokenizeResponse(TokenizeRequest req, string identifier, string auth)
     : base(req)
 {
     Identifier    = identifier;
     Authenticable = auth;
 }