Skip to main content

With the initialize card transaction (v2) endpoint you get a card payment page that is hosted by CM.com. Inside it the consumer enters their card details and completes 3D Secure authentication if their bank asks for it. Card data never touches your systems.

The page is made to be embedded in an iframe on your own checkout page. While the consumer pays, it sends messages to your page with postMessage, so you know when to show your own success or failure screen.

How does it work?

  1. Call the initialize card transaction (v2) endpoint. The transaction is created with status OPEN.
  2. Set action.iframe.url from the response as the src of an iframe on your page. Use the URL as it is; do not build or change it.
  3. The consumer enters their card details in the iframe and confirms the payment.
  4. If the bank asks for 3D Secure authentication, the consumer completes it inside the same iframe. On our acceptance environment you can use these OTP codes to test the different outcomes.
  5. When the payment has a final status, the page sends a transactionStatus message to your page.
  6. You confirm the final status with a webhook for the STATUS_CHANGE event, or with the get card transaction (v2) endpoint. Then replace the iframe with your own result screen. The page shows a short result after 3D Secure, but not after every outcome, so do not rely on it.

The consumer stays on your page the whole time. They are not redirected to returnUrl or returnUrls: these fields are required in the request, but this flow does not use them.

The message is not proof of payment

A postMessage is a hint for your user interface. It can be lost, for example when the consumer closes the tab. Always use the webhook, or the get transaction endpoint, to decide whether the order is paid.

action.redirect.url is deprecated

The response also holds the same URL in action.redirect.url. That field is kept for existing integrations and will be removed in a future version. Use action.iframe.url. Opening the page as a top-level page or in a popup is not supported: your page then receives no messages.

Adding the iframe

<iframe
id="cm-card-payment"
src="<action.iframe.url>"
title="Card payment"
style="width: 100%; height: 500px; border: 0;"
sandbox="allow-scripts allow-forms allow-same-origin allow-popups"
></iframe>
  • sandbox: if you sandbox the iframe, allow at least the four tokens above. The page needs scripts and forms for the card form and 3D Secure, and its own origin for its requests. Some banks open help links in a new window. Do not add allow-top-navigation: the page never navigates your page.
  • Height: start with a height of about 500 pixels. The page sends iframeResize messages with the height it needs.
  • Content Security Policy: if your page has a CSP, allow the CM.com host of your environment in frame-src (see Checking where a message comes from).
  • Keep the iframe on the page until you have received a final status. Removing the iframe, or the consumer leaving your page, while the payment is in progress cancels the payment.

Messages

Every message is a plain object with these fields:

FieldTypeDescription
typestringThe kind of message. See below.
versionnumberThe version of the message format. Currently 1.
iframeIdstringAlways creditCardV2Frame. Use it to tell these messages from others.

Messages do not contain personal data or card data. Ignore types and fields you don't know: new ones can be added without a version change. A change that breaks the format comes with a new version.

transactionStatus​

The payment has a final status. The page sends this message once each time it loads. If the iframe is loaded again after the payment is final, you receive the message again, so make sure a duplicate does no harm.

{
"type": "transactionStatus",
"version": 1,
"iframeId": "creditCardV2Frame",
"transaction": {
"status": "successful"
}
}

transaction.status is the status of the card payment page, which differs from the API status. See Outcomes for what each value means.

transaction.statusAPI status (get transaction, webhook)
successfulSUCCESS
failedFAILURE
cancelledCANCELLED
expiredEXPIRED
rejectedFAILURE

error​

The page could not determine a final status. The payment may still complete, so get the status from the API. See When you receive no final status.

{
"type": "error",
"version": 1,
"iframeId": "creditCardV2Frame",
"code": "status_unavailable"
}
codeMeaning
status_unavailableThe page could not get the final status of the payment in time.
initialization_failedThe card form or the 3D Secure page loaded, but could not start.

iframeResize​

The page needs a different height, for example when the 3D Secure challenge of the bank is shown. Set the height of the iframe to height pixels.

{ "type": "iframeResize", "version": 1, "iframeId": "creditCardV2Frame", "height": 640 }

resetScroll​

The content of the page changed completely, for example when 3D Secure starts. Scroll your page so the top of the iframe is visible.

{ "type": "resetScroll", "version": 1, "iframeId": "creditCardV2Frame" }

Listening for messages

Checking where a message comes from​

Any page can send your page a message, so check every message before you act on it:

  1. event.origin must be the CM.com host of your environment:

    EnvironmentOrigin
    Acceptancehttps://cardprocessing.acc.pay.cm.com
    Productionhttps://cardprocessing.pay.cm.com
  2. event.source must be the window of your iframe.

  3. event.data.iframeId must be creditCardV2Frame.

Example​

const CM_ORIGIN = 'https://cardprocessing.pay.cm.com'; // https://cardprocessing.acc.pay.cm.com on acceptance
const iframe = document.getElementById('cm-card-payment');

window.addEventListener('message', (event) => {
if (event.origin !== CM_ORIGIN || event.source !== iframe.contentWindow) {
return;
}
const message = event.data;
if (!message || message.iframeId !== 'creditCardV2Frame') {
return;
}

switch (message.type) {
case 'transactionStatus':
// A hint: confirm the status on your server (webhook or get transaction) before you show the result.
showResult(message.transaction.status);
break;
case 'error':
// No final status yet: ask your server to poll the get transaction endpoint.
waitForFinalStatus();
break;
case 'iframeResize':
iframe.style.height = `${message.height}px`;
break;
case 'resetScroll':
iframe.scrollIntoView({ block: 'start' });
break;
// Ignore any other type.
}
});

Outcomes

The iframe never navigates your page and never closes itself, and it does not show a result for every outcome. So replace or hide the iframe as soon as you receive a transactionStatus or error message, and show your own result screen.

Which message your page receives for each outcome, what the iframe shows, and what we recommend you do.

OutcomeMessageAPI statusWhat the iframe showsWhat to do
Payment authorised, with or without a 3D Secure challengetransactionStatus, successfulSUCCESS"Payment successful" after 3D Secure, otherwise the card formConfirm the status, then show your order confirmation.
3D Secure challenge not passed (for example a wrong code)transactionStatus, usually failed, sometimes cancelledFAILURE or CANCELLED"Payment not completed"Let the consumer try again with a new transaction, or offer another payment method.
3D Secure failed without a challenge, the card was declined, or a technical errortransactionStatus, failedFAILURE"Payment not completed" after 3D Secure, otherwise the card formLet the consumer try again with a new transaction, or offer another payment method.
Blocked by fraud screeningtransactionStatus, rejectedFAILURE"Payment not completed" after 3D Secure, otherwise the card formOffer another payment method. Do not retry with the same card.
3D Secure was not finished in timetransactionStatus, expiredEXPIRED"Payment not completed"Start a new transaction if the consumer wants to pay.
The card details were rejected, or the payment could not be submittedNoneOPEN, or the final status if the payment was already finishedThe card form with an error message. The consumer can correct their details and confirm again.Keep the iframe. If the consumer gives up, rely on the webhook or the get transaction endpoint.
The consumer did not confirm the card form in timeNoneEXPIREDThe card formRely on the webhook or the get transaction endpoint.
The page could not get the final statuserror, status_unavailableAny"We could not confirm your payment" after 3D Secure, otherwise the card form with an error messagePoll the get transaction endpoint until the status is final.
The card form or the 3D Secure page loaded, but could not starterror, initialization_failedOPEN, later EXPIRED"Payment not completed" on the 3D Secure page. The card form can stay empty or incomplete.Check that you use action.iframe.url unchanged, then start a new transaction.
The URL was changed or is incomplete, or the transaction is unknownNoneOPEN, later EXPIREDA plain error pageUse action.iframe.url unchanged, then start a new transaction.
The consumer closed the tab or left your pageNoneCANCELLED or EXPIREDNothing, the iframe is goneRely on the webhook or the get transaction endpoint.

After a wrong 3D Secure code the bank decides the result, and depending on how it reports it you receive failed or cancelled. Treat both the same way: the payment is not completed.

A transaction can be paid only once. To let the consumer try again after a final status other than SUCCESS, initialize a new transaction and load its URL in the iframe.

When you receive no final status

Your page can miss the final message, for example when the consumer's connection drops. Do not wait for a message forever:

  • When you receive an error message, get the status from your server.
  • When you have received no message about 1 minute after the consumer confirmed the card form, also get the status from your server, and keep the iframe on the page. Getting the status does not affect the payment.
  • The page itself does not wait forever either. The card form checks for a final status for about 30 seconds after the consumer confirms it. During 3D Secure the consumer can take longer at their bank, so the 3D Secure page keeps checking until the transaction expires, plus 2 minutes. When the page stops checking without a final status, it sends error with status_unavailable.
  • Your server uses the webhook, or polls the get card transaction (v2) endpoint with a growing interval, until the status is final (SUCCESS, FAILURE, CANCELLED or EXPIRED).
  • A transaction that is never finished expires. See transaction expiration.

Sequence

The payment without problems:

Consumer Your page / server CM.com API CM.com card payment page (iframe)
| | | |
| go to checkout | | |
|-------------------->| POST .../initialize | |
| |------------------------->| |
| | 201, action.iframe.url | |
| |<-------------------------| |
| | <iframe src=action.iframe.url> |
| |---------------------------------------------------->|
| card details, 3D Secure (inside the iframe) |
|-------------------------------------------------------------------------->|
| | postMessage transactionStatus "successful" |
| |<----------------------------------------------------|
| | webhook | |
| |<-------------------------| |
| | GET transaction | |
| |------------------------->| |
| | status SUCCESS | |
| |<-------------------------| |
| order confirmation | | |
|<--------------------| | |

When the payment is not completed (failed, cancelled, rejected or expired):

Consumer Your page / server CM.com API CM.com card payment page (iframe)
| | | |
| card details, 3D Secure (inside the iframe) |
|-------------------------------------------------------------------------->|
| | postMessage transactionStatus "failed" |
| |<----------------------------------------------------|
| | webhook | |
| |<-------------------------| |
| | GET transaction | |
| |------------------------->| |
| | status FAILURE | |
| |<-------------------------| |
| try again, or another payment method | |
|<--------------------| | |
| try again | | |
|-------------------->| POST .../initialize (new transaction) |
| |------------------------->| |
| | 201, new action.iframe.url |
| |<-------------------------| |

When the page cannot confirm the status:

Consumer Your page / server CM.com API CM.com card payment page (iframe)
| | | |
| card details, 3D Secure (inside the iframe) |
|-------------------------------------------------------------------------->|
| | postMessage error "status_unavailable" |
| |<----------------------------------------------------|
| | GET transaction (repeat until final) |
| |------------------------->| |
| | status SUCCESS / FAILURE / CANCELLED / EXPIRED |
| |<-------------------------| |
| result | | |
|<--------------------| | |