Documentation
Feedback
Guides
API Reference

Guides
VTEX Sales App
How to customize VTEX Sales App
Define payment methods displayed on VTEX Sales App

After creating a payment condition as described in the VTEX Sales App - Payments guide, we need to create the filters that will define which payment methods will appear at inStore’s checkout.

You must do this by inserting a JavaScript object in the checkout-instore-custom.js file. Check out the How to customize VTEX Sales App guide for further information on how to access this file.

Edit the checkout-instore-custom.js file

There are two options for defining which payment methods will be displayed on VTEX Sales App. You can set global payment methods, that is, payment methods that any VTEX Sales App user will be able to see, or payment methods per vendor, which means only specific users will be able to see them.

Define global payment methods

  1. The object that contains the payment filters is called window.PAYMENTS_FILTER_GLOBAL. If this object does not already exist in the code, you should insert it, as described below.

The window.PAYMENTS_FILTER_GLOBAL object should contain the following properties:


_15
{
_15
"data": {
_15
"h-0": "Attribute",
_15
"h-1": "Type",
_15
"h-2": "Description",
_15
"0-0": "`removeFilters`",
_15
"0-1": "array",
_15
"0-2": "You should add payment conditions that **will not** be displayed on VTEX Sales App in this array",
_15
"1-0": "`filters`",
_15
"1-1": "array",
_15
"1-2": "You should add payment conditions that **will** be displayed on VTEX Sales App in this array"
_15
},
_15
"cols": 3,
_15
"rows": 2
_15
}

You must identify each payment condition by their payment condition ID. Check Where to find the payment condition ID for more details.

The code should look similar to the example below.


_10
{
_10
"codes": [
_10
{
_10
"code": "\nwindow.PAYMENTS_FILTER_GLOBAL = {\n removeFilters: [\n '6', // Boleto Bancário\n '45', // Direct debit\n ],\n filters: [\n '2', '4', // Credit card\n '202' // Cash\n '125' // Pix\n ]\n};",
_10
"language": "javascript"
_10
}
_10
]
_10
}

In this example, we are excluding the conditions “Boleto bancário” (ID = 6) and "Direct debit" (ID = 45); and we are including “Credit card” (IDs = 2 and 4), “Cash” (ID = 202) and "Pix" (ID = 125). The first two will not be displayed at checkout, while the last two will be displayed.

  1. Still in the checkout-instore-custom.js file, you need to add a reference to the object created within the window.INSTORE_CONFIG object.

To do this, include the following line of code inside the window.INSTORE_CONFIG object:


_10
payments: window.PAYMENTS_FILTER_GLOBAL

The window.INSTORE_CONFIG object should then look like the example below:


_10
window.INSTORE_CONFIG = {
_10
payments: window.PAYMENTS_FILTER_GLOBAL,
_10
};

Do not remove any of the other properties present in the window.INSTORE_CONFIG object to avoid breaking other functionalities.

  1. After making changes in the code, make sure you press the Save button.

Define payment methods per sales associate

After you define the global payment methods that will be displayed in your store, you can override this information with the specific payment methods you want to remove for specific sales associates.

  1. You must declare a constant object in the checkout-instore-custom.js file. Inside it, you can use removeFilters and filters properties described in the Define global payment methods section to define the payment methods that will be displayed for this user.

    The example below determines that the user whose email is john@email.com will not see the Cash payment method option on VTEX Sales App.


_10
const vendorConfig = {
_10
'john@email.com': {
_10
payments: {
_10
removeFilters: [
_10
'202', // Cash
_10
],
_10
},
_10
},
_10
}

  1. Add the following functions to your checkout-instore-custom.js file. They will observe if the sales associate has a specific configuration associated with them, then set the specific payment methods filter associated with them, and repeat this validation every time a different user logs in.

_43
function hasVendorConfig(vendor) {
_43
const email = vendor && vendor.username
_43
return (
_43
email &&
_43
vendorConfig[email] &&
_43
vendorConfig[email].payments &&
_43
(vendorConfig[email].payments.filters ||
_43
vendorConfig[email].payments.removeFilters)
_43
)
_43
}
_43
_43
function setPaymentsFilter(vendor) {
_43
const email = vendor && vendor.username
_43
if (hasVendorConfig(vendor)) {
_43
const pFilters = vendorConfig[email].payments
_43
if (pFilters.filters) {
_43
window.INSTORE_CONFIG.payments = window.INSTORE_CONFIG.payments || {}
_43
window.INSTORE_CONFIG.payments.filters = pFilters.filters
_43
}
_43
if (pFilters.removeFilters) {
_43
window.INSTORE_CONFIG.payments = window.INSTORE_CONFIG.payments || {}
_43
window.INSTORE_CONFIG.payments.removeFilters = pFilters.removeFilters
_43
}
_43
} else {
_43
window.INSTORE_CONFIG.payments = window.PAYMENTS_FILTER_GLOBAL
_43
}
_43
}
_43
_43
function onVendorChange(vendor) {
_43
setPaymentsFilter(vendor)
_43
}
_43
_43
document.addEventListener(
_43
'vendorIdentified',
_43
function (event) {
_43
const data = event.data
_43
const vendor = data.vendor
_43
onVendorChange(vendor)
_43
},
_43
false
_43
)
_43
_43
onVendorChange(getVendor())

  1. After making changes in the code, make sure you press the Save button.

Where to find the payment condition ID

As explained above, the implementation of payment filters requires listing the payment condition IDs in the window.PAYMENTS_FILTER_GLOBAL object.

You can find the ID of each condition in the Payments module. In the main menu of the VTEX Admin, click on Payments and then on Settings.

In the Payment conditions tab, you will find the ID next to each of the conditions. In the example below, we see that the payment condition ID for Cash is 202.

{"base64":"  ","img":{"width":1161,"height":206,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":11566,"url":"https://cdn.jsdelivr.net/gh/vtexdocs/dev-portal-content@main/images/define-payment-methods-displayed-on-instore-0.png"}}
If we wanted to include Cash as a payment condition to be displayed at the inStore checkout, this would be the value we would add to the filters array, inside the window.PAYMENTS_FILTER_GLOBAL object of the checkout-instore-custom.js file.

Contributors
1
Photo of the contributor
+ 1 contributors
Was this helpful?
Yes
No
Suggest edits (Github)
Contributors
1
Photo of the contributor
+ 1 contributors
On this page