GuidesAPI ReferenceChangelog
Log In
Guides

Purchase with Payment Token

Overview

Hosted Tokenization allows your customers to input credit card numbers directly on your website in a secure frame controlled by Moneris.

Accepting customer payments by using the Moneris Hosted Tokenization and the Moneris server-to-server APIs allows you to avoid compliance burdens for Payment Card Industry (PCI) standards.

Hosted Tokenization allows your customers to input credit card numbers directly on your website in a secure frame controlled by Moneris; this allows the rest of your website to maintain the look and feel you choose. Upon customer submission the tokenization frame captures the sensitive credit card data and returns a temporary “token” to your server allowing you to proceed with payment via our API.


1. Hosted Tokenization Setup

You will need to follow these steps.

  1. Login to your Moneris Merchant Resource Centre:
  2. Click on ‘Admin’ on the menu.
  3. Click on ‘Hosted Tokenization’ in the sub-menu.
  4. Enter the source domain page. This is the address of the main outer page that sends the transaction to Moneris.
  5. Click the button “Create Profile”
  6. Make a note of the Profile ID that gets generated since this will need to be included in your HTML iFrame code.
  7. Do the required development as outlined here
  8. Test your solution in the test environment
  9. Activate your production store
  10. Create and configure your product Hosted Tokenization store in the production Merchant Resource Centre
  11. Make the necessary changes to move your solution from the test environment into production

📘

Moneris Merchant Resource Centre (MRC)

Access MRC MRC Sign in Credentials


2. Getting Temporary Token

To get a temporary token you will need to send a request to Moneris from within an IFrame.

A sample code is illustrated below.

Note that the Profile ID in the HTML link below will need to be replaced with your own Profile ID, which you can configure the MRC as described here.


📘

Note

The src and postMessage URL will need to be updated to the appropriate QA or production URL listed below.


Required variables

Variable NameDefinition
IdRequired - Provided by the Hosted Tokenization profile configuration tool in the MRC.
css_bodyRequired - CSS applied to the body. By default, margin and padding is set to zero
css_textboxRequired - CSS applied to all text boxes in general.

Optional variables

Variable NameDefinition
pmmsgRecommended - Forces form to only accept message of 'tokenize'.
css_textbox_panOptional - CSS applied to the pan text box specifically.
enable_expOptional - Must be set to 1 for expiry date text box to be displayed (Format: MMYY)
css_textbox_expOptional - CSS applied to the expiry date text box specifically.
enable_cvdOptional - Must be set to 1 for CVD text box to be displayed
css_textbox_cvdOptional - CSS applied to the CVD text box specifically.
display_labelsOptional – 0 for no labels, 1 for traditional labels, 2 for place holder labels.
css_input_labelOptional – CSS for input labels
css_label_panOptional – CSS for card number label
css_label_expOptional – CSS for expiry date label
css_label_cvdOptional – CSS for CVD label
pan_labelOptional – text for card number label (default is “Card Number”)
exp_labelOptional – text for expiry date label (default is “Expiry Date”)
cvd_labelOptional – text for CVD label (default is “CVD”)
enable_exp_formattingOptional - Formatting applied to expiry date field to display a slash between month and year (Format: MM/YY). Must be set to 1 to enable formatting.
enable_cc_formattingOptional - Formatting applied to credit card number based on the card type (Format: Visa - 4242 4242 4242 4242, MC - 5454 5454 5454 5454, Amex - 333 666666 55555)

Response Fields

FieldDescription
responseCodeIndication whether the page-loading or card-submission was successful or why it failed. Please note, if expiry text box or CVD text box are enabled, the returned responseCode value will be in the form of a list (e.g. [“944”,”943”]), since there may be more than one failure. For example, in the case where both the card number entered and expiry date are invalid. If only the card number text box is displayed, the responseCode will be returned in the form of a string.
errorMessageDescription of failure (This is a very generic description – see “responseCode Definitions” below for specific error code results).
binBIN range of the submitted card number. Provides merchant ability to determine the card type and perform any card-specific processing.
dataKeyTokenized card number. This is what is used with the Vault API transaction

Response Code Definitions

Response CodeDefinition
001Successful creation of temporary token
940Invalid profile id (on tokenization request)
941Error generating token
942Invalid Profile ID, or source URL
943Card data is invalid (not numeric, fails mod10, we will remove spaces)
944Invalid expiration date (mmyy, must be current month or in the future)
945Invalid CVD data (not 3-4 digits)

Code sample

<html>
<head>
  <title>Outer Frame - Merchant Page</title>
  <script>
    function doMonerisSubmit() {
      var monFrameRef = document.getElementById('monerisFrame').contentWindow;
      monFrameRef.postMessage('tokenize', 'https://mpg1t.moneris.io/HPPtoken/index.php');
      // Change link according to table above
      return false;
    }

    var respMsg = function (e) {
      var respData = eval("(" + e.data + ")");
      document.getElementById("monerisResponse").innerHTML = e.origin + " SENT " + " - " +
        respData.responseCode + "-" + respData.dataKey + "-" + respData.errorMessage;
      document.getElementById("monerisFrame").style.display = 'none';
    }

    window.onload = function () {
      if (window.addEventListener) {
        window.addEventListener("message", respMsg, false);
      } else {
        if (window.attachEvent) {
          window.attachEvent("onmessage", respMsg);
        }
      }
    }
  </script>
</head>
<body>
  <div>Hosted Tokenization Demo</div>
  <div id="monerisResponse"></div>
  <iframe
    id="monerisFrame"
    src="https://mpg1t.moneris.io/HPPtoken/index.php?id=ht1TTK3NZLJ82PE&pmmsg=true&css_body=background:white;margin:0 0 0 6px;padding:0;color:darkgray;&css_textbox=font-size:0.975rem;float:left;border-width:0;margin:0 0 0 4px;padding:0;height:30px;&css_textbox_pan=width:180px;&enable_exp=1&css_textbox_exp=width:70px;&enable_cvd=1&css_textbox_cvd=width:50px;&display_labels=2&exp_label=MMYY"
    frameborder="0"
    style="width: calc(100% - 10px); height: 60px;">
  </iframe>
  <input type="button" onClick="doMonerisSubmit()" value="submit iframe">
</body>
</html>

3. Receiving Temporary Token Response

var respMsg = function (e) {
  var respData = eval("(" + e.data + ")");
  document.getElementById("monerisResponse").innerHTML = e.origin + " SENT " + " - " +
    respData.responseCode + "-" + respData.dataKey + "-" + respData.errorMessage;
  document.getElementById("monerisFrame").style.display = 'none';
  // Your token will be in the field: respData.dataKey
  // From this point you can post the token to another page that will process the payment.
}

📘

Note

Describes how to receive the response from the Hosted Tokenization page containing the temporary token


4. Processing the Payment

To charge the card using the temporary token you will need to utilize our API to Create Payment with the temporary token as the payment method.

In the POST /payments request, include the “paymentMethodData” object with the following parameters:

  • "paymentMethodType" with a value of "TEMPORARY_TOKEN",
  • “temporaryToken” with a value matching the token provided by the Hosted Tokenization service

📘

For details on the API, refer to:

Navigate to Purchase Navigate to Pre-Authorization & Completion


Additional Information

📘

Learn more with the API Definitions

Peruse the endpoints, request/response formats, and authentication methods covered in this scenario.

API References