Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
developer:sample_codes:net_xml_secure_cards [2018/04/20 08:44]
tleite
developer:sample_codes:net_xml_secure_cards [2021/06/09 13:53] (current)
lezlieh added note about NET framework and NET core
Line 1: Line 1:
 +====== .NET XML Secure Cards ======
 +
 +
 +**NOTE:​** ​  
 +  *   - Supported on .NET Framework 4.5 
 +  *   - .NET Core is not supported
 +
 +The sample code below requires the **{{:​developer:​sample_codes:​nuvei-api-dotnet.zip|.NET XML API}}**.
 +
 +
 +\\
 +----
 +**SecureCard registration:​**
 +
 +<code csharp>
 +
 +using System;
 +using System.Security.Cryptography;​
 +using System.Collections.Generic;​
 +using System.Text;​
 +using NuveiClient;​
 +
 +namespace ApiTest
 +{
 +    class SecureCardRegistrationSample
 +    {
 +        static void Main (string[] args)
 +        {
 + String gateway = "​nuvei"; ​      // Gateway that will process the transaction.
 + String terminalId = ""; ​       // Terminal ID
 +            String secret = ""; ​           // Shared Secret as configured in the Terminal Setup in your Nuvei SelfCare ​ System
 +
 +            String secureCardMerchantRef = ""; ​   // Unique Merchant Reference. Length is limited to 48 chars.
 +            String cardNumber = ""; ​       // The cardholders PAN (or SecureCard Card Reference);
 +            String cardType = ""; ​       // See our Integrator Guide for a list of valid Card Type parameters
 +            String cardExpiry = ""; ​       // Format: MMYY
 +            String cardHolderName = ""; ​       // Cardholders name
 +
 +            String dontCheckSecurity = ""; ​   // (optional) "​Y"​ if you do not want the CVV to be validated online.
 +            String cvv = ""; ​           // (optional) 3 digit (4 for AMEX cards) security digit on the back of the card.
 +            String issueNo = ""; ​       // (optional) Issue number for Switch and Solo cards.
 +
 +            IList<​String>​ permittedTerminals = new List<​String>​ (); // PERMITTED TERMINALS
 +            //​permittedTerminals.Add ("​1002"​);​
 +            //​permittedTerminals.Add ("​1009"​);​
 +            IList<​CustomField>​ customFields = new List<​CustomField>​ (); // CustomFields
 +            //​customFields.Add ("​name1",​ "​value1"​));​
 +            //​customFields.Add ("​name2",​ "​value2"​));​
 +
 +            Boolean testAccount = true;
 +
 +            XmlSecureCardRegRequest securereg = new XmlSecureCardRegRequest (secureCardMerchantRef,​ terminalId, cardNumber, cardExpiry, cardType, cardHolderName);​
 +
 +            if (!String.IsNullOrEmpty (dontCheckSecurity)) {
 +                securereg.SetDontCheckSecurity (dontCheckSecurity);​
 +            }
 +            if (!String.IsNullOrEmpty (cvv)) {
 +                securereg.SetCvv (cvv);
 +            }
 +            if (!String.IsNullOrEmpty (issueNo)) {
 +                securereg.SetIssueNo (issueNo);
 +            }
 +            if (permittedTerminals != null && permittedTerminals.Count != 0) {
 +                securereg.SetPermittedTerminals (permittedTerminals);​
 +            }
 +            if (customFields != null && customFields.Count != 0) {
 +                securereg.SetCustomFields (customFields);​
 +            }
 +
 +            XmlSecureCardRegResponse response = securereg.ProcessRequest (secret, testAccount,​ gateway);
 +
 +            String expectedResponseHash = Response.GetResponseHash (terminalId + response.MerchantRef + response.CardRef + response.DateTimeHashString + secret);
 +
 +            if (response.IsError == true) {
 +                Console.Out.WriteLine ("​ERROR : " + response.ErrorString);​
 +                //Handle Error Response
 +            } else if (response.Hash != expectedResponseHash) {
 +                Console.Out.WriteLine ("​ERROR : Response HASH parameter not as expected. If live possible man-in-the-middle attack."​);​
 +                //Handle Invalid Hash scenario - inform merchant that transaction may have to be voided.
 +            } else {
 +                Console.Out.WriteLine ("​SecureCard successfully stored."​);​
 +                Console.Out.WriteLine ("​CARDREFERENCE : " + response.CardRef);​
 +                //Handle Response
 +            }
 +        }
 +    }
 +}
 +</​code>​
 +
 +\\
 +----
 +**SecureCard record update:**
 +
 +<code csharp>
 +
 +using System;
 +using System.Security.Cryptography;​
 +using System.Collections.Generic;​
 +using System.Text;​
 +using NuveiClient;​
 +
 +namespace ApiTest
 +{
 +    class  SecureCardRecordUpdateSample
 +    {
 +        static void Main (string[] args)
 +        {
 + String gateway = "​nuvei"; ​      // Gateway that will process the transaction.
 + String terminalId = ""; ​       // Terminal ID
 +            String secret = ""; ​           // Shared Secret as configured in the Terminal Setup in your Nuvei SelfCare ​ System
 +
 +            String secureCardMerchantRef = ""; ​   // Unique Merchant Reference. Length is limited to 48 chars.
 +            String cardNumber = ""; ​       // The cardholders PAN (or SecureCard Card Reference);
 +            String cardType = ""; ​       // See our Integrator Guide for a list of valid Card Type parameters
 +            String cardExpiry = ""; ​       // Format: MMYY
 +            String cardHolderName = ""; ​       // Cardholders name
 +
 +            String dontCheckSecurity = ""; ​   // (optional) "​Y"​ if you do not want the CVV to be validated online.
 +            String cvv = ""; ​           // (optional) 3 digit (4 for AMEX cards) security digit on the back of the card.
 +            String issueNo = ""; ​       // (optional) Issue number for Switch and Solo cards.
 +
 +            IList<​String>​ permittedTerminals = new List<​String>​ (); // PERMITTED TERMINALS
 +            //​permittedTerminals.Add ("​1003"​);​
 +            //​permittedTerminals.Add ("​1013"​);​
 +            IList<​CustomField>​ customFields = new List<​CustomField>​ (); // CustomFields
 +            //​customFields.Add (new CustomField ("​name1",​ "​value1"​));​
 +            //​customFields.Add (new CustomField ("​name2",​ "​value2"​));​
 +
 +            Boolean testAccount = true;
 +
 +            XmlSecureCardUpdRequest secureupd = new XmlSecureCardUpdRequest (secureCardMerchantRef,​ terminalId, cardNumber, cardExpiry, cardType, cardHolderName);​
 +
 +            if (!String.IsNullOrEmpty (dontCheckSecurity)) {
 +                secureupd.SetDontCheckSecurity (dontCheckSecurity);​
 +            }
 +            if (!String.IsNullOrEmpty (cvv)) {
 +                secureupd.SetCvv (cvv);
 +            }
 +            if (!String.IsNullOrEmpty (issueNo)) {
 +                secureupd.SetIssueNo (issueNo);
 +            }
 +            if (permittedTerminals != null && permittedTerminals.Count != 0) {
 +                secureupd.SetPermittedTerminals (permittedTerminals);​
 +            }
 +            if (customFields != null && customFields.Count != 0) {
 +                secureupd.SetCustomFields (customFields);​
 +            }
 +
 +            XmlSecureCardUpdResponse response = secureupd.ProcessRequest (secret, testAccount,​ gateway);
 +
 +            String expectedResponseHash = Response.GetResponseHash (terminalId + response.MerchantRef + response.CardRef + response.DateTimeHashString + secret);
 +
 +            if (response.IsError == true) {
 +                Console.Out.WriteLine ("​ERROR : " + response.ErrorString);​
 +                //Handle Error Response
 +            } else if (response.Hash != expectedResponseHash) {
 +                Console.Out.WriteLine ("​ERROR : Response HASH parameter not as expected. If live possible man-in-the-middle attack."​);​
 +                //Handle Invalid Hash scenario - inform merchant that transaction may have to be voided.
 +            } else {
 +                Console.Out.WriteLine ("​SecureCard successfully updated."​);​
 +                //Handle Response
 +            }
 +        }
 +    }
 +}
 +
 +</​code>​
 +
 +\\
 +----
 +**SecureCard record deletion:**
 +
 +<code csharp>
 +
 +using System;
 +using System.Security.Cryptography;​
 +using System.Collections.Generic;​
 +using System.Text;​
 +using $GatewayClient;​
 +
 +namespace ApiTest
 +{
 +    class SecureCardRecordDeletionSample
 +    {
 +        static void Main (string[] args)
 +        {
 + String gateway = "​nuvei"; ​       // Gateway that will process the transaction.
 + String terminalId = ""; ​       // Terminal ID
 +            String secret = ""; ​           // Shared Secret as configured in the Terminal Setup in your Nuvei SelfCare ​ System
 +
 +            String secureCardMerchantRef = ""; ​   // Unique Merchant Reference. Length is limited to 48 chars.
 +            String secureCardCardRef = ""; ​   // This is the Nuvei generated 16 digit card number token
 +
 +            Boolean testAccount = false;
 +
 +            XmlSecureCardDelRequest securedel = new XmlSecureCardDelRequest (secureCardMerchantRef,​ terminalId, secureCardCardRef);​
 +            XmlSecureCardDelResponse response = securedel.ProcessRequest (secret, testAccount,​ gateway);
 +
 +            String expectedResponseHash = Response.GetResponseHash (terminalId + response.MerchantRef + response.DateTimeHashString + secret);
 +
 +            if (response.IsError == true) {
 +                Console.Out.WriteLine ("​ERROR : " + response.ErrorString);​
 +                //Handle Error Response
 +            } else if (response.Hash != expectedResponseHash) {
 +                Console.Out.WriteLine ("​ERROR : Response HASH parameter not as expected. If live possible man-in-the-middle attack."​);​
 +                //Handle Invalid Hash scenario - inform merchant that transaction may have to be voided.
 +            } else {
 +                Console.Out.WriteLine ("​SecureCard successfully deleted."​);​
 +                //Handle Response
 +            }
 +        }
 +    }
 +}
 +
 +</​code>​
 +
 +\\
 +----
 +**SecureCard Search:**
 +
 +<code csharp>
 +
 +using System;
 +using System.Security.Cryptography;​
 +using System.Collections.Generic;​
 +using System.Text;​
 +using NuveiClient;​
 +
 +namespace ApiTest
 +{
 +    class SecureCardSearchSample
 +    {
 +        static void Main (string[] args)
 +        {
 + String gateway = "​nuvei"; ​       // Gateway that will process the transaction.
 + String terminalId = ""; ​       // Terminal ID
 +            String secret = ""; ​           // Shared Secret as configured in the Terminal Setup in your Nuvei SelfCare ​ System
 +
 +            String secureCardMerchantRef = ""; ​   // Unique Merchant Reference. Length is limited to 48 chars.
 +
 +            Boolean testAccount = true;
 +
 +            XmlSecureCardSearchRequest securesearch = new XmlSecureCardSearchRequest (secureCardMerchantRef,​ terminalId);​
 +            XmlSecureCardSearchResponse response = securesearch.ProcessRequest (secret, testAccount,​ gateway);
 +
 +            String expectedResponseHash = Response.GetResponseHash (terminalId + response.MerchantRef + response.CardRef + response.CardType + response.CardExpiry + response.CardHolderName + response.DateTimeHashString + secret);
 +
 +            if (response.IsError == true) {
 +                Console.Out.WriteLine ("​ERROR : " + response.ErrorString);​
 +                //Handle Error Response
 +            } else if (response.Hash != expectedResponseHash) {
 +                Console.Out.WriteLine ("​ERROR : Response HASH parameter not as expected. If live possible man-in-the-middle attack."​);​
 +                //Handle Invalid Hash scenario - inform merchant that transaction may have to be voided.
 +            } else {
 +                Console.Out.WriteLine ("​SecureCard successfully found."​);​
 +                Console.Out.WriteLine ("​MERCHANTREF : " + response.MerchantRef);​
 +                Console.Out.WriteLine ("​CARDREFERENCE : " + response.CardRef);​
 +                Console.Out.WriteLine ("​CARDTYPE : " + response.CardType);​
 +                Console.Out.WriteLine ("​CARDEXPIRY : " + response.CardExpiry);​
 +                Console.Out.WriteLine ("​CARDHOLDERNAME : " + response.CardHolderName);​
 +                //Handle Response
 +            }
 +        }
 +    }
 +}
 +</​code>​
 +
  
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International