diff --git a/Source/ConfigurationWithMLE.cs b/Source/ConfigurationWithMLE.cs new file mode 100644 index 0000000..d17055b --- /dev/null +++ b/Source/ConfigurationWithMLE.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using Cybersource_rest_samples_dotnet.Samples.Payments; + +namespace Cybersource_rest_samples_dotnet +{ + class ConfigurationWithMLE + { + // initialize dictionary object + private readonly Dictionary _configurationDictionary = new Dictionary(); + private readonly Dictionary _configurationDictionaryforMLE = new Dictionary(); + + public Dictionary GetMapToControlMLE() + { + _configurationDictionaryforMLE.Add("CreatePayment", true); //CreatePayment function will have MLE=true i.e. (/pts/v2/payments POST API) + _configurationDictionaryforMLE.Add("CapturePayment", false); //capturePayment function will have MLE=false i.e. (/pts/v2/payments/{id}/captures POST API) + + return _configurationDictionaryforMLE; + } + + public Dictionary GetConfiguration1() + { + _configurationDictionary.Add("authenticationType", "JWT"); //mle only supoort with JWT Auth Type + _configurationDictionary.Add("merchantID", "testrest"); + _configurationDictionary.Add("merchantsecretKey", "yBJxy6LjM2TmcPGu+GaJrHtkke25fPpUX+UY6/L/1tE="); + _configurationDictionary.Add("merchantKeyId", "08c94330-f618-42a3-b09d-e1e43be5efda"); + _configurationDictionary.Add("keysDirectory", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\..\\Source\\Resource")); + _configurationDictionary.Add("keyFilename", "testrest"); + _configurationDictionary.Add("runEnvironment", "apitest.cybersource.com"); + _configurationDictionary.Add("keyAlias", "testrest"); + _configurationDictionary.Add("keyPass", "testrest"); + + //MLE configs + _configurationDictionary.Add("useMLEGlobally", "true"); //globally MLE will be enabled for all the MLE supported APIs by Cybs in SDK + _configurationDictionary.Add("mleKeyAlias", "CyberSource_SJC_US"); //this is optional paramter, not required to set the parameter/value if custom value is not required for MLE key alias. Default value is "CyberSource_SJC_US". + + + // Configs related to meta key + _configurationDictionary.Add("portfolioID", string.Empty); + _configurationDictionary.Add("useMetaKey", "false"); + + /* + * Add the property if required to override the cybs default developerId in all request body + */ + _configurationDictionary.Add("defaultDeveloperId", ""); + + return _configurationDictionary; + } + + + public Dictionary GetConfiguration2() + { + _configurationDictionary.Add("authenticationType", "JWT"); + _configurationDictionary.Add("merchantID", "testrest"); + _configurationDictionary.Add("merchantsecretKey", "yBJxy6LjM2TmcPGu+GaJrHtkke25fPpUX+UY6/L/1tE="); + _configurationDictionary.Add("merchantKeyId", "08c94330-f618-42a3-b09d-e1e43be5efda"); + _configurationDictionary.Add("keysDirectory", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\..\\Source\\Resource")); + _configurationDictionary.Add("keyFilename", "testrest"); + _configurationDictionary.Add("runEnvironment", "apitest.cybersource.com"); + _configurationDictionary.Add("keyAlias", "testrest"); + _configurationDictionary.Add("keyPass", "testrest"); + + //mle configs + _configurationDictionary.Add("useMLEGlobally", "false"); //globally MLE will be disabled for all the MLE supported APIs by Cybs in SDK + _configurationDictionary.Add("mleKeyAlias", "CyberSource_SJC_US"); //this is optional paramter, not required to set the parameter/value if custom value is not required for MLE key alias. Default value is "CyberSource_SJC_US". + + + // Configs related to meta key + _configurationDictionary.Add("portfolioID", string.Empty); + _configurationDictionary.Add("useMetaKey", "false"); + + /* + * Add the property if required to override the cybs default developerId in all request body + */ + _configurationDictionary.Add("defaultDeveloperId", ""); + + return _configurationDictionary; + } + } +} + + \ No newline at end of file diff --git a/Source/Samples/MLEFeature/PaymentsWithGlobalMLE.cs b/Source/Samples/MLEFeature/PaymentsWithGlobalMLE.cs new file mode 100644 index 0000000..8223419 --- /dev/null +++ b/Source/Samples/MLEFeature/PaymentsWithGlobalMLE.cs @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; +using System.Text; +using CyberSource.Api; +using CyberSource.Client; +using CyberSource.Model; + +namespace Cybersource_rest_samples_dotnet.Samples.MLEFeature +{ + class PaymentsWithGlobalMLE + { + + + public static void WriteLogAudit(int status) + { + var filePath = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString().Split('.'); + var filename = filePath[filePath.Length - 1]; + Console.WriteLine($"[Sample Code Testing] [{filename}] {status}"); + } + + public static bool CaptureTrueForProcessPayment { get; set; } = false; + + public static PtsV2PaymentsPost201Response Run() + { + string clientReferenceInformationCode = "TC50171_3"; + Ptsv2paymentsClientReferenceInformation clientReferenceInformation = new Ptsv2paymentsClientReferenceInformation( + Code: clientReferenceInformationCode + ); + + bool processingInformationCapture = false; + if (CaptureTrueForProcessPayment) + { + processingInformationCapture = true; + } + + Ptsv2paymentsProcessingInformation processingInformation = new Ptsv2paymentsProcessingInformation( + Capture: processingInformationCapture + ); + + string paymentInformationCardNumber = "4111111111111111"; + string paymentInformationCardExpirationMonth = "12"; + string paymentInformationCardExpirationYear = "2031"; + Ptsv2paymentsPaymentInformationCard paymentInformationCard = new Ptsv2paymentsPaymentInformationCard( + Number: paymentInformationCardNumber, + ExpirationMonth: paymentInformationCardExpirationMonth, + ExpirationYear: paymentInformationCardExpirationYear + ); + + Ptsv2paymentsPaymentInformation paymentInformation = new Ptsv2paymentsPaymentInformation( + Card: paymentInformationCard + ); + + string orderInformationAmountDetailsTotalAmount = "102.21"; + string orderInformationAmountDetailsCurrency = "USD"; + Ptsv2paymentsOrderInformationAmountDetails orderInformationAmountDetails = new Ptsv2paymentsOrderInformationAmountDetails( + TotalAmount: orderInformationAmountDetailsTotalAmount, + Currency: orderInformationAmountDetailsCurrency + ); + + string orderInformationBillToFirstName = "John"; + string orderInformationBillToLastName = "Doe"; + string orderInformationBillToAddress1 = "1 Market St"; + string orderInformationBillToLocality = "san francisco"; + string orderInformationBillToAdministrativeArea = "CA"; + string orderInformationBillToPostalCode = "94105"; + string orderInformationBillToCountry = "US"; + string orderInformationBillToEmail = "test@cybs.com"; + string orderInformationBillToPhoneNumber = "4158880000"; + Ptsv2paymentsOrderInformationBillTo orderInformationBillTo = new Ptsv2paymentsOrderInformationBillTo( + FirstName: orderInformationBillToFirstName, + LastName: orderInformationBillToLastName, + Address1: orderInformationBillToAddress1, + Locality: orderInformationBillToLocality, + AdministrativeArea: orderInformationBillToAdministrativeArea, + PostalCode: orderInformationBillToPostalCode, + Country: orderInformationBillToCountry, + Email: orderInformationBillToEmail, + PhoneNumber: orderInformationBillToPhoneNumber + ); + + Ptsv2paymentsOrderInformation orderInformation = new Ptsv2paymentsOrderInformation( + AmountDetails: orderInformationAmountDetails, + BillTo: orderInformationBillTo + ); + + var requestObj = new CreatePaymentRequest( + ClientReferenceInformation: clientReferenceInformation, + ProcessingInformation: processingInformation, + PaymentInformation: paymentInformation, + OrderInformation: orderInformation + ); + + try + { + + var configDictionary = new ConfigurationWithMLE().GetConfiguration1(); + var clientConfig = new CyberSource.Client.Configuration(merchConfigDictObj: configDictionary); + + var apiInstance = new PaymentsApi(clientConfig); + PtsV2PaymentsPost201Response result = apiInstance.CreatePayment(requestObj); + Console.WriteLine(result); + WriteLogAudit(apiInstance.GetStatusCode()); + return result; + } + catch (ApiException e) + { + Console.WriteLine("Error Code: " + e.ErrorCode); + Console.WriteLine("Error Message: " + e.Message); + Console.WriteLine("Exception on calling the API : " + e.Message); + WriteLogAudit(e.ErrorCode); + return null; + } + } + } +} diff --git a/Source/Samples/MLEFeature/PaymentsWithMapToContol1.cs b/Source/Samples/MLEFeature/PaymentsWithMapToContol1.cs new file mode 100644 index 0000000..361e6d3 --- /dev/null +++ b/Source/Samples/MLEFeature/PaymentsWithMapToContol1.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; +using System.Text; +using CyberSource.Api; +using CyberSource.Client; +using CyberSource.Model; + +namespace Cybersource_rest_samples_dotnet.Samples.MLEFeature +{ + class PaymentsWithMapToContol1 + { + + + public static void WriteLogAudit(int status) + { + var filePath = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString().Split('.'); + var filename = filePath[filePath.Length - 1]; + Console.WriteLine($"[Sample Code Testing] [{filename}] {status}"); + } + + public static bool CaptureTrueForProcessPayment { get; set; } = false; + + public static PtsV2PaymentsPost201Response Run() + { + string clientReferenceInformationCode = "TC50171_3"; + Ptsv2paymentsClientReferenceInformation clientReferenceInformation = new Ptsv2paymentsClientReferenceInformation( + Code: clientReferenceInformationCode + ); + + bool processingInformationCapture = false; + if (CaptureTrueForProcessPayment) + { + processingInformationCapture = true; + } + + Ptsv2paymentsProcessingInformation processingInformation = new Ptsv2paymentsProcessingInformation( + Capture: processingInformationCapture + ); + + string paymentInformationCardNumber = "4111111111111111"; + string paymentInformationCardExpirationMonth = "12"; + string paymentInformationCardExpirationYear = "2031"; + Ptsv2paymentsPaymentInformationCard paymentInformationCard = new Ptsv2paymentsPaymentInformationCard( + Number: paymentInformationCardNumber, + ExpirationMonth: paymentInformationCardExpirationMonth, + ExpirationYear: paymentInformationCardExpirationYear + ); + + Ptsv2paymentsPaymentInformation paymentInformation = new Ptsv2paymentsPaymentInformation( + Card: paymentInformationCard + ); + + string orderInformationAmountDetailsTotalAmount = "102.21"; + string orderInformationAmountDetailsCurrency = "USD"; + Ptsv2paymentsOrderInformationAmountDetails orderInformationAmountDetails = new Ptsv2paymentsOrderInformationAmountDetails( + TotalAmount: orderInformationAmountDetailsTotalAmount, + Currency: orderInformationAmountDetailsCurrency + ); + + string orderInformationBillToFirstName = "John"; + string orderInformationBillToLastName = "Doe"; + string orderInformationBillToAddress1 = "1 Market St"; + string orderInformationBillToLocality = "san francisco"; + string orderInformationBillToAdministrativeArea = "CA"; + string orderInformationBillToPostalCode = "94105"; + string orderInformationBillToCountry = "US"; + string orderInformationBillToEmail = "test@cybs.com"; + string orderInformationBillToPhoneNumber = "4158880000"; + Ptsv2paymentsOrderInformationBillTo orderInformationBillTo = new Ptsv2paymentsOrderInformationBillTo( + FirstName: orderInformationBillToFirstName, + LastName: orderInformationBillToLastName, + Address1: orderInformationBillToAddress1, + Locality: orderInformationBillToLocality, + AdministrativeArea: orderInformationBillToAdministrativeArea, + PostalCode: orderInformationBillToPostalCode, + Country: orderInformationBillToCountry, + Email: orderInformationBillToEmail, + PhoneNumber: orderInformationBillToPhoneNumber + ); + + Ptsv2paymentsOrderInformation orderInformation = new Ptsv2paymentsOrderInformation( + AmountDetails: orderInformationAmountDetails, + BillTo: orderInformationBillTo + ); + + var requestObj = new CreatePaymentRequest( + ClientReferenceInformation: clientReferenceInformation, + ProcessingInformation: processingInformation, + PaymentInformation: paymentInformation, + OrderInformation: orderInformation + ); + + try + { + + var configDictionary = new ConfigurationWithMLE().GetConfiguration1(); + var mapToControlMLE = new ConfigurationWithMLE().GetMapToControlMLE(); + var clientConfig = new CyberSource.Client.Configuration(merchConfigDictObj: configDictionary, mapToControlMLEonAPI: mapToControlMLE); + + var apiInstance = new PaymentsApi(clientConfig); + PtsV2PaymentsPost201Response result = apiInstance.CreatePayment(requestObj); + Console.WriteLine(result); + WriteLogAudit(apiInstance.GetStatusCode()); + return result; + } + catch (ApiException e) + { + Console.WriteLine("Error Code: " + e.ErrorCode); + Console.WriteLine("Error Message: " + e.Message); + Console.WriteLine("Exception on calling the API : " + e.Message); + WriteLogAudit(e.ErrorCode); + return null; + } + } + } +} diff --git a/Source/Samples/MLEFeature/PaymentsWithMapToContol2.cs b/Source/Samples/MLEFeature/PaymentsWithMapToContol2.cs new file mode 100644 index 0000000..960f3df --- /dev/null +++ b/Source/Samples/MLEFeature/PaymentsWithMapToContol2.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; +using System.Text; +using CyberSource.Api; +using CyberSource.Client; +using CyberSource.Model; + +namespace Cybersource_rest_samples_dotnet.Samples.MLEFeature +{ + class PaymentsWithMapToContol2 + { + + + public static void WriteLogAudit(int status) + { + var filePath = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString().Split('.'); + var filename = filePath[filePath.Length - 1]; + Console.WriteLine($"[Sample Code Testing] [{filename}] {status}"); + } + + public static bool CaptureTrueForProcessPayment { get; set; } = false; + + public static PtsV2PaymentsPost201Response Run() + { + string clientReferenceInformationCode = "TC50171_3"; + Ptsv2paymentsClientReferenceInformation clientReferenceInformation = new Ptsv2paymentsClientReferenceInformation( + Code: clientReferenceInformationCode + ); + + bool processingInformationCapture = false; + if (CaptureTrueForProcessPayment) + { + processingInformationCapture = true; + } + + Ptsv2paymentsProcessingInformation processingInformation = new Ptsv2paymentsProcessingInformation( + Capture: processingInformationCapture + ); + + string paymentInformationCardNumber = "4111111111111111"; + string paymentInformationCardExpirationMonth = "12"; + string paymentInformationCardExpirationYear = "2031"; + Ptsv2paymentsPaymentInformationCard paymentInformationCard = new Ptsv2paymentsPaymentInformationCard( + Number: paymentInformationCardNumber, + ExpirationMonth: paymentInformationCardExpirationMonth, + ExpirationYear: paymentInformationCardExpirationYear + ); + + Ptsv2paymentsPaymentInformation paymentInformation = new Ptsv2paymentsPaymentInformation( + Card: paymentInformationCard + ); + + string orderInformationAmountDetailsTotalAmount = "102.21"; + string orderInformationAmountDetailsCurrency = "USD"; + Ptsv2paymentsOrderInformationAmountDetails orderInformationAmountDetails = new Ptsv2paymentsOrderInformationAmountDetails( + TotalAmount: orderInformationAmountDetailsTotalAmount, + Currency: orderInformationAmountDetailsCurrency + ); + + string orderInformationBillToFirstName = "John"; + string orderInformationBillToLastName = "Doe"; + string orderInformationBillToAddress1 = "1 Market St"; + string orderInformationBillToLocality = "san francisco"; + string orderInformationBillToAdministrativeArea = "CA"; + string orderInformationBillToPostalCode = "94105"; + string orderInformationBillToCountry = "US"; + string orderInformationBillToEmail = "test@cybs.com"; + string orderInformationBillToPhoneNumber = "4158880000"; + Ptsv2paymentsOrderInformationBillTo orderInformationBillTo = new Ptsv2paymentsOrderInformationBillTo( + FirstName: orderInformationBillToFirstName, + LastName: orderInformationBillToLastName, + Address1: orderInformationBillToAddress1, + Locality: orderInformationBillToLocality, + AdministrativeArea: orderInformationBillToAdministrativeArea, + PostalCode: orderInformationBillToPostalCode, + Country: orderInformationBillToCountry, + Email: orderInformationBillToEmail, + PhoneNumber: orderInformationBillToPhoneNumber + ); + + Ptsv2paymentsOrderInformation orderInformation = new Ptsv2paymentsOrderInformation( + AmountDetails: orderInformationAmountDetails, + BillTo: orderInformationBillTo + ); + + var requestObj = new CreatePaymentRequest( + ClientReferenceInformation: clientReferenceInformation, + ProcessingInformation: processingInformation, + PaymentInformation: paymentInformation, + OrderInformation: orderInformation + ); + + try + { + + var configDictionary = new ConfigurationWithMLE().GetConfiguration2(); + var mapToControlMLE = new ConfigurationWithMLE().GetMapToControlMLE(); + var clientConfig = new CyberSource.Client.Configuration(merchConfigDictObj: configDictionary, mapToControlMLEonAPI: mapToControlMLE); + + var apiInstance = new PaymentsApi(clientConfig); + PtsV2PaymentsPost201Response result = apiInstance.CreatePayment(requestObj); + Console.WriteLine(result); + WriteLogAudit(apiInstance.GetStatusCode()); + return result; + } + catch (ApiException e) + { + Console.WriteLine("Error Code: " + e.ErrorCode); + Console.WriteLine("Error Message: " + e.Message); + Console.WriteLine("Exception on calling the API : " + e.Message); + WriteLogAudit(e.ErrorCode); + return null; + } + } + } +} diff --git a/cybersource-rest-samples-csharp.csproj b/cybersource-rest-samples-csharp.csproj index 7730f5d..18482ec 100644 --- a/cybersource-rest-samples-csharp.csproj +++ b/cybersource-rest-samples-csharp.csproj @@ -105,6 +105,7 @@ + @@ -159,6 +160,9 @@ + + +