Skip to content

Commit

Permalink
3.23.0
Browse files Browse the repository at this point in the history
Co-authored-by: Timothy Martinak <timothy.martinak@getbraintree.com>
Co-authored-by: Sara Vasquez <saravasquez@paypal.com>
  • Loading branch information
3 people committed Mar 26, 2024
1 parent 8947c04 commit e3aa86d
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,10 @@
# Changelog

## 3.23.0

- Add `domains` parameter support to `ClientToken.generate`
- Refactor key validation in `ClientTokenGateway`

## 3.22.0

- Add `UnderReview` to `Dispute.Status`
Expand Down
7 changes: 5 additions & 2 deletions lib/braintree/client_token_gateway.js
Expand Up @@ -24,10 +24,10 @@ class ClientTokenGateway extends Gateway {
params.version = DEFAULT_VERSION;
}

err = Util.verifyKeys(this._generateSignature(), params);
err = this.validateParams(params);

if (!err) {
err = this.validateParams(params);
err = Util.verifyKeys(this._generateSignature(), params);
}

if (err) {
Expand All @@ -51,6 +51,8 @@ class ClientTokenGateway extends Gateway {
.map((name) => name);

if (invalidOptions.length > 0) {
// NEXT_MAJOR_VERSION change UnexpectedError to InvalidKeysError
// InvalidKeysError is more codebase consistent and makes more contextual sense
// eslint-disable-next-line consistent-return, new-cap
return exceptions.UnexpectedError(
`A customer id is required for the following options: ${invalidOptions.join(
Expand Down Expand Up @@ -91,6 +93,7 @@ class ClientTokenGateway extends Gateway {
"options[verifyCard]",
"options[failOnDuplicatePaymentMethod]",
],
ignore: ["domains"],
};
}
}
Expand Down
6 changes: 4 additions & 2 deletions lib/braintree/validation_error_codes.js
Expand Up @@ -72,11 +72,13 @@ class ValidationErrorCodes {
this.ClientToken = {
CustomerDoesNotExist: "92804",
FailOnDuplicatePaymentMethodRequiresCustomerId: "92803",
InvalidDomainFormat: "92011",
MakeDefaultRequiresCustomerId: "92801",
ProxyMerchantDoesNotExist: "92805",
VerifyCardRequiresCustomerId: "92802",
MerchantAccountDoesNotExist: "92807",
ProxyMerchantDoesNotExist: "92805",
TooManyDomains: "92810",
UnsupportedVersion: "92806",
VerifyCardRequiresCustomerId: "92802",
};

this.CreditCard = {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "braintree",
"version": "3.22.0",
"version": "3.23.0",
"description": "A library for server-side integrating with Braintree.",
"keywords": [
"braintree",
Expand Down
64 changes: 64 additions & 0 deletions test/integration/braintree/client_token_gateway_spec.js
Expand Up @@ -261,6 +261,70 @@ describe("ClientTokenGateway", function () {
);
});

it("can pass domains", function (done) {
let expectedDomains = ["example.com"];
let clientTokenParams = {
domains: expectedDomains,
};

specHelper.defaultGateway.clientToken.generate(
clientTokenParams,
function (err, result) {
assert.isTrue(result.success);
let clientToken = JSON.parse(
specHelper.decodeClientToken(result.clientToken)
);

let authFingerprintPayload = Buffer.from(
clientToken.authorizationFingerprint,
"base64"
).toString("utf8");

expectedDomains.forEach((domain) => {
assert.isTrue(authFingerprintPayload.includes(domain));
});
done();
}
);
});

it("calls callback with an error when an invalid domain is supplied", (done) =>
specHelper.defaultGateway.clientToken.generate(
{
domains: ["example"],
},
function (err, result) {
assert.isFalse(result.success);
assert.equal(
result.message,
"Client token domains must be valid domain names (RFC 1035), e.g. example.com"
);
done();
}
));

it("calls callback with an error when too many domains are supplied", (done) =>
specHelper.defaultGateway.clientToken.generate(
{
domains: [
"example1.com",
"example2.com",
"example3.com",
"example4.com",
"example5.com",
"example6.com",
],
},
function (err, result) {
assert.isFalse(result.success);
assert.equal(
result.message,
"Cannot specify more than 5 client token domains"
);
done();
}
));

it("calls callback with an error when an invalid parameter is supplied", (done) =>
specHelper.defaultGateway.clientToken.generate(
{
Expand Down
19 changes: 17 additions & 2 deletions test/unit/braintree/client_token_gateway_spec.js
Expand Up @@ -3,7 +3,7 @@
let braintree = specHelper.braintree;

describe("ClientTokenGateway", () =>
describe("generate", () =>
describe("generate", () => {
it("returns an error when credit card options are supplied without a customer ID", function (done) {
specHelper.defaultGateway.clientToken.generate(
{
Expand All @@ -18,4 +18,19 @@ describe("ClientTokenGateway", () =>
done();
}
);
})));
});

it("does not return an error when the domains option is supplied", function (done) {
specHelper.defaultGateway.clientToken.generate(
{
domains: ["example.com"],
},
function (err, response) {
assert.equal(err, null);
assert.typeOf(response, "object");
assert.typeOf(response.clientToken, "string");
done();
}
);
});
}));

0 comments on commit e3aa86d

Please sign in to comment.