Skip to content

Commit b5d4d09

Browse files
committed
Release braintree-web 3.107.0 source
1 parent e778fbc commit b5d4d09

File tree

15 files changed

+570
-34
lines changed

15 files changed

+570
-34
lines changed

CHANGELOG.md

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

3+
## 3.107.0
4+
5+
- Hosted Fields
6+
- Add support for passing through a sessionId value
7+
- PayPal Checkout
8+
- Enable option to pass through client-metadata-id
9+
- Fastlane
10+
- Add support for loading the Fastlane component in an AMD environment
11+
- Local Payment
12+
- Added Support for Local Payment `mbway` and `bancomatpay`
13+
314
## 3.106.0
415

516
- Fraudnet

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "braintree-web",
3-
"version": "3.106.0",
3+
"version": "3.107.0",
44
"license": "MIT",
55
"main": "src/index.js",
66
"private": true,
@@ -28,7 +28,7 @@
2828
"@braintree/sanitize-url": "7.0.4",
2929
"@braintree/uuid": "1.0.0",
3030
"@braintree/wrap-promise": "2.1.0",
31-
"@paypal/accelerated-checkout-loader": "1.0.1",
31+
"@paypal/accelerated-checkout-loader": "1.1.0",
3232
"card-validator": "10.0.0",
3333
"credit-card-type": "10.0.1",
3434
"framebus": "6.0.0",

scripts/release

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ release_source() {
123123
local CP_CMD="cp"
124124
if [[ "$(uname)"="Darwin" ]]; then
125125
# Coreutils version of cp supports --parents, mac default one doesn't
126-
CP_CMD="gcp"
126+
CP_CMD="cp"
127127
fi
128128

129-
git ls-files | egrep -v "$(join '|' $SOURCE_IGNORES)" | xargs cp --parents -t "$BRAINTREE_JS_SOURCE_DEST"
129+
git ls-files | egrep -v "$(join '|' $SOURCE_IGNORES)" | xargs "$CP_CMD" --parents -t "$BRAINTREE_JS_SOURCE_DEST"
130130
echo -e "Applied source changes in ${BLUE}$BRAINTREE_JS_SOURCE_DEST${RESET}."
131131
exit 0
132132
set -e

src/client/get-configuration.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ var isDateStringBeforeOrOn = require("../lib/is-date-string-before-or-on");
1212

1313
var BRAINTREE_VERSION = require("./constants").BRAINTREE_VERSION;
1414

15-
function getConfiguration(authData) {
15+
function getConfiguration(authData, inputSessionId) {
1616
return new Promise(function (resolve, reject) {
1717
var configuration, attrs, configUrl, reqOptions;
18-
var sessionId = uuid();
18+
var sessionId = inputSessionId || uuid();
1919
var analyticsMetadata = {
2020
merchantAppId: window.location.host,
2121
platform: constants.PLATFORM,

src/hosted-fields/external/hosted-fields.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,12 @@ function HostedFields(options) {
371371
var frameReadyPromiseResolveFunctions = {};
372372
var frameReadyPromises = [];
373373
var componentId = uuid();
374+
var sessionId = options.sessionId;
374375

375376
this._merchantConfigurationOptions = assign({}, options);
376377

377378
if (options.client) {
378-
clientConfig = options.client.getConfiguration();
379+
clientConfig = options.client.getConfiguration(undefined, sessionId); // eslint-disable-line no-undefined
379380
assetsUrl = clientConfig.gatewayConfiguration.assetsUrl;
380381
isDebug = clientConfig.isDebug;
381382
} else {
@@ -389,6 +390,7 @@ function HostedFields(options) {
389390
debug: isDebug,
390391
assetsUrl: assetsUrl,
391392
name: "Hosted Fields",
393+
sessionId: sessionId,
392394
});
393395

394396
hostedFieldsUrl = composeUrl(assetsUrl, componentId, isDebug);

src/hosted-fields/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ var VERSION = process.env.npm_package_version;
132132
* @param {styleOptions} [options.styles] {@link module:braintree-web/hosted-fields~styleOptions Styles} applied to each field.
133133
* @param {boolean} [options.preventAutofill=false] When true, browsers will not try to prompt the customer to autofill their credit card information.
134134
* @param {callback} [callback] The second argument, `data`, is the {@link HostedFields} instance. If no callback is provided, `create` returns a promise that resolves with the {@link HostedFields} instance.
135+
* @param {string} [options.sessionId] Used in specific cases where associating SDK events with a specific external id is required.
135136
* @returns {void}
136137
* @example
137138
* braintree.hostedFields.create({

src/lib/camel-case-to-snake-case.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,32 @@ function transformKey(key) {
88
.toLowerCase();
99
}
1010

11-
module.exports = function (obj) {
12-
return Object.keys(obj).reduce(function (newObj, key) {
13-
var transformedKey = transformKey(key);
11+
function camelCaseToSnakeCase(input) {
12+
var converted;
1413

15-
newObj[transformedKey] = obj[key];
14+
if (Array.isArray(input)) {
15+
converted = [];
1616

17-
return newObj;
18-
}, {});
19-
};
17+
input.forEach(function (x) {
18+
converted.push(camelCaseToSnakeCase(x));
19+
});
20+
} else if (typeof input === "object") {
21+
converted = Object.keys(input).reduce(function (newObj, key) {
22+
var transformedKey = transformKey(key);
23+
24+
if (typeof input[key] === "object") {
25+
newObj[transformedKey] = camelCaseToSnakeCase(input[key]);
26+
} else {
27+
newObj[transformedKey] = input[key];
28+
}
29+
30+
return newObj;
31+
}, {});
32+
} else {
33+
converted = input;
34+
}
35+
36+
return converted;
37+
}
38+
39+
module.exports = camelCaseToSnakeCase;

src/local-payment/external/local-payment.js

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,56 @@ LocalPayment.prototype._initialize = function () {
349349
* // Handle any error calling startPayment.
350350
* console.error(err);
351351
* });
352+
* @example <caption>MB WAY</caption>
353+
* localPaymentInstance.startPayment({
354+
* paymentType: 'mbway',
355+
* amount: '10.00',
356+
* currencyCode: 'EUR',
357+
* givenName: 'Joe',
358+
* surname: 'Doe',
359+
* phone: '1234566789',
360+
* phoneCountryCode: '351'
361+
* address: {
362+
* streetAddress: 'Rua Escura 12',
363+
* locality: 'Porto',
364+
* postalCode: '4465-283',
365+
* countryCode: 'PT',
366+
* },
367+
* onPaymentStart: function (data) {
368+
* // NOTE: It is critical here to store data.paymentId on your server
369+
* // so it can be mapped to a webhook sent by Braintree once the
370+
* // buyer completes their payment.
371+
* console.log('Payment ID:', data.paymentId);
372+
* },
373+
* }).catch(function (err) {
374+
* // Handle any error calling startPayment.
375+
* console.error(err);
376+
* });
377+
* @example <caption>BANCOMAT PAY</caption>
378+
* localPaymentInstance.startPayment({
379+
* paymentType: 'bancomatpay',
380+
* amount: '10.00',
381+
* currencyCode: 'EUR',
382+
* givenName: 'Joe',
383+
* surname: 'Doe',
384+
* phone: '1234566789',
385+
* phoneCountryCode: '49'
386+
* address: {
387+
* streetAddress: 'Via del Corso 12',
388+
* locality: 'Roma',
389+
* postalCode: '00100',
390+
* countryCode: 'IT',
391+
* },
392+
* onPaymentStart: function (data) {
393+
* // NOTE: It is critical here to store data.paymentId on your server
394+
* // so it can be mapped to a webhook sent by Braintree once the
395+
* // buyer completes their payment.
396+
* console.log('Payment ID:', data.paymentId);
397+
* },
398+
* }).catch(function (err) {
399+
* // Handle any error calling startPayment.
400+
* console.error(err);
401+
* });
352402
*/
353403
LocalPayment.prototype.startPayment = function (options) {
354404
var missingOption,
@@ -843,16 +893,14 @@ function isDeferredPaymentTypeOptions(options) {
843893
? options.paymentType.toLowerCase()
844894
: options.paymentType;
845895

846-
if (paymentType === "pay_upon_invoice") {
847-
return true;
848-
} else if (paymentType === "blik") {
896+
if (paymentType === "blik") {
849897
return (
850898
blikOptions.hasOwnProperty("level_0") ||
851899
blikOptions.hasOwnProperty("oneClick")
852900
);
853901
}
854902

855-
return false;
903+
return ["pay_upon_invoice", "mbway", "bancomatpay"].includes(paymentType);
856904
}
857905

858906
function hasMissingAddressOption(options) {

src/paypal-checkout/paypal-checkout.js

Lines changed: 108 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var methods = require("../lib/methods");
1616
var useMin = require("../lib/use-min");
1717
var convertMethodsToError = require("../lib/convert-methods-to-error");
1818
var querystring = require("../lib/querystring");
19+
var camelCaseToSnakeCase = require("../lib/camel-case-to-snake-case");
1920
var VERSION = process.env.npm_package_version;
2021
var INTEGRATION_TIMEOUT_MS = require("../lib/constants").INTEGRATION_TIMEOUT_MS;
2122

@@ -364,6 +365,36 @@ PayPalCheckout.prototype._setupFrameService = function (client) {
364365
* @property {string} amount.value The amount the shipping option will cost. Includes the specified number of digits after decimal separator for the ISO-4217 currency code.
365366
*/
366367

368+
/** @typedef {object} PayPalCheckout~pricingScheme
369+
* @property {string} pricingModel The pricing model. Options are `FIXED`, `VARIABLE`, or `AUTO_RELOAD`.
370+
* @property {string} price The price for the billing cycle.
371+
* @property {string} reloadThresholdAmount The amount at which to reload on auto_reload plans.
372+
*/
373+
374+
/**
375+
* @typedef {Object} PayPalCheckout~billingCycles
376+
* @property {(string|number)} billingFrequency The frequency of billing.
377+
* @property {string} billingFrequencyUnit The unit of billing frequency. Options are `DAY`, `WEEK`, `MONTH`, or `YEAR`.
378+
* @property {(string|number)} numberOfExecutions The number of executions for the billing cycle.
379+
* @property {(string|number)} sequence The order in the upcoming billing cycles.
380+
* @property {string} startDate The start date in ISO 8601 format (`2024-04-06T00:00:00Z`). If populated and the intent is to charge the buyer for the billing cycle at the checkout, it should be populated as current time in ISO 8601 format.
381+
* @property {boolean} trial Indicates if the billing cycle is a trial.
382+
* @property {pricingScheme} pricingScheme The {@link PayPalCheckout~pricingScheme|pricing scheme object} for this billing cycle.
383+
*/
384+
385+
/**
386+
* @typedef {Object} PayPalCheckout~planMetadata
387+
* @property {billingCycles[]} [billingCycles] An array of {@link PayPalCheckout~billingCycles|billing cyles} for this plan.
388+
* @property {string} currencyIsoCode The ISO code for the currency, for example `USD`.
389+
* @property {string} name The name of the plan.
390+
* @property {string} productDescription A description of the product. (Accepts only one element)
391+
* @property {(string|number)} productQuantity The quantity of the product. (Accepts only one element)
392+
* @property {(string|number)} oneTimeFeeAmount The one-time fee amount.
393+
* @property {(string|number)} shippingAmount The amount for shipping.
394+
* @property {(string|number)} productPrice The price of the product.
395+
* @property {(string|number)} taxAmount The amount of tax.
396+
*/
397+
367398
/**
368399
* Creates a PayPal payment ID or billing token using the given options. This is meant to be passed to the PayPal JS SDK.
369400
* When a {@link callback} is defined, the function returns undefined and invokes the callback with the id to be used with the PayPal JS SDK. Otherwise, it returns a Promise that resolves with the id.
@@ -400,6 +431,10 @@ PayPalCheckout.prototype._setupFrameService = function (client) {
400431
* * `login` - A PayPal account login page is used.
401432
* * `billing` - A non-PayPal account landing page is used.
402433
* @param {lineItem[]} [options.lineItems] The {@link PayPalCheckout~lineItem|line items} for this transaction. It can include up to 249 line items.
434+
*
435+
* @param {string} [options.planType] Determines the charge pattern for the Recurring Billing Agreement. Can be 'RECURRING', 'SUBSCRIPTION', 'UNSCHEDULED', or 'INSTALLMENTS'.
436+
* @param {planMetadata} [options.planMetadata] When plan type is defined, allows for {@link PayPalCheckout~planMetadata|plan metadata} to be set for the Billing Agreement.
437+
*
403438
* @param {callback} [callback] The second argument is a PayPal `paymentId` or `billingToken` string, depending on whether `options.flow` is `checkout` or `vault`. This is also what is resolved by the promise if no callback is provided.
404439
* @example
405440
* // this paypal object is created by the PayPal JS SDK
@@ -479,9 +514,65 @@ PayPalCheckout.prototype._setupFrameService = function (client) {
479514
* }).catch(function (err) {
480515
* console.error('Error!', err);
481516
* });
517+
*
482518
* ```
483519
*
484-
* @returns {(Promise|void)} Returns a promise if no callback is provided.
520+
* @example <caption>use the new plan features</caption>
521+
* // Plan and plan metadata are passed to createPayment
522+
* ```javascript
523+
* braintree.client.create({
524+
* authorization: 'authorization'
525+
* }).then(function (clientInstance) {
526+
* return braintree.paypalCheckout.create({
527+
* client: clientInstance
528+
* });
529+
* }).then(function (paypalCheckoutInstance) {
530+
* return paypal.Button.render({
531+
* env: 'production'
532+
*
533+
* payment: function () {
534+
* return paypalCheckoutInstance.createPayment({
535+
* flow: 'vault',
536+
* planType: 'RECURRING',
537+
* planMetadata: {
538+
* billingCycles: [
539+
* {
540+
* billingFrequency: "1",
541+
* billingFrequencyUnit: "MONTH",
542+
* numberOfExecutions: "1",
543+
* sequence: "1",
544+
* startDate: "2024-04-06T00:00:00Z",
545+
* trial: true,
546+
* pricingScheme: {
547+
* pricingModel: "FIXED",
548+
* },
549+
* },
550+
* ],
551+
* currencyIsoCode: "USD",
552+
* name: "Netflix with Ads",
553+
* productDescription: "iPhone 13",
554+
* productQuantity: "1.0",
555+
* oneTimeFeeAmount: "10",
556+
* shippingAmount: "3.0",
557+
* productPrice: "200",
558+
* taxAmount: "20",
559+
* };
560+
* });
561+
* },
562+
*
563+
* onAuthorize: function (data, actions) {
564+
* return paypalCheckoutInstance.tokenizePayment(data).then(function (payload) {
565+
* // Submit payload.nonce to your server
566+
* });
567+
* }
568+
* }, '#paypal-button');
569+
* }).catch(function (err) {
570+
* console.error('Error!', err);
571+
* });
572+
*
573+
* ```
574+
*
575+
* @returns {(promise|void)} returns a promise if no callback is provided.
485576
*/
486577
PayPalCheckout.prototype.createPayment = function (options) {
487578
if (!options || !constants.FLOW_ENDPOINTS.hasOwnProperty(options.flow)) {
@@ -1199,8 +1290,9 @@ PayPalCheckout.prototype.loadPayPalSDK = function (options) {
11991290
dataAttributes["user-id-token"] || dataAttributes["data-user-id-token"];
12001291

12011292
if (this._configuration) {
1202-
dataAttributes["client-metadata-id"] =
1203-
this._configuration.analyticsMetadata.sessionId;
1293+
dataAttributes["client-metadata-id"] = dataAttributes["client-metadata-id"]
1294+
? dataAttributes["client-metadata-id"]
1295+
: this._configuration.analyticsMetadata.sessionId;
12041296
}
12051297

12061298
if (!userIdToken) {
@@ -1383,11 +1475,24 @@ PayPalCheckout.prototype._formatPaymentResourceData = function (
13831475
paymentResource.billingAgreementDetails = options.billingAgreementDetails;
13841476
}
13851477
} else {
1478+
// NOTE: This flow is "vault"
13861479
paymentResource.shippingAddress = options.shippingAddressOverride;
13871480

13881481
if (options.billingAgreementDescription) {
13891482
paymentResource.description = options.billingAgreementDescription;
13901483
}
1484+
1485+
if (options.planType) {
1486+
/* eslint-disable camelcase */
1487+
paymentResource.plan_type = options.planType;
1488+
1489+
if (options.planMetadata) {
1490+
paymentResource.plan_metadata = camelCaseToSnakeCase(
1491+
options.planMetadata
1492+
);
1493+
}
1494+
/* eslint-enable camelcase */
1495+
}
13911496
}
13921497

13931498
// this needs to be set outside of the block where add it to the

0 commit comments

Comments
 (0)