Skip to content

Commit

Permalink
Release braintree-web 3.99.1 source
Browse files Browse the repository at this point in the history
Co-authored-by: Joe Plukarski <[email protected]>
  • Loading branch information
braintreeps committed Jan 26, 2024
1 parent f566a06 commit a6b3268
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 69 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

# 3.99.1

- Venmo
- Fix bug where the Venmo Desktop Popup would sometimes return a tokenization error when a customer canceled within the modal.
- Package updates
- Replace `tomashanacek/gulp-envify` with `ladjs/gulp-envify` due to missing dependency (`tomashanacek/loose-envify`).

# 3.99.0

- Venmo
Expand Down
41 changes: 13 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "braintree-web",
"version": "3.99.0",
"version": "3.99.1",
"license": "MIT",
"main": "src/index.js",
"private": true,
Expand Down Expand Up @@ -50,7 +50,7 @@
"eslint-config-braintree": "^5.0.1",
"eslint-config-prettier": "^8.5.0",
"gulp": "^4.0.2",
"gulp-envify": "tomashanacek/gulp-envify#37d97bca9073ec4161957c69d774f1870fdb6e57",
"@ladjs/gulp-envify": "^2.0.1",
"gulp-minifier": "^3.5.0",
"gulp-remove-code": "^3.0.2",
"gulp-rename": "^2.0.0",
Expand Down
20 changes: 19 additions & 1 deletion src/venmo/shared/web-login-backdrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
var frameService = require("../../lib/frame-service/external");
var useMin = require("../../lib/use-min");
var ExtendedPromise = require("@braintree/extended-promise");
var errors = require("../shared/errors");
var BraintreeError = require("../../lib/braintree-error");

var VERSION = process.env.npm_package_version;
var VENMO_LOGO_SVG =
Expand Down Expand Up @@ -30,6 +32,7 @@ function openPopup(options) {
var venmoUrl = options.venmoUrl;
var checkForStatusChange = options.checkForStatusChange;
var cancelTokenization = options.cancelTokenization;
var checkPaymentContextStatus = options.checkPaymentContextStatus;
var extendedPromise = new ExtendedPromise();

document
Expand All @@ -44,7 +47,6 @@ function openPopup(options) {
cancelTokenization();
closeBackdrop();
});

frameServiceInstance.open({}, function (frameServiceErr) {
var retryStartingCount = 1;

Expand All @@ -59,6 +61,22 @@ function openPopup(options) {
extendedPromise.reject(statusCheckError);
});
}

// We add this check here because at this point
// the status should not be in CREATED status.
// However, there is an edge case where if a buyer
// cancels in the popup, the popup might close itself
// before it can send the graphQL mutation to update its status.
// In these cases, the status will be stuck in CREATED status, and
// tokenization would fail, incorrectly throwing a tokenization error
// instead of informing the merchant that the customer canceled.
checkPaymentContextStatus().then(function (status) {
if (status === "CREATED") {
extendedPromise.reject(
new BraintreeError(errors.VENMO_CUSTOMER_CANCELED)
);
}
});
frameServiceInstance.close();
closeBackdrop();
});
Expand Down
83 changes: 46 additions & 37 deletions src/venmo/venmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ Venmo.prototype._tokenizeWebLoginWithRedirect = function () {
frameServiceInstance: self._frameServiceInstance,
venmoUrl: url,
debug: self._isDebug,
checkPaymentContextStatus: self._checkPaymentContextStatus.bind(self),
})
.then(function (payload) {
analytics.sendEvent(
Expand Down Expand Up @@ -786,6 +787,50 @@ Venmo.prototype._checkPaymentContextStatusAndProcessResult = function (
) {
var self = this;

return self._checkPaymentContextStatus().then(function (node) {
var resultStatus = node.status;

if (resultStatus !== self._venmoPaymentContextStatus) {
self._venmoPaymentContextStatus = resultStatus;

analytics.sendEvent(
self._createPromise,
"venmo.tokenize.web-login.status-change"
);

switch (resultStatus) {
case "APPROVED":
return Promise.resolve(node);
case "CANCELED":
return Promise.reject(
new BraintreeError(errors.VENMO_CUSTOMER_CANCELED)
);
case "FAILED":
return Promise.reject(
new BraintreeError(errors.VENMO_TOKENIZATION_FAILED)
);
default:
}
}

return new Promise(function (resolve, reject) {
if (retryCount < self._maxRetryCount) {
retryCount++;

return self
._checkPaymentContextStatusAndProcessResult(retryCount)
.then(resolve)
.catch(reject);
}

return reject(new BraintreeError(errors.VENMO_TOKENIZATION_FAILED));
});
});
};

Venmo.prototype._checkPaymentContextStatus = function () {
var self = this;

return self
._queryPaymentContextStatus(self._venmoPaymentContextId)
.catch(function (networkError) {
Expand All @@ -799,43 +844,7 @@ Venmo.prototype._checkPaymentContextStatusAndProcessResult = function (
);
})
.then(function (node) {
var resultStatus = node.status;

if (resultStatus !== self._venmoPaymentContextStatus) {
self._venmoPaymentContextStatus = resultStatus;

analytics.sendEvent(
self._createPromise,
"venmo.tokenize.web-login.status-change"
);

switch (resultStatus) {
case "APPROVED":
return Promise.resolve(node);
case "CANCELED":
return Promise.reject(
new BraintreeError(errors.VENMO_CUSTOMER_CANCELED)
);
case "FAILED":
return Promise.reject(
new BraintreeError(errors.VENMO_TOKENIZATION_FAILED)
);
default:
}
}

return new Promise(function (resolve, reject) {
if (retryCount < self._maxRetryCount) {
retryCount++;

return self
._checkPaymentContextStatusAndProcessResult(retryCount)
.then(resolve)
.catch(reject);
}

return reject(new BraintreeError(errors.VENMO_TOKENIZATION_FAILED));
});
return Promise.resolve(node);
});
};

Expand Down
2 changes: 1 addition & 1 deletion tasks/build.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

var gulp = require("gulp");
var envify = require("gulp-envify");
var envify = require("@ladjs/gulp-envify");
var rename = require("gulp-rename");
var removeCode = require("gulp-remove-code");
var replace = require("gulp-replace");
Expand Down
1 change: 1 addition & 0 deletions test/venmo/unit/venmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2952,6 +2952,7 @@ describe("Venmo", () => {
frameServiceInstance: expect.any(Object),
venmoUrl: expect.stringContaining(venmoConstants.VENMO_WEB_LOGIN_URL),
debug: testContext.configuration.isDebug,
checkPaymentContextStatus: expect.any(Function),
});
});

Expand Down
3 changes: 3 additions & 0 deletions test/venmo/unit/web-login-backdrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe("web-login-backdrop", () => {
classListAddMock,
classListRemoveMock,
setupOptions,
mockPaymentContextStatus,
openOptions;

beforeEach(() => {
Expand All @@ -40,6 +41,7 @@ describe("web-login-backdrop", () => {
mockClose = jest.fn();
mockCancelTokenization = jest.fn();
mockStatusCheck = jest.fn().mockResolvedValue();
mockPaymentContextStatus = jest.fn().mockResolvedValue();
classListAddMock = jest.fn();
eventListenerMock = jest.fn();
classListRemoveMock = jest.fn();
Expand Down Expand Up @@ -69,6 +71,7 @@ describe("web-login-backdrop", () => {
frameServiceInstance: mockFrameService,
cancelTokenization: mockCancelTokenization,
checkForStatusChange: mockStatusCheck,
checkPaymentContextStatus: mockPaymentContextStatus,
};
});

Expand Down

0 comments on commit a6b3268

Please sign in to comment.