fune/browser/components/payments/res/unprivileged-fallbacks.js
prathiksha c8c6fdba8f Bug 1475760 - Take address-fields into account for payer/contact picker dropdown labels. r=MattN
Differential Revision: https://phabricator.services.mozilla.com/D2831

--HG--
extra : rebase_source : 13304d7b7739ebb5a2b7d835ffaf088dc40afd17
2018-08-20 13:23:43 -07:00

62 lines
2.2 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* This file defines fallback objects to be used during development outside
* of the paymentDialogWrapper. When loaded in the wrapper, a frame script
* overwrites these methods. Since these methods need to get overwritten in the
* global scope, it can't be converted into an ES module.
*/
/* eslint-disable no-console */
/* exported log, PaymentDialogUtils */
"use strict";
var log = {
error: console.error.bind(console, "paymentRequest.xhtml:"),
warn: console.warn.bind(console, "paymentRequest.xhtml:"),
info: console.info.bind(console, "paymentRequest.xhtml:"),
debug: console.debug.bind(console, "paymentRequest.xhtml:"),
};
var PaymentDialogUtils = {
getAddressLabel(address, addressFields = null) {
if (addressFields) {
let requestedFields = addressFields.trim().split(/\s+/);
return requestedFields.filter(f => f && address[f]).map(f => address[f]).join(", ") +
` (${address.guid})`;
}
return `${address.name} (${address.guid})`;
},
isCCNumber(str) {
return !!str.replace(/[-\s]/g, "").match(/^\d{9,}$/);
},
DEFAULT_REGION: "US",
supportedCountries: ["US", "CA"],
getFormFormat(country) {
return {
"addressLevel1Label": country == "US" ? "state" : "province",
"postalCodeLabel": country == "US" ? "zip" : "postalCode",
"fieldsOrder": [
{fieldId: "name", newLine: true},
{fieldId: "organization", newLine: true},
{fieldId: "street-address", newLine: true},
{fieldId: "address-level2"},
{fieldId: "address-level1"},
{fieldId: "postal-code"},
],
// The following values come from addressReferences.js and should not be changed.
/* eslint-disable-next-line max-len */
"postalCodePattern": country == "US" ? "(\\d{5})(?:[ \\-](\\d{4}))?" : "[ABCEGHJKLMNPRSTVXY]\\d[ABCEGHJ-NPRSTV-Z] ?\\d[ABCEGHJ-NPRSTV-Z]\\d",
};
},
getDefaultPreferences() {
let prefValues = {
saveCreditCardDefaultChecked: false,
saveAddressDefaultChecked: true,
};
return prefValues;
},
};