Prerequisites
You must create a P12 certificate. See the .
With this change to use a P12 certificate in your C# SOAP toolkit configuration, your
application must meet these new requirements:
- .NET Framework 4.7.2 and later Redistributable Package
- Portable.BouncyCastle
Migration Steps
Follow these steps to upgrade your C# code:
- Add the following service URL as a service reference to your project:
wherehttps://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_N.NNN.wsdlN.NNNis the latest server API version.This generates a Connected Services section in your project. It also generates anapp.configfile for your project. - Add the following sections to the top of yourapp.configfile:<configuration> <configSections> <section name="toolkitProperties" type="System.Configuration.NameValueSectionHandler"/> </configSections> <toolkitProperties> <add key="MERCHANT_ID" value="<your_merchant_id>"/> <add key="KEY_ALIAS" value="<your_certificate_key_alias>"/> <add key="KEY_FILE" value="<your_certificate_file>"/> <add key="KEY_PASS" value="<your_certificate_password>"/> <add key="KEY_DIRECTORY" value="<path/to/certificate/file>"/> </toolkitProperties> </configuration>The<configSections>tag must be the first section inside<configurations>.
- In the generatedapp.configfile, leave the<binding>section as it is.The<binding>section must look like this:<bindings> <basicHttpBinding> <binding name="ITransactionProcessor"> <security mode="Transport"/> </binding> </basicHttpBinding> </bindings>
- Add this dependency to thepackages.configfile:<packages> <package id="Portable.BouncyCastle" version="1.9.0" targetFramework="net472" /> </packages>
- Install the dependency:nuget install packages.config -OutputDirectory packages
- Add this package reference to your.csprojfile:
The steps for adding a new dependency can also be done through Visual Studio Package Manager.<Reference Include="BouncyCastle.Crypto, Version=1.9.0.0, Culture=neutral, PublicKeyToken=0e99375e54769942, processorArchitecture=MSIL"> <HintPath>packages\Portable.BouncyCastle.1.9.0\lib\net40\BouncyCastle.Crypto.dll</HintPath> </Reference> - Add your P12 certificate to theKEY_DIRECTORY.ThisKEY_DIRECTORYlocation must be accessible to your code. Ensure that your code has permission to read this location.
- Copy these files to your project directory and import them to your project:
- CertificateCacheUtility.cs
- InspectorBehavior.cs
- PropertiesUtility.cs
- SecurityUtility.cs
- SoapEnvelopeUtility.cs
- Find these lines in your existing code:
Replace them with these lines:TransactionProcessorClient proc = new TransactionProcessorClient(); proc.ChannelFactory.Credentials.UserName.UserName = request.merchantID; proc.ChannelFactory.Credentials.UserName.Password = TRANSACTION_KEY; ReplyMessage reply = proc.runTransaction(request);TransactionProcessorClient proc = new TransactionProcessorClient(); proc.Endpoint.EndpointBehaviors.Add(new InspectorBehavior()); ReplyMessage reply = proc.runTransaction(request); - Find your installation of .NET Framework.This is often located at one of these locations:
- C:\Windows\Microsoft.NET\Framework\v4.0.30319(32-bit)
- C:\Windows\Microsoft.NET\Framework64\v4.0.30319(64-bit)
- UsemsBuild.exeto compile your project.<path_to_framework>\msBuild.exe <name_of_project>.csproj
- Run the project executable:bin\<configuration>\<project_name>.exe
- (Optional) You can confirm that your configuration is updated successfully by checking that your request was authenticated using a Bearer token. To confirm, add this command after line 59 in theCSharpSoapToolkit\InspectorBehavior.csfile:Console.WriteLine(request.ToString());
Sample Payload Using P12 Authentication
<?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:schemas-cybersource-com:transaction-data-1.215"> <SOAP-ENV:Header> <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> <wsse:BinarySecurityToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" wsu:Id="X509Token"> MIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigAMIICXzCCAcigA........ </wsse:BinarySecurityToken> <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> <ds:SignedInfo> <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /> <ds:SignatureMethodAlgorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" /> <ds:Reference URI="#Body"> <ds:Transforms> <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /> </ds:Transforms> <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" /> <ds:DigestValue> KRmKx6digestvalye12389012367u7hlkV1vvbtec........... </ds:DigestValue> </ds:Reference> </ds:SignedInfo> <ds:SignatureValue>otrfnrck17dwxI4UR12345612yNG7TtE8L3XFhfEa/63r2uBDsg7b2YY8C6nKvkJGop4NHW7d30yfrz5dK2CHkp18TM+hVkyNIVLGokZzZpAwuc0sXm33+J4i765421duLsE4jM0FfIABsPHT2vgSq+T0g+812312jOeIk5R5kLhwnlVd92wQvBmpxINBW2Hh5adwwtpv+gj4AtvuhLYe1ky4R/oDNSWLPmyY1dSIyGDKO4ko8CT0mFlAvxECa8dLHRsyFrZVlK6................ </ds:SignatureValue> <ds:KeyInfo> <wsse:SecurityTokenReference> <wsse:Reference URI="#X509Token" /> </wsse:SecurityTokenReference> </ds:KeyInfo> </ds:Signature> </wsse:Security> </SOAP-ENV:Header> <soapenv:Body> <requestMessage xmlns="urn:schemas-cybersource-com:transaction-data-1.215"> <merchantID>johndoe</merchantID> <merchantReferenceCode>MRC-123</merchantReferenceCode> <billTo> <firstName>John</firstName> <lastName>Doe</lastName> <street1>123 Example Road</street1> <city>Austin</city> <state>TX</state> <postalCode>12345</postalCode> <country>US</country> <email>abc@company.com</email> </billTo> <shipTo> <firstName>John</firstName> <lastName>Doe</lastName> <street1>123 Example Road</street1> <city>Austin</city> <state>TX</state> <postalCode>12345</postalCode> <country>US</country> </shipTo> <purchaseTotals> <currency>USD</currency> <grandTotalAmount>100.00</grandTotalAmount> </purchaseTotals> <card> <accountNumber>4111111111111111</accountNumber> <expirationMonth>12</expirationMonth> <expirationYear>2029</expirationYear> <cvNumber>111</cvNumber> </card> <ccAuthService run="true"></ccAuthService> <ccCaptureService run="true"></ccCaptureService> </requestMessage> </soapenv:Body> </soapenv:Envelope>