Payment Isolation Gateway Interface API
Your storefront can send actions to the Payment Isolation Gateway Interface (PIGI) and receive responses back. Both actions and responses consist of messages sent via the Window.postMessage() method. This reference includes all the possible actions and associated responses.
For information on how PIGI works, refer to the Concepts page. For information on integrating PIGI into your headless checkout, refer to the Integrate PIGI page.
Terminology
Throughout the following reference, keep the following terms in mind:
- Actions are commands sent from the parent to PIGI. Each action has a corresponding response. If an action fails, an error message is displayed to the end user.
- Responses are messages sent from PIGI back to the parent. Most responses are sent after an action is complete, but some are independent from the actions.
- The parent is the DOM containing the PIGI
<iframe>element. - A message is a JavaScript variable sent to PIGI or the parent using
Window.postMessage().
Add Payment
Add Payment Action
stringactionType:PIGI_ADD_PAYMENT
Send this action to tokenize the customer-entered payment information and add that token to the order. This action does not authorize or capture the payment.
Example message sent from parent to PIGI:
{
actionType: 'PIGI_ADD_PAYMENT',
}
Add Payment Response
stringresponseType:PIGI_ADD_PAYMENTobjectpayload:stringpaymentType - Acceptable values areCREDIT_CARD,BRANDED_CARD,GIFT_CARD, orPAYPAL.booleansuccess -truewhen thePIGI_ADD_PAYMENTaction succeeds.numberheight - the height of the DOM that contains PIGI (measured in pixels) when the response message sends.
PIGI sends this response to the parent when the payment has been successfully added to the order.
PIGI also sends this response to the parent when a customer adds a gift card payment to the order, because the gift card payment method contains its own button and requires no instructions to add the payment. You may wish to update the order information in the parent window to display the new outstanding balance.
Example message sent from PIGI to parent:
{
responseType: 'PIGI_ADD_PAYMENT',
payload: {
paymentType: 'CREDIT_CARD',
success: true,
height: 120,
},
}
Refresh Order
Refresh Order Action
stringactionType:PIGI_REFRESH_ORDER
Send this action to PIGI if a customer updates their order after PIGI was first displayed (e.g., if a customer updates the order line items). Payment gateways require updated information about the customer or order to add the payment to the order.
Example message sent from the parent to PIGI:
{
actionType: 'PIGI_REFRESH_ORDER',
}
Refresh Order Response
stringresponseType:PIGI_REFRESH_ORDERobjectpayload:booleansuccess -truewhen thePIGI_REFRESH_ORDERaction succeeds.numberheight - the height of the DOM that contains PIGI (measured in pixels) when the response message sends.
PIGI sends this message back to the parent when it successfully refreshes the order.
Example message sent from PIGI to the parent:
{
responseType: 'PIGI_REFRESH_ORDER',
payload: {
success: true,
height: 120,
},
}
Update Language
Update Language Action
stringactionType:PIGI_UPDATE_LANGUAGEobjectpayload:stringlanguage - language ISO in ISO-639-1 format.
Send this action to change the language displayed in PIGI. This action requires a payload that contains the new language in ISO-639-1 format.
Example message sent from the parent to PIGI:
{
actionType: 'PIGI_UPDATE_LANGUAGE',
payload: {
language: 'en',
},
}
Update Language Response
stringresponseType:PIGI_UPDATE_LANGUAGEobjectpayload:booleansuccess -truewhen thePIGI_UPDATE_LANGUAGEaction succeeds.numberheight - the height of the DOM that contains PIGI (measured in pixels) when the response message sends.
PIGI sends this response back to the parent when it successfully updates the language.
Example message sent back to the parent:
{
responseType: 'PIGI_UPDATE_LANGUAGE',
payload: {
success: true,
height: 120,
},
}
Update Media Match
Update Media Match Action
stringactionType:PIGI_UPDATE_MEDIA_MATCHobjectpayload:stringconditionText - media rule condition.booleanmatches - whether or not the condition was met.
The Create CSS Styling for PIGI endpoint enables you to change the CSS styling for PIGI user interface. This endpoint defines media rules, which make changes to the CSS under certain conditions.
Every time PIGI initializes (and the parent receives the PIGI Initialize Response), check whether the media rules have changed. If the the media rules have changed, use the PIGI_UPDATE_MEDIA_MATCH action to pass the new media rule to PIGI. You can do so by adding a listener — the following JavaScript snippet shows an example:
function updateMediaMatch(event) {
const payload = {
conditionText: event.media,
matches: event.matches,
};
const iframeElement = document.querySelector("iframe#PIGI");
const iframeWindow = iframeElement.contentWindow;
const action = { actionType: "PIGI_UPDATE_MEDIA_MATCH", payload };
iframeWindow.postMessage(action, "*");
}
// The following media rules are a result of a call to the [Create CSS Styling for PIGI](/api/checkout#operation/CreateCSSStylingForPIGI) endpoint.
const mediaRules = [
{
conditionText: "screen and (max-height: 600px)",
cssRules: [
{
cssText: ".ToggleField__Text { color:blue; }",
},
],
},
];
mediaRules.forEach((rule) => {
const mediaMatch = window.matchMedia(rule.conditionText);
mediaMatch.addListener(updateMediaMatch);
updateMediaMatch(mediaMatch);
});
The following example shows the PIGI_UPDATE_MEDIA_MATCH sent from the parent to PIGI:
{
actionType: 'PIGI_UPDATE_MEDIA_MATCH',
payload: {
conditionText: 'screen and (min-width: 768px)',
matches: false
},
}
Update Media Match Response
stringresponseType:PIGI_UPDATE_MEDIA_MATCHobjectpayload:booleansuccess -truewhen thePIGI_UPDATE_MEDIA_MATCHaction succeeds.numberheight - the height of the DOM that contains PIGI (measured in pixels) when the response message sends.
Example message sent back to the parent:
{
responseType: 'PIGI_UPDATE_MEDIA_MATCH',
payload: {
success: true,
height: 120,
},
}
Display Error Message
Display Error Message Action
stringactionType:PIGI_DISPLAY_ERROR_MESSAGEobjectpayload:stringmessage - error message to display in PIGI.stringsub_type - type of error, corresponds to payment gateway name.
Send this action to PIGI to display an error message in the user interface. The sub_type of error helps PIGI determine where to display the error. You can display more than one error at a time.
Example message sent from the parent to PIGI:
{
actionType: 'PIGI_DISPLAY_ERROR_MESSAGE',
payload: {
error: {
message: 'message to be displayed',
sub_type: 'string_to_categorize_error',
},
},
}
Display Error Message Response
stringresponseType:PIGI_DISPLAY_ERROR_MESSAGEobjectpayload:booleansuccess -truewhen thePIGI_DISPLAY_ERROR_MESSAGEaction succeeds.numberheight - the height of the DOM that contains PIGI (measured in pixels) when the response message sends.
PIGI sends this response to the parent when the error successfully displays.
Example message sent from PIGI to the parent:
{
responseType: 'PIGI_DISPLAY_ERROR_MESSAGE',
payload: {
success: true,
height: 120,
},
}
Clear Error Messages
Clear Error Messages Action
stringactionType:PIGI_CLEAR_ERROR_MESSAGES
Send this message to PIGI when you want to remove the error message from the user interface.
Example message sent from the parent to PIGI:
{
actionType: 'PIGI_CLEAR_ERROR_MESSAGES',
}
Clear Error Messages Response
stringresponseType:PIGI_CLEAR_ERROR_MESSAGESobjectpayload:booleansuccess -truewhen thePIGI_CLEAR_ERROR_MESSAGESaction succeedsnumberheight - the height of the DOM that contains PIGI (measured in pixels) when the response message sends.
PIGI sends this message to the parent when it successfully removes any error messages.
Example message sent from PIGI to the parent:
{
responseType: 'PIGI_CLEAR_ERROR_MESSAGES',
payload: {
success: true,
height: 120,
},
}
Select Payment Method
Select Payment Method Action
stringresponseType:PIGI_SELECT_PAYMENT_METHODobjectpayload:numberindex - the index of the payment gateway method to be selected.stringgatewayName - the gateway name of the payment gateway method to be selected. The available names include:stripe,authorize,spreedly,qualpay,braintree,paysafe,moneris,adyen,cybersource,paypal_paypal,paypal_braintree,flexiti,branded_flexiti,branded_paysafe, andamazon
Send this action to PIGI to reflect the customer's choice of payment method. Either the index or gatewayName is required. If both are used, PIGI uses index.
Example message sent from the parent to PIGI:
{
actionType: 'PIGI_SELECT_PAYMENT_METHOD',
payload: {
gatewayName: 'stripe',
},
}
Select Payment Method Response
stringresponseType:PIGI_SELECT_PAYMENT_METHODobjectpayload:booleansuccess -truewhen thePIGI_SELECT_PAYMENT_METHODaction succeeds.numberheight - the height of the DOM that contains PIGI (measured in pixels) when the response message sends.
PIGI sends this response when the payment method has been selected.
Example message sent from PIGI to the parent:
{
responseType: 'PIGI_SELECT_PAYMENT_METHOD',
payload: {
success: true,
height: 120,
},
}
Handle SCA
Handle SCA Action
stringresponseType:PIGI_HANDLE_SCAobjectpayload:
Send this action to PIGI when you receive a 202 error in response to calling the Process Order endpoint.
Example message sent from the parent to PIGI:
{
actionType: "PIGI_HANDLE_SCA";
}
Handle SCA Response
stringresponseType:PIGI_HANDLE_SCAobjectpayload:stringstep - the status of the 3DS authentication. Possible values areDISPLAYED,COMPLETED, orFAILED.booleansuccess -truewhen thePIGI_HANDLE_SCAaction succeeds.numberheight - the height of the DOM that contains PIGI (measured in pixels) when the response message sends.
PIGI uses 3D Secure (3DS) to prompt the customer to verify their identity. PIGI then sends several responses that indicate when the 3DS interface is displayed and when the authentication is complete.
Example message sent from PIGI to the parent:
{
responseType: 'PIGI_HANDLE_SCA',
payload: {
step: 'DISPLAYED'
success: true,
height: 120,
},
}
The parent must handle this response and act appropriately. The following JavaScript snippet provides an example of handling the PIGI_HANDLE_SCA response:
window.addEventListener('message', ({ data }) => {
const type = data.responseType;
switch (type) {
case 'PIGI_HANDLE_SCA':
switch (data.payload.step) {
case 'DISPLAYED':
// Code for when the 3DS screen is displayed within the PIGI iframe. This code should resize the PIGI iframe accordingly.
break;
case 'COMPLETED':
// Code for when authentication is successful. The frontend should make another call to the Process Order endpoint.
break;
case 'FAILED':
// Code for when authentication is not successful.
break;
default:
}
break;
}
}
Event-driven responses
Some messages sent by PIGI to the parent will not happen in response to an action sent from the parent but letting the parent know an event has happened within PIGI.
PIGI Initialize Response
stringresponseType:PIGI_INITIALIZEDobjectpayload:booleansuccessnumberheight - the height of the DOM that contains PIGI (measured in pixels) when the response message sends.
PIGI sends this message when it successfully loads and is ready to start receiving actions.
Example message sent from PIGI to the parent:
{
responseType: 'PIGI_INITIALIZED',
payload: {
success: true,
height: 120,
},
}
PIGI Update Height Response
stringresponseType:PIGI_UPDATE_HEIGHTobjectpayload:booleansuccessnumberheight - the height of the DOM that contains PIGI (measured in pixels) when the response message sends.
PIGI sends this message when the document height is updated.
Example message sent from PIGI to the parent:
{
responseType: 'PIGI_UPDATE_HEIGHT',
payload: {
success: true,
height: 120,
},
}