DEAD CODE. Do not use this code. It has been replaced by Hosted Fields.

Introduction

UltraCart created a new method for collecting credit card numbers using javascript checkouts.  The credit card number is sent to UltraCart one time and then represented by a masked number.

Here are the reasons:

 

Steps to Implement

 

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script>
 
// NOTE! This is an Example!  In your code, your cart object will usually be a global variable, and might not be named 'cart'. 
// So please take care to remove the local variable 'cart' that immediately follows this comment and replace all instances of
// 'cart' with the name of your cart object variable.
// Also, older versions of the checkout may use 'shoppingCartId' instead of just 'cartId'.  Examine your cart object and adjust the code as needed.
  var cart = {
        merchantId: 'DEMO',
        cartId: '12345',
        cardNumber: ''
  };
 
  function storeCard() {    
  
    // Extract the card number from the field
    var cardNumber = jQuery("#cardNumberId").val();
 
    // If they haven't specified 15 digits yet then don't store it.
    if (cardNumber.replace(/[^0-9]/g,"").length < 15) {
      // TODO - Verify your cart object is named 'cart'! This is an example only.  We see ALOT of merchants use this code with some github sources that use 'myCart' as their variable.  TEST THIS.  GET IT RIGHT!
      cart.creditCardNumber = cardNumber;
      return;
    }
 
    // Create a masked version of the card number and update the client field
    var maskedCardNumber = cardNumber;
    for (var i = 0; i < 12; i++) {
      maskedCardNumber = maskedCardNumber.replace(/[0-9]/, 'X');
    }
    
    // Store the masked one on the cart object to make sure a full card number doesn't go up.
    cart.cardNumber = maskedCardNumber;
    // Update the form as well
    jQuery("#cardNumberId").val(maskedCardNumber);
 
    // Perform the JSONP request to store it (asynchronous by nature)
    jQuery.getJSON('https://token.ultracart.com/cgi-bin/UCCheckoutAPICardStore?callback=?', 
      {
        merchantId: cart.merchantId,
        shoppingCartId: cart.cartId,
        cardNumber: cardNumber
      }
    ).done(function(data) { 
      if (data.success) {
        cart.creditCardNumber = data.maskedCardNumber;
        cart.creditCardType = data.cardType;
        jQuery("#cardNumberId").val(cart.creditCardNumber);
      }
    });
  }
 
</script>
 
Card Number <input type="text" name="cardNumber" onblur="storeCard()" id="cardNumberId"/> <br/>
Other Field <input type="text" name"other"/>
 


 

The rest_api github project has this code implemented for reference:

https://github.com/UltraCart/rest_api/tree/master/cart_example

You'll see a reference to it within copyAllElementValuesToCart (cart_X.X.js), and the actual function is found within ultracart_common_functions_X.X.js