Skip to content

Commit

Permalink
Release braintree-web 3.107.0 source
Browse files Browse the repository at this point in the history
  • Loading branch information
CJGlitter committed Sep 6, 2024
1 parent e778fbc commit b5d4d09
Show file tree
Hide file tree
Showing 15 changed files with 570 additions and 34 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# CHANGELOG

## 3.107.0

- Hosted Fields
- Add support for passing through a sessionId value
- PayPal Checkout
- Enable option to pass through client-metadata-id
- Fastlane
- Add support for loading the Fastlane component in an AMD environment
- Local Payment
- Added Support for Local Payment `mbway` and `bancomatpay`

## 3.106.0

- Fraudnet
Expand Down
8 changes: 4 additions & 4 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.106.0",
"version": "3.107.0",
"license": "MIT",
"main": "src/index.js",
"private": true,
Expand Down Expand Up @@ -28,7 +28,7 @@
"@braintree/sanitize-url": "7.0.4",
"@braintree/uuid": "1.0.0",
"@braintree/wrap-promise": "2.1.0",
"@paypal/accelerated-checkout-loader": "1.0.1",
"@paypal/accelerated-checkout-loader": "1.1.0",
"card-validator": "10.0.0",
"credit-card-type": "10.0.1",
"framebus": "6.0.0",
Expand Down
4 changes: 2 additions & 2 deletions scripts/release
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ release_source() {
local CP_CMD="cp"
if [[ "$(uname)"="Darwin" ]]; then
# Coreutils version of cp supports --parents, mac default one doesn't
CP_CMD="gcp"
CP_CMD="cp"
fi

git ls-files | egrep -v "$(join '|' $SOURCE_IGNORES)" | xargs cp --parents -t "$BRAINTREE_JS_SOURCE_DEST"
git ls-files | egrep -v "$(join '|' $SOURCE_IGNORES)" | xargs "$CP_CMD" --parents -t "$BRAINTREE_JS_SOURCE_DEST"
echo -e "Applied source changes in ${BLUE}$BRAINTREE_JS_SOURCE_DEST${RESET}."
exit 0
set -e
Expand Down
4 changes: 2 additions & 2 deletions src/client/get-configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ var isDateStringBeforeOrOn = require("../lib/is-date-string-before-or-on");

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

function getConfiguration(authData) {
function getConfiguration(authData, inputSessionId) {
return new Promise(function (resolve, reject) {
var configuration, attrs, configUrl, reqOptions;
var sessionId = uuid();
var sessionId = inputSessionId || uuid();
var analyticsMetadata = {
merchantAppId: window.location.host,
platform: constants.PLATFORM,
Expand Down
4 changes: 3 additions & 1 deletion src/hosted-fields/external/hosted-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,12 @@ function HostedFields(options) {
var frameReadyPromiseResolveFunctions = {};
var frameReadyPromises = [];
var componentId = uuid();
var sessionId = options.sessionId;

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

if (options.client) {
clientConfig = options.client.getConfiguration();
clientConfig = options.client.getConfiguration(undefined, sessionId); // eslint-disable-line no-undefined
assetsUrl = clientConfig.gatewayConfiguration.assetsUrl;
isDebug = clientConfig.isDebug;
} else {
Expand All @@ -389,6 +390,7 @@ function HostedFields(options) {
debug: isDebug,
assetsUrl: assetsUrl,
name: "Hosted Fields",
sessionId: sessionId,
});

hostedFieldsUrl = composeUrl(assetsUrl, componentId, isDebug);
Expand Down
1 change: 1 addition & 0 deletions src/hosted-fields/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ var VERSION = process.env.npm_package_version;
* @param {styleOptions} [options.styles] {@link module:braintree-web/hosted-fields~styleOptions Styles} applied to each field.
* @param {boolean} [options.preventAutofill=false] When true, browsers will not try to prompt the customer to autofill their credit card information.
* @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.
* @param {string} [options.sessionId] Used in specific cases where associating SDK events with a specific external id is required.
* @returns {void}
* @example
* braintree.hostedFields.create({
Expand Down
34 changes: 27 additions & 7 deletions src/lib/camel-case-to-snake-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,32 @@ function transformKey(key) {
.toLowerCase();
}

module.exports = function (obj) {
return Object.keys(obj).reduce(function (newObj, key) {
var transformedKey = transformKey(key);
function camelCaseToSnakeCase(input) {
var converted;

newObj[transformedKey] = obj[key];
if (Array.isArray(input)) {
converted = [];

return newObj;
}, {});
};
input.forEach(function (x) {
converted.push(camelCaseToSnakeCase(x));
});
} else if (typeof input === "object") {
converted = Object.keys(input).reduce(function (newObj, key) {
var transformedKey = transformKey(key);

if (typeof input[key] === "object") {
newObj[transformedKey] = camelCaseToSnakeCase(input[key]);
} else {
newObj[transformedKey] = input[key];
}

return newObj;
}, {});
} else {
converted = input;
}

return converted;
}

module.exports = camelCaseToSnakeCase;
56 changes: 52 additions & 4 deletions src/local-payment/external/local-payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,56 @@ LocalPayment.prototype._initialize = function () {
* // Handle any error calling startPayment.
* console.error(err);
* });
* @example <caption>MB WAY</caption>
* localPaymentInstance.startPayment({
* paymentType: 'mbway',
* amount: '10.00',
* currencyCode: 'EUR',
* givenName: 'Joe',
* surname: 'Doe',
* phone: '1234566789',
* phoneCountryCode: '351'
* address: {
* streetAddress: 'Rua Escura 12',
* locality: 'Porto',
* postalCode: '4465-283',
* countryCode: 'PT',
* },
* onPaymentStart: function (data) {
* // NOTE: It is critical here to store data.paymentId on your server
* // so it can be mapped to a webhook sent by Braintree once the
* // buyer completes their payment.
* console.log('Payment ID:', data.paymentId);
* },
* }).catch(function (err) {
* // Handle any error calling startPayment.
* console.error(err);
* });
* @example <caption>BANCOMAT PAY</caption>
* localPaymentInstance.startPayment({
* paymentType: 'bancomatpay',
* amount: '10.00',
* currencyCode: 'EUR',
* givenName: 'Joe',
* surname: 'Doe',
* phone: '1234566789',
* phoneCountryCode: '49'
* address: {
* streetAddress: 'Via del Corso 12',
* locality: 'Roma',
* postalCode: '00100',
* countryCode: 'IT',
* },
* onPaymentStart: function (data) {
* // NOTE: It is critical here to store data.paymentId on your server
* // so it can be mapped to a webhook sent by Braintree once the
* // buyer completes their payment.
* console.log('Payment ID:', data.paymentId);
* },
* }).catch(function (err) {
* // Handle any error calling startPayment.
* console.error(err);
* });
*/
LocalPayment.prototype.startPayment = function (options) {
var missingOption,
Expand Down Expand Up @@ -843,16 +893,14 @@ function isDeferredPaymentTypeOptions(options) {
? options.paymentType.toLowerCase()
: options.paymentType;

if (paymentType === "pay_upon_invoice") {
return true;
} else if (paymentType === "blik") {
if (paymentType === "blik") {
return (
blikOptions.hasOwnProperty("level_0") ||
blikOptions.hasOwnProperty("oneClick")
);
}

return false;
return ["pay_upon_invoice", "mbway", "bancomatpay"].includes(paymentType);
}

function hasMissingAddressOption(options) {
Expand Down
111 changes: 108 additions & 3 deletions src/paypal-checkout/paypal-checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var methods = require("../lib/methods");
var useMin = require("../lib/use-min");
var convertMethodsToError = require("../lib/convert-methods-to-error");
var querystring = require("../lib/querystring");
var camelCaseToSnakeCase = require("../lib/camel-case-to-snake-case");
var VERSION = process.env.npm_package_version;
var INTEGRATION_TIMEOUT_MS = require("../lib/constants").INTEGRATION_TIMEOUT_MS;

Expand Down Expand Up @@ -364,6 +365,36 @@ PayPalCheckout.prototype._setupFrameService = function (client) {
* @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.
*/

/** @typedef {object} PayPalCheckout~pricingScheme
* @property {string} pricingModel The pricing model. Options are `FIXED`, `VARIABLE`, or `AUTO_RELOAD`.
* @property {string} price The price for the billing cycle.
* @property {string} reloadThresholdAmount The amount at which to reload on auto_reload plans.
*/

/**
* @typedef {Object} PayPalCheckout~billingCycles
* @property {(string|number)} billingFrequency The frequency of billing.
* @property {string} billingFrequencyUnit The unit of billing frequency. Options are `DAY`, `WEEK`, `MONTH`, or `YEAR`.
* @property {(string|number)} numberOfExecutions The number of executions for the billing cycle.
* @property {(string|number)} sequence The order in the upcoming billing cycles.
* @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.
* @property {boolean} trial Indicates if the billing cycle is a trial.
* @property {pricingScheme} pricingScheme The {@link PayPalCheckout~pricingScheme|pricing scheme object} for this billing cycle.
*/

/**
* @typedef {Object} PayPalCheckout~planMetadata
* @property {billingCycles[]} [billingCycles] An array of {@link PayPalCheckout~billingCycles|billing cyles} for this plan.
* @property {string} currencyIsoCode The ISO code for the currency, for example `USD`.
* @property {string} name The name of the plan.
* @property {string} productDescription A description of the product. (Accepts only one element)
* @property {(string|number)} productQuantity The quantity of the product. (Accepts only one element)
* @property {(string|number)} oneTimeFeeAmount The one-time fee amount.
* @property {(string|number)} shippingAmount The amount for shipping.
* @property {(string|number)} productPrice The price of the product.
* @property {(string|number)} taxAmount The amount of tax.
*/

/**
* Creates a PayPal payment ID or billing token using the given options. This is meant to be passed to the PayPal JS SDK.
* 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.
Expand Down Expand Up @@ -400,6 +431,10 @@ PayPalCheckout.prototype._setupFrameService = function (client) {
* * `login` - A PayPal account login page is used.
* * `billing` - A non-PayPal account landing page is used.
* @param {lineItem[]} [options.lineItems] The {@link PayPalCheckout~lineItem|line items} for this transaction. It can include up to 249 line items.
*
* @param {string} [options.planType] Determines the charge pattern for the Recurring Billing Agreement. Can be 'RECURRING', 'SUBSCRIPTION', 'UNSCHEDULED', or 'INSTALLMENTS'.
* @param {planMetadata} [options.planMetadata] When plan type is defined, allows for {@link PayPalCheckout~planMetadata|plan metadata} to be set for the Billing Agreement.
*
* @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.
* @example
* // this paypal object is created by the PayPal JS SDK
Expand Down Expand Up @@ -479,9 +514,65 @@ PayPalCheckout.prototype._setupFrameService = function (client) {
* }).catch(function (err) {
* console.error('Error!', err);
* });
*
* ```
*
* @returns {(Promise|void)} Returns a promise if no callback is provided.
* @example <caption>use the new plan features</caption>
* // Plan and plan metadata are passed to createPayment
* ```javascript
* braintree.client.create({
* authorization: 'authorization'
* }).then(function (clientInstance) {
* return braintree.paypalCheckout.create({
* client: clientInstance
* });
* }).then(function (paypalCheckoutInstance) {
* return paypal.Button.render({
* env: 'production'
*
* payment: function () {
* return paypalCheckoutInstance.createPayment({
* flow: 'vault',
* planType: 'RECURRING',
* planMetadata: {
* billingCycles: [
* {
* billingFrequency: "1",
* billingFrequencyUnit: "MONTH",
* numberOfExecutions: "1",
* sequence: "1",
* startDate: "2024-04-06T00:00:00Z",
* trial: true,
* pricingScheme: {
* pricingModel: "FIXED",
* },
* },
* ],
* currencyIsoCode: "USD",
* name: "Netflix with Ads",
* productDescription: "iPhone 13",
* productQuantity: "1.0",
* oneTimeFeeAmount: "10",
* shippingAmount: "3.0",
* productPrice: "200",
* taxAmount: "20",
* };
* });
* },
*
* onAuthorize: function (data, actions) {
* return paypalCheckoutInstance.tokenizePayment(data).then(function (payload) {
* // Submit payload.nonce to your server
* });
* }
* }, '#paypal-button');
* }).catch(function (err) {
* console.error('Error!', err);
* });
*
* ```
*
* @returns {(promise|void)} returns a promise if no callback is provided.
*/
PayPalCheckout.prototype.createPayment = function (options) {
if (!options || !constants.FLOW_ENDPOINTS.hasOwnProperty(options.flow)) {
Expand Down Expand Up @@ -1199,8 +1290,9 @@ PayPalCheckout.prototype.loadPayPalSDK = function (options) {
dataAttributes["user-id-token"] || dataAttributes["data-user-id-token"];

if (this._configuration) {
dataAttributes["client-metadata-id"] =
this._configuration.analyticsMetadata.sessionId;
dataAttributes["client-metadata-id"] = dataAttributes["client-metadata-id"]
? dataAttributes["client-metadata-id"]
: this._configuration.analyticsMetadata.sessionId;
}

if (!userIdToken) {
Expand Down Expand Up @@ -1383,11 +1475,24 @@ PayPalCheckout.prototype._formatPaymentResourceData = function (
paymentResource.billingAgreementDetails = options.billingAgreementDetails;
}
} else {
// NOTE: This flow is "vault"
paymentResource.shippingAddress = options.shippingAddressOverride;

if (options.billingAgreementDescription) {
paymentResource.description = options.billingAgreementDescription;
}

if (options.planType) {
/* eslint-disable camelcase */
paymentResource.plan_type = options.planType;

if (options.planMetadata) {
paymentResource.plan_metadata = camelCaseToSnakeCase(
options.planMetadata
);
}
/* eslint-enable camelcase */
}
}

// this needs to be set outside of the block where add it to the
Expand Down
Loading

0 comments on commit b5d4d09

Please sign in to comment.