From fd61c467e9a9f6964922cf80597bf096ddca1552 Mon Sep 17 00:00:00 2001 From: Braintree Date: Tue, 19 Nov 2024 13:21:22 -0600 Subject: [PATCH] Release braintree-web 3.112.1 source --- CHANGELOG.md | 5 +++++ package-lock.json | 4 ++-- package.json | 2 +- src/lib/url-params.js | 11 +++++++++++ src/venmo/venmo.js | 6 ++++++ test/venmo/unit/venmo.js | 13 +++++++++++++ 6 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 src/lib/url-params.js diff --git a/CHANGELOG.md b/CHANGELOG.md index d18a4846..5eea10c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## 3.112.1 + +- Venmo + - Fix a bug where, after redirecting in the mobile web flow, we were passing in a null context ID to a graphql API call. The fix is to set the Venmo instance's venmoPaymentContextId based on resource_id in url. + ## 3.112.0 - Local Payment diff --git a/package-lock.json b/package-lock.json index 67807f54..457901fc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "braintree-web", - "version": "3.112.0", + "version": "3.112.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "braintree-web", - "version": "3.112.0", + "version": "3.112.1", "license": "MIT", "dependencies": { "@braintree/asset-loader": "2.0.1", diff --git a/package.json b/package.json index 892e5e11..fbffbe61 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "braintree-web", - "version": "3.112.0", + "version": "3.112.1", "license": "MIT", "main": "src/index.js", "private": true, diff --git a/src/lib/url-params.js b/src/lib/url-params.js new file mode 100644 index 00000000..919b4d8c --- /dev/null +++ b/src/lib/url-params.js @@ -0,0 +1,11 @@ +"use strict"; + +var querystring = require("./querystring"); + +function getUrlParams() { + return querystring.parse(window.location.href); +} + +module.exports = { + getUrlParams: getUrlParams, +}; diff --git a/src/venmo/venmo.js b/src/venmo/venmo.js index fc807593..0c5c0d65 100644 --- a/src/venmo/venmo.js +++ b/src/venmo/venmo.js @@ -16,6 +16,7 @@ var ExtendedPromise = require("@braintree/extended-promise"); var getVenmoUrl = require("./shared/get-venmo-url"); var desktopWebLogin = require("./shared/web-login-backdrop"); var snakeCaseToCamelCase = require("../lib/snake-case-to-camel-case"); +var urlParams = require("../lib/url-params"); // NEXT_MAJOR_VERSION the source code for this is actually in a // typescript repo called venmo-desktop, once the SDK is migrated @@ -503,6 +504,11 @@ Venmo.prototype.hasTokenizationResult = function () { // when listening on a hashchange event Venmo.prototype._hasTokenizationResult = function (hash) { var params = getFragmentParameters(hash); + var paramsFromUrl = urlParams.getUrlParams(); + + if (paramsFromUrl.resource_id) { + this._venmoPaymentContextId = paramsFromUrl.resource_id; + } return ( typeof (params.venmoSuccess || params.venmoError || params.venmoCancel) !== diff --git a/test/venmo/unit/venmo.js b/test/venmo/unit/venmo.js index b714546b..30544db0 100644 --- a/test/venmo/unit/venmo.js +++ b/test/venmo/unit/venmo.js @@ -5,6 +5,7 @@ jest.mock("../../../src/venmo/shared/supports-venmo"); jest.mock("../../../src/venmo/external"); jest.mock("../../../src/lib/in-iframe"); jest.mock("../../../src/venmo/shared/web-login-backdrop"); +jest.mock("../../../src/lib/url-params"); const analytics = require("../../../src/lib/analytics"); const { fake } = require("../../helpers"); @@ -23,6 +24,7 @@ const { setupDesktopWebLogin, } = require("../../../src/venmo/shared/web-login-backdrop"); const venmoConstants = require("../../../src/venmo/shared/constants"); +const urlParams = require("../../../src/lib/url-params"); function triggerVisibilityHandler(instance, runAllTimers = true) { // TODO we should have it trigger the actual @@ -55,6 +57,7 @@ describe("Venmo", () => { beforeAll(() => { window.open = jest.fn(); originalLocationHref = window.location.href; + urlParams.getUrlParams.mockReturnValue({}); }); beforeEach(() => { @@ -2008,6 +2011,16 @@ describe("Venmo", () => { it("returns false when URL has no Venmo payload", () => { expect(venmo.hasTokenizationResult()).toBe(false); }); + + it("sets the _venmoPaymentContextId from the resource_id", () => { + urlParams.getUrlParams.mockReturnValue({ + resource_id: "test-resource-id", // eslint-disable-line camelcase + }); + + venmo.hasTokenizationResult(); + + expect(venmo._venmoPaymentContextId).toBe("test-resource-id"); + }); }); describe("tokenize", () => {