Skip to content

Commit ba73271

Browse files
braintreepsibooker
andcommitted
Release braintree-web 3.117.0 source
Co-authored-by: Iris Booker <ibooker@paypal.com>
1 parent c095ba7 commit ba73271

File tree

11 files changed

+107
-21
lines changed

11 files changed

+107
-21
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# CHANGELOG
22

3+
## 3.117.0
4+
5+
- Venmo
6+
- Add missing analytics events for Popup Bridge
7+
- Add `styleCspNonce` option to provide nonce to whitelist injected style in content support policy.
8+
- Fraudnet
9+
- Add new option `cb1` to `dataCollector.create()` to allow specifying a callback name that will be invoked when fraudnet has finished initializing.
10+
311
## 3.116.3
412

513
- PayPal Checkout

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "braintree-web",
3-
"version": "3.116.3",
3+
"version": "3.117.0",
44
"license": "MIT",
55
"main": "src/index.js",
66
"private": true,

scripts/release

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ release_source() {
129129
set +e
130130

131131
local CP_CMD="cp"
132-
if [[ "$(uname)"="Darwin" ]]; then
132+
#if [[ "$(uname)"="Darwin" ]]; then
133133
# Coreutils version of cp supports --parents, mac default one doesn't
134-
CP_CMD="gcp"
135-
fi
134+
# CP_CMD="gcp"
135+
#fi
136136

137137
git ls-files | egrep -v "$(join '|' $SOURCE_IGNORES)" | xargs "$CP_CMD" --parents -t "$BRAINTREE_JS_SOURCE_DEST"
138138
echo -e "Applied source changes in ${BLUE}$BRAINTREE_JS_SOURCE_DEST${RESET}."

src/data-collector/fraudnet.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ Fraudnet.prototype.initialize = function (options) {
4747
this._parameterBlock = _createParameterBlock(
4848
this.sessionId,
4949
this._beaconId,
50-
environment
50+
environment,
51+
options.cb1
5152
);
5253

5354
return loadScript({
@@ -94,12 +95,13 @@ function _generateBeaconId(sessionId) {
9495
);
9596
}
9697

97-
function _createParameterBlock(sessionId, beaconId, environment) {
98+
function _createParameterBlock(sessionId, beaconId, environment, cb1) {
9899
var el = document.body.appendChild(document.createElement("script"));
99100
var config = {
100101
f: sessionId,
101102
s: FRAUDNET_SOURCE,
102103
b: beaconId,
104+
cb1: cb1,
103105
};
104106

105107
// for some reason, the presence of the sandbox

src/data-collector/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ var errors = require("./errors");
9090
* @param {string} [options.riskCorrelationId] Pass a custom risk correlation id when creating the data collector.
9191
* @param {string} [options.clientMetadataId] Deprecated. Use `options.riskCorrelationId` instead.
9292
* @param {string} [options.correlationId] Deprecated. Use `options.riskCorrelationId` instead.
93+
* @param {string} [options.cb1] Callback name for fraudnet that will be invoked on the window object when fraudnet is finished initializing.
9394
* @param {callback} [callback] The second argument, `data`, is the {@link DataCollector} instance.
9495
* @returns {(Promise|void)} Returns a promise that resolves the {@link DataCollector} instance if no callback is provided.
9596
*/
@@ -127,6 +128,7 @@ function create(options) {
127128
options.correlationId,
128129
clientSessionId: clientConfiguration.analyticsMetadata.sessionId,
129130
environment: clientConfiguration.gatewayConfiguration.environment,
131+
cb1: options.cb1,
130132
})
131133
.then(function (fraudnetInstance) {
132134
if (fraudnetInstance) {

src/venmo/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ var VERSION = process.env.npm_package_version;
5252
* @param {boolean} [options.allowDesktop] Used to support desktop users. When enabled, the default mode is to render a scannable QR-code customers scan with their phone's to approve via the mobile app.
5353
* @param {boolean} [options.allowDesktopWebLogin=false] When `true`, the customer will authorize payment via a window popup that allows them to sign in to their Venmo account. This is used explicitly for customers operating from desktop browsers wanting to avoid the QR Code flow.
5454
* @param {boolean} [options.mobileWebFallBack] Use this option when you want to use a web-login experience, such as if on mobile and the Venmo app isn't installed.
55+
* @param {string} [options.styleCspNonce] specify a nonce for style code used by Venmo. This option requires either the option `allowDesktopWebLogin=true` or `mobileWebFallback=true`. This nonce should also appear in the `style-src` section of the content security policy. See more about nonces [here]{https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP#nonces}.
5556
* @param {boolean} [options.allowAndroidRecreation=true] This flag is for when your integration uses the [Android PopupBridge](https://github.com/braintree/popup-bridge-android). Setting this flag to false will avoid a page refresh when returning to your page after payment authorization. If not specified, it defaults to true and the Android activity will be recreated, resulting in a page refresh.
5657
* @param {boolean} [options.collectCustomerBillingAddress] When `true`, the customer's billing address will be collected and displayed on the Venmo paysheet (provided the Enriched Customer Data checkbox is also enabled for the merchant account).
5758
* @param {boolean} [options.collectCustomerShippingAddress] When `true`, the customer's shipping address will be collected and displayed on the Venmo paysheet (provided the Enriched Customer Data checkbox is also enabled for the merchant account).

src/venmo/shared/web-login-backdrop.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ function getElementStyles() {
201201
return allStyles.join("\n");
202202
}
203203

204-
function buildAndStyleElements() {
204+
function buildAndStyleElements(styleCspNonce) {
205205
var alreadyRenderedBackdrop = document.getElementById(ELEMENT_IDS.backdrop);
206206
var backdropStylesElement,
207207
backdropDiv,
@@ -226,6 +226,9 @@ function buildAndStyleElements() {
226226
continueButton = document.createElement("button");
227227
cancelButton = document.createElement("button");
228228

229+
if (styleCspNonce) {
230+
backdropStylesElement.nonce = styleCspNonce;
231+
}
229232
backdropStylesElement.id = "venmo-desktop-web__injected-styles";
230233
backdropStylesElement.innerHTML = getElementStyles();
231234

@@ -274,7 +277,7 @@ function buildAndStyleElements() {
274277
* @returns {Promise} Returns a promise
275278
*/
276279
function runWebLogin(options) {
277-
buildAndStyleElements();
280+
buildAndStyleElements(options.styleCspNonce);
278281

279282
return openPopup(options);
280283
}

src/venmo/venmo.js

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22

33
var analytics = require("../lib/analytics");
4+
var assign = require("../lib/assign").assign;
45
var isBrowserSupported = require("./shared/supports-venmo");
56
var browserDetection = require("./shared/browser-detection");
67
var constants = require("./shared/constants");
@@ -82,6 +83,9 @@ function Venmo(options) {
8283
this._taxAmount = options.taxAmount;
8384
this._shippingAmount = options.shippingAmount;
8485
this._totalAmount = options.totalAmount;
86+
this._cspNonce =
87+
(this._mobileWebFallBack || this._allowDesktop) &&
88+
(options.styleCspNonce || false);
8589

8690
this._shouldCreateVenmoPaymentContext =
8791
this._cannotHaveReturnUrls || !this._shouldUseLegacyFlow;
@@ -605,7 +609,7 @@ Venmo.prototype.tokenize = function (options) {
605609
*
606610
* This is an alternate, opt-in flow to be used the Desktop QR Flow is not desired for Pay with Venmo desktop experiences.
607611
*/
608-
tokenizationPromise = this._tokenizeWebLoginWithRedirect();
612+
tokenizationPromise = this._tokenizeWebLoginWithRedirect(options);
609613
} else if (this._cannotHaveReturnUrls) {
610614
// in the manual return strategy, we create the payment
611615
// context on initialization, then continually poll once
@@ -719,23 +723,30 @@ Venmo.prototype.cancelTokenization = function () {
719723

720724
Venmo.prototype._tokenizeWebLoginWithRedirect = function () {
721725
var self = this;
726+
var webLoginOptions;
722727

723728
analytics.sendEvent(self._createPromise, "venmo.tokenize.web-login.start", {
724729
paypal_context_id: self._venmoPaymentContextId,
725730
});
726731
this._tokenizePromise = new ExtendedPromise();
727732

728733
return this.getUrl().then(function (url) {
734+
webLoginOptions = {
735+
checkForStatusChange:
736+
self._checkPaymentContextStatusAndProcessResult.bind(self),
737+
cancelTokenization: self.cancelTokenization.bind(self),
738+
frameServiceInstance: self._frameServiceInstance,
739+
venmoUrl: url,
740+
debug: self._isDebug,
741+
checkPaymentContextStatus: self._checkPaymentContextStatus.bind(self),
742+
};
743+
if (self._cspNonce) {
744+
webLoginOptions = assign({}, webLoginOptions, {
745+
styleCspNonce: self._cspNonce,
746+
});
747+
}
729748
desktopWebLogin
730-
.runWebLogin({
731-
checkForStatusChange:
732-
self._checkPaymentContextStatusAndProcessResult.bind(self),
733-
cancelTokenization: self.cancelTokenization.bind(self),
734-
frameServiceInstance: self._frameServiceInstance,
735-
venmoUrl: url,
736-
debug: self._isDebug,
737-
checkPaymentContextStatus: self._checkPaymentContextStatus.bind(self),
738-
})
749+
.runWebLogin(webLoginOptions)
739750
.then(function (payload) {
740751
analytics.sendEvent(
741752
self._createPromise,
@@ -1249,6 +1260,13 @@ Venmo.prototype.processHashChangeFlowResults = function (hash) {
12491260
}
12501261
);
12511262

1263+
if (window.popupBridge) {
1264+
analytics.sendEvent(
1265+
self._createPromise,
1266+
"popup-bridge:venmo:succeeded"
1267+
);
1268+
}
1269+
12521270
return resolve({
12531271
paymentMethodNonce: payload.paymentMethodId,
12541272
username: payload.userName,
@@ -1260,8 +1278,19 @@ Venmo.prototype.processHashChangeFlowResults = function (hash) {
12601278
if (
12611279
err.type === errors.VENMO_MOBILE_POLLING_TOKENIZATION_CANCELED.type
12621280
) {
1281+
if (window.popupBridge) {
1282+
analytics.sendEvent(
1283+
self._createPromise,
1284+
"popup-bridge:venmo:canceled"
1285+
);
1286+
}
12631287
// We want to reject in this case because if it the process was canceled, we don't want to take the happy path
12641288
reject(err);
1289+
} else if (window.popupBridge) {
1290+
analytics.sendEvent(
1291+
self._createPromise,
1292+
"popup-bridge:venmo:failed"
1293+
);
12651294
}
12661295

12671296
analytics.sendEvent(
@@ -1280,9 +1309,21 @@ Venmo.prototype.processHashChangeFlowResults = function (hash) {
12801309
"venmo.appswitch.handle.success"
12811310
);
12821311

1312+
if (window.popupBridge) {
1313+
analytics.sendEvent(
1314+
self._createPromise,
1315+
"popup-bridge:venmo:succeeded"
1316+
);
1317+
}
1318+
12831319
resolve(params);
12841320
} else if (params.venmoError) {
12851321
analytics.sendEvent(self._createPromise, "venmo.appswitch.handle.error");
1322+
1323+
if (window.popupBridge) {
1324+
analytics.sendEvent(self._createPromise, "popup-bridge:venmo:failed");
1325+
}
1326+
12861327
reject(
12871328
new BraintreeError({
12881329
type: errors.VENMO_APP_FAILED.type,
@@ -1298,6 +1339,11 @@ Venmo.prototype.processHashChangeFlowResults = function (hash) {
12981339
);
12991340
} else if (params.venmoCancel) {
13001341
analytics.sendEvent(self._createPromise, "venmo.appswitch.handle.cancel");
1342+
1343+
if (window.popupBridge) {
1344+
analytics.sendEvent(self._createPromise, "popup-bridge:venmo:canceled");
1345+
}
1346+
13011347
reject(new BraintreeError(errors.VENMO_APP_CANCELED));
13021348
} else {
13031349
// User has either manually switched back to browser, or app is not available for app switch

test/data-collector/unit/fraudnet.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ describe("FraudNet", () => {
2323
});
2424

2525
it("contains expected values in parsed data", async () => {
26-
const result = await fraudNet.setup({ sessionId: "fake-sessionID" });
26+
const testCallback = "testCallback";
27+
const result = await fraudNet.setup({
28+
sessionId: "fake-sessionID",
29+
cb1: testCallback,
30+
});
2731

2832
const sessionId = result.sessionId;
2933
const el = document.querySelector('[fncls][type="application/json"]');
@@ -32,6 +36,7 @@ describe("FraudNet", () => {
3236
expect(parsedData.b).toContain(sessionId);
3337
expect(parsedData.f).toBe(sessionId);
3438
expect(parsedData.s).toBe("BRAINTREE_SIGNIN");
39+
expect(parsedData.cb1).toBe(testCallback);
3540
expect(parsedData.sandbox).toBe(true);
3641
});
3742

0 commit comments

Comments
 (0)