diff --git a/CHANGELOG.md b/CHANGELOG.md index 873e3b93..f77381c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +# 3.102.0 + +- PayPal + - Support new `amountBreakdown` and its subfields in the `updatePayment` method + # 3.101.3 - FrameService diff --git a/package-lock.json b/package-lock.json index 23187980..6c1e549d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "braintree-web", - "version": "3.101.3", + "version": "3.102.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 99afb858..f91fe398 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "braintree-web", - "version": "3.101.3", + "version": "3.102.0", "license": "MIT", "main": "src/index.js", "private": true, diff --git a/src/paypal-checkout/paypal-checkout.js b/src/paypal-checkout/paypal-checkout.js index acce5797..aa93edc1 100644 --- a/src/paypal-checkout/paypal-checkout.js +++ b/src/paypal-checkout/paypal-checkout.js @@ -575,6 +575,14 @@ PayPalCheckout.prototype._createPaymentResource = function (options, config) { * @param {string} options.currency The currency code of the amount, such as 'USD'. Required when using the Checkout flow. * @param {shippingOption[]} [options.shippingOptions] List of {@link PayPalCheckout~shippingOption|shipping options} offered by the payee or merchant to the payer to ship or pick up their items. * @param {lineItem[]} [options.lineItems] The {@link PayPalCheckout~lineItem|line items} for this transaction. It can include up to 249 line items. + * @param {object} [options.amountBreakdown] Optional collection of amounts that break down the total into individual pieces. + * @param {string} [options.amountBreakdown.itemTotal] Optional, item amount + * @param {string} [options.amountBreakdown.shipping] Optional, shipping amount + * @param {string} [options.amountBreakdown.handling] Optional, handling amount + * @param {string} [options.amountBreakdown.taxTotal] Optional, tax amount + * @param {string} [options.amountBreakdown.insurance] Optional, insurance amount + * @param {string} [options.amountBreakdown.shippingDiscount] Optional, shipping discount amount + * @param {string} [options.amountBreakdown.discount] Optional, discount amount * @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 @@ -1469,6 +1477,10 @@ PayPalCheckout.prototype._formatUpdatePaymentData = function (options) { paymentResource.shippingOptions = options.shippingOptions; } + if (options.hasOwnProperty("amountBreakdown")) { + paymentResource.amountBreakdown = options.amountBreakdown; + } + /* shippingAddress not supported yet */ if (options.hasOwnProperty("shippingAddress")) { analytics.sendEvent( diff --git a/test/paypal-checkout/unit/paypal-checkout.js b/test/paypal-checkout/unit/paypal-checkout.js index 29367489..05b37fd8 100644 --- a/test/paypal-checkout/unit/paypal-checkout.js +++ b/test/paypal-checkout/unit/paypal-checkout.js @@ -1520,6 +1520,32 @@ describe("PayPalCheckout", () => { expect(formattedData).not.toHaveProperty("recipientName"); }); }); + + it("propagates amountBreakdown when passed", () => { + const amountBreakdown = { + itemTotal: "12.34", + shipping: "2.99", + handling: "0", + taxTotal: "1.99", + insurance: "0", + shippingDiscount: "0", + discount: "0", + }; + const options = { + paymentId: "abc123", + currency: "USD", + amountBreakdown: amountBreakdown, + }; + const actual = PayPalCheckout.prototype._formatUpdatePaymentData(options); + + expect(actual).toStrictEqual({ + paymentId: "abc123", + // eslint-disable-next-line no-undefined + merchantAccountId: undefined, + currencyIsoCode: "USD", + amountBreakdown: amountBreakdown, + }); + }); }); describe("startVaultInitiatedCheckout", () => {