Simple Software Licensing
            Help Center Simple Software Licensing Payment Integration

            Integrating License Generation with ClickBank

            Before you attempt to implement this you should read Clickbanks documentation. 

            For Instant Notification 2.1

            Clickbank sends many different parameters in the HTTP POST message for the notification. The items which are of interest for generating licenses are: 

            • ccustfullname Customer full name - if you want to issue named licenses.
            • ccustemail Custom email - if you want to include an email address in the license.
            • cproditem Product number - if you are selling multiple products/editions.
            • ctransaction Transaction type - you should only issue licenses when a SALE is completed.

            Clickbank also sends a SHA1 hash value based on the contents of the notification combined with your secret value with Clickbank. 

            Creating A License

            Licenses are created the same way for clickbank as in the generic example. The following code shows a brief summary of the minimum amount of changes that are required to configure the code for Clickbank. Your script will probably require more adaptations to handle different scenarios such as error handling which has intentionally been left out to minimize the amount of code. The code is an adaptation of the generic code. 

            1. if (Request.Form("ctransaction") == "SALE" && ipnValid(Request))
            2.             {
            3.                 //clickbank version
            4.                 string email = Request.Form["ccustemail"];
            5.                 string fullname = Request.Form["ccustfullname"];
            6.                 Guid userSerial = Guid.NewGuid();

            7.                 LicensedUser licensee = null;

            8.                 //depending on what info you expect to receive you may need to call a different create method
            9.                 licensee = LicensedUser.Create(fullname.Trim(), email.Trim(), null);

            10.                 //setup your product
            11.                 //you may need to check Request.Form["cproditem"] for different editions and products

            12.                 //create license

            13.                 //send license by email
            14.             }

            Verifying The Cipher

            C# code for verifying the cipher (code provided by Clickbank). This method should be called before you generate the license to verify that the notification was sent by Clickbank and not a third party attempting to crack your license generation. 

            1.         ///
            2.         /// This method takes the same named post parameters that are sent in the ClickBank Instant Notification Service.
            3.         ///
            4.         ///
            5.         /// True if the ClickBank passed paramter cverify matches the calculated sha1 of the provided data, False otherwise
            6.         ///
            7.         public static bool ipnValid(HttpRequest request)
            8.         {
            9.             string secretKey = "YOUR SECRET KEY";
            10.             List ipnFields = new List();
            11.             foreach (string param in request.Form.Keys)
            12.             {
            13.                 if (param.Equals("cverify"))
            14.                 {
            15.                     continue;
            16.                 }
            17.                 ipnFields.Add(param);
            18.             }
            19.             ipnFields.Sort();
            20.             string pop = "";
            21.             foreach (String field in ipnFields)
            22.             {
            23.                 pop += request.Form.Get(field) + "|";
            24.             }
            25.             pop += secretKey;
            26.             string cverify = request.Form.Get("cverify");
            27.             byte[] hashedData = new SHA1Managed().ComputeHash(Encoding.UTF8.GetBytes(pop));
            28.             string calced_verification = BitConverter.ToString(hashedData).Replace("-", "").ToUpper().Substring(0, 8);
            29.             return calced_verification.Equals(cverify);
            30.         }
            Updated: 08 Nov 2017 11:20 PM
            Help us to make this article better
            0 0