Denali – Mastercard Regex Patch

In your Denali implementation, the credit card regex values reside in the Utils.js file, which is located in the Utilities module. To update this module, redefine the paymenthodIdCreditCart() method as described in this section. You can download the code samples described in this procedure here: MastercardBinRegex---DenaliCodeSamples.zip.

Step 1: Extend the Utils.js File

  1. If you have not done so already, create a directory to store your custom module.

    Following best practices, name this directory extensions and place it in your Modules directory. Depending on your implementation and customizations, this directory might already exist.

  2. Open your extensions directory and create a custom module to maintain your customizations.

    Give this directory a unique name that is similar to the module being customized. For example:

    Modules/extensions/Utilities.Extension@1.0.0/

  3. In your new Utilities.Extension@1.0.0 module, create a subdirectory called JavaScript.

  4. In your JavaScript subdirectory, create a new JavaScript file.

    Give this file a unique name that is similar to the file being modified. For example:

    Modules/extensions/Utilities.Extension@1.0.0/JavaScript/Utils.Extension.js

  5. Open this file and set it up to redefine the paymenthodIdCreditCart method of the Utils.js file.

    Important:

    This must be wrapped inside the mountToApp() method.

    Your file should match the following code snippet:

                    define(
       'Utils.Extension'
    ,  [
          'Utils'
    
       ,  'underscore'
       ]
    ,  function (
          Utils
    
       ,  _
       )
    {
    
       'use strict';
    
       return {
          mountToApp: function ()
          {
          Utils.prototype.paymenthodIdCreditCart=
    
             function paymenthodIdCreditCart (cc_number)
             {
                // regex for credit card issuer validation
                var cards_reg_ex = {
                   'VISA': /^4[0-9]{12}(?:[0-9]{3})?$/
                ,  'Master Card': /^(5[1-5][0-9]{14}|2(2(2[1-9]|[3-9][0-9])|[3-6][0-9][0-9]|7([0-1][0-9]|20))[0-9]{12})$/  // previous value: /^5[1-5][0-9]{14}$/
                ,  'American Express': /^3[47][0-9]{13}$/
                ,  'Discover': /^6(?:011|5[0-9]{2})[0-9]{12}$/
                ,  'Maestro': /^(?:5[0678]\d\d|6304|6390|67\d\d)\d{8,15}$/
                }
    
                // get the credit card name
                ,  paymenthod_name;
    
                // validate that the number and issuer
                _.each(cards_reg_ex, function (reg_ex, name)
                {
                   if (reg_ex.test(cc_number))
                   {
                      paymenthod_name = name;
                   }
                });
    
                var paymentmethod = paymenthod_name && _.findWhere(SC.ENVIRONMENT.siteSettings.paymentmethods, {name: paymenthod_name.toString()});
    
                return paymentmethod && paymentmethod.internalid;
             }            
          } 
       };
    }); 
    
                  
  6. Save the file.

Step 2: Prepare the Developer Tools for Your Customizations

  1. Open the Utilities.Extension@1.0.0 module.

  2. Create a file in this module and name it ns.package.json.

    Modules/extensions/Utilities.Extension@1.0.0/ns.package.json

  3. Build the ns.package.json file using the following code

                    {
        "gulp": {
            "javascript": [
                "JavaScript/*.js"
            ]
        }
    } 
    
                  
  4. Save the ns.package.json file.

  5. Open the distro.json file.

    This file is located in the top-level directory of your SuiteCommerce Advanced source code.

  6. Add your custom module to the modules object to ensure that the Gulp tasks include your extension when you deploy.

    Your code should look similar to the following example:

                    {
        "name": "SuiteCommerce Advanced Mont Blanc",
        "version": "2.0",
        "buildToolsVersion": "1.1.0",
        "folders": {
            "modules": "Modules",
            "suitecommerceModules": "Modules/suitecommerce",
            "thirdPartyModules": "Modules/third_parties",
            "distribution": "LocalDistribution",
            "deploy": "DeployDistribution"
        },
        "modules": {
            "extensions/Utilities.Extension": "1.0.0",
            "suitecommerce/Account": "2.1.0",
                       //... 
    
                  
  7. Add Utils.Extension as a dependency to the following entry points of the JavaScript object:

    • SC.Shopping.Starter

    • SC.MyAccount.Starter

    • SC.Checkout.Starter

    Your code should look similar to the following example:

                    //...
    "javascript": [
        {
            "entryPoint": "SC.Shopping.Starter",
            "exportFile": "shopping.js",
            "dependencies": [
                "Backbone.View.Plugins",
                            //...
                            "Utils.Extension"
                      ],
             //...
             },
        {
            "entryPoint": "SC.MyAccount.Starter",
            "exportFile": "myaccount.js",
            "dependencies": [
                "Backbone.View.Plugins",
                            //...
                            "Utils.Extension"
                      ],
             //...
             },
        {
            "entryPoint": "SC.Checkout.Starter",
            "exportFile": "checkout.js",
            "dependencies": [
                "Backbone.View.Plugins",
                            //...
                            "Utils.Extension"
                      ],
             //...
             },
    //... 
    
                  
  8. Save the distro.json file.

Step 3: Test and Deploy Your Extension

  1. Test your source code customizations on a local server (see Test SCA Customizations on a Local Server) or deploy them to your NetSuite account (see Deploy SCA Customizations to NetSuite). If you are currently running SCA on a local server, your changes should appear on your local site immediately.

  2. Confirm your results.

    Upon successful deployment, the new Mastercard regex should be included in your compiled shopping.js, myaccount.js, and checkout.js files.

Related Topics

Mastercard 2-Series BIN Regex Patch
Mont Blanc – Mastercard Regex Patch
Vinson – Mastercard Regex Patch

General Notices