A suite of tools for integrating Braintree in the browser
Installations
npm install braintree-web
Score
89.5
Supply Chain
99
Quality
92.2
Maintenance
100
Vulnerability
98.6
License
Developer
Developer Guide
Module System
CommonJS, UMD
Min. Node Version
Typescript Support
No
Node Version
20.17.0
NPM Version
10.8.2
Statistics
444 Stars
288 Commits
134 Forks
119 Watching
15 Branches
75 Contributors
Updated on 19 Nov 2024
Bundle Size
324.73 kB
Minified
77.93 kB
Minified + Gzipped
Languages
JavaScript (98.97%)
HTML (0.7%)
Shell (0.33%)
Total Downloads
Cumulative downloads
Total Downloads
53,060,084
Last day
-13.8%
57,437
Compared to previous day
Last week
2.5%
301,983
Compared to previous week
Last month
22.8%
1,319,040
Compared to previous month
Last year
37.7%
12,592,288
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
15
braintree-web
A suite of tools for integrating Braintree in the browser.
This is the repo to submit issues if you have any problems or questions about a Braintree JavaScript integration.
For a ready-made payment UI, see Braintree Web Drop-in.
Install
npm install braintree-web
bower install braintree-web
Usage
For more thorough documentation, visit the JavaScript client SDK docs.
If you are upgrading from version 2.x, take a look at our migration guide.
Hosted Fields integration
1<form action="/" id="my-sample-form"> 2 <input type="hidden" name="payment_method_nonce" /> 3 <label for="card-number">Card Number</label> 4 <div id="card-number"></div> 5 6 <label for="cvv">CVV</label> 7 <div id="cvv"></div> 8 9 <label for="expiration-date">Expiration Date</label> 10 <div id="expiration-date"></div> 11 12 <input id="my-submit" type="submit" value="Pay" disabled /> 13</form>
1var submitBtn = document.getElementById("my-submit"); 2var form = document.getElementById("my-sample-form"); 3 4braintree.client.create( 5 { 6 authorization: CLIENT_AUTHORIZATION, 7 }, 8 clientDidCreate 9); 10 11function clientDidCreate(err, client) { 12 braintree.hostedFields.create( 13 { 14 client: client, 15 styles: { 16 input: { 17 "font-size": "16pt", 18 color: "#3A3A3A", 19 }, 20 21 ".number": { 22 "font-family": "monospace", 23 }, 24 25 ".valid": { 26 color: "green", 27 }, 28 }, 29 fields: { 30 number: { 31 selector: "#card-number", 32 }, 33 cvv: { 34 selector: "#cvv", 35 }, 36 expirationDate: { 37 selector: "#expiration-date", 38 }, 39 }, 40 }, 41 hostedFieldsDidCreate 42 ); 43} 44 45function hostedFieldsDidCreate(err, hostedFields) { 46 submitBtn.addEventListener("click", submitHandler.bind(null, hostedFields)); 47 submitBtn.removeAttribute("disabled"); 48} 49 50function submitHandler(hostedFields, event) { 51 event.preventDefault(); 52 submitBtn.setAttribute("disabled", "disabled"); 53 54 hostedFields.tokenize(function (err, payload) { 55 if (err) { 56 submitBtn.removeAttribute("disabled"); 57 console.error(err); 58 } else { 59 form["payment_method_nonce"].value = payload.nonce; 60 form.submit(); 61 } 62 }); 63}
Advanced integration
To be eligible for the easiest level of PCI compliance (SAQ A), payment fields cannot be hosted on your checkout page. For an alternative to the following, use Hosted Fields.
1braintree.client.create( 2 { 3 authorization: CLIENT_AUTHORIZATION, 4 }, 5 function (err, client) { 6 client.request( 7 { 8 endpoint: "payment_methods/credit_cards", 9 method: "post", 10 data: { 11 creditCard: { 12 number: "4111111111111111", 13 expirationDate: "10/20", 14 cvv: "123", 15 billingAddress: { 16 postalCode: "12345", 17 }, 18 }, 19 }, 20 }, 21 function (err, response) { 22 // Send response.creditCards[0].nonce to your server 23 } 24 ); 25 } 26);
For more examples, see the reference.
Promises
All the asynchronous methods will return a Promise
if no callback is provided.
1var submitBtn = document.getElementById("my-submit"); 2var yourStylesConfig = { 3 /* your Hosted Fields `styles` config */ 4}; 5var yourFieldsConfig = { 6 /* your Hosted Hields `fields` config */ 7}; 8 9braintree.client 10 .create({ authorization: CLIENT_AUTHORIZATION }) 11 .then(function (client) { 12 return braintree.hostedFields.create({ 13 client: client, 14 styles: yourStylesConfig, 15 fields: yourFieldsConfig, 16 }); 17 }) 18 .then(function (hostedFields) { 19 submitBtn.addEventListener("click", function (event) { 20 event.preventDefault(); 21 submitBtn.setAttribute("disabled", "disabled"); 22 23 hostedFields 24 .tokenize() 25 .then(function (payload) { 26 // send payload.nonce to your server 27 }) 28 .catch(function (err) { 29 submitBtn.removeAttribute("disabled"); 30 console.error(err); 31 }); 32 }); 33 });
Releases
Subscribe to this repo to be notified when SDK releases go out.
Versions
This SDK abides by our Client SDK Deprecation Policy. For more information on the potential statuses of an SDK check our developer docs.
Major version number | Status | Released | Deprecated | Unsupported |
---|---|---|---|---|
3.x.x | Active | August 2016 | TBA | TBA |
2.x.x | Unsupported | November 2014 | February 2022 | February 2023 |
License
The Braintree JavaScript SDK is open source and available under the MIT license. See the LICENSE file for more info.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
9 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 7
Reason
4 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-mxhp-79qh-mcx6
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: npmCommand not pinned by hash: scripts/release:89
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Score
3.6
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to braintree-web
@types/braintree-web
TypeScript definitions for braintree-web
@types/braintree-web-drop-in
TypeScript definitions for braintree-web-drop-in
braintree-web-drop-in
[![Build Status](https://github.com/braintree/braintree-web-drop-in/workflows/Unit%20Tests/badge.svg)](https://github.com/braintree/braintree-web-drop-in/actions?query=workflow%3A%22Unit+Tests%22) [![Build Status](https://github.com/braintree/braintree-we
braintree-web-drop-in-react
React component for Braintree Web Drop-In (v3)