Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PP-11463 Fix Google pay description dialog bug #3685

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions app/assets/javascripts/browsered/web-payments/google-pay.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,27 @@ const processPayment = paymentData => {
}
}

const shortenGooglePayDescription = (fullPaymentDescription) => {
const MAX_LENGTH_PAYMENT_DESCRIPTION = 18

if (fullPaymentDescription.length > MAX_LENGTH_PAYMENT_DESCRIPTION) {
return fullPaymentDescription.substring(0, MAX_LENGTH_PAYMENT_DESCRIPTION - 1) + '…'
} else {
return fullPaymentDescription
}
}

const createGooglePaymentRequest = () => {
const methodData = [{
supportedMethods: 'https://google.com/pay',
data: getGooglePaymentsConfiguration()
}]

const shortenedPaymentDescription = shortenGooglePayDescription(window.paymentDetails.description)

const details = {
total: {
label: window.paymentDetails.description,
label: shortenedPaymentDescription,
amount: {
currency: 'GBP',
value: window.paymentDetails.amount
Expand Down Expand Up @@ -159,5 +171,6 @@ const googlePayNow = () => {

module.exports = {
createGooglePaymentRequest,
googlePayNow
googlePayNow,
shortenGooglePayDescription
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"Charge",
"parent",
"showCardType",
"openregisterLocationPicker"
"openregisterLocationPicker",
"window"
],
"ignore": [
"app/assets/javascripts/modules/*.js"
Expand Down
29 changes: 29 additions & 0 deletions test/unit/browsered/web-payments/google-pay.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict'

global.window = {
Card: {},
Charge: {}
}

const { shortenGooglePayDescription } = require('../../../../app/assets/javascripts/browsered/web-payments/google-pay')
const { expect } = require('chai')

const STRING_17_CHAR_LENGTH = 'abcdefghijklmnopq'
const STRING_18_CHAR_LENGTH = 'abcdefghijklmnopqr'
const STRING_19_CHAR_LENGTH = 'abcdefghijklmnopqrs'

describe('Google Pay', () => {
describe('shorten payment description for Google pay', () => {
it('should return the original description when the length < 18', () => {
expect(shortenGooglePayDescription(STRING_17_CHAR_LENGTH)).to.equal(STRING_17_CHAR_LENGTH)
})

it('should return the original description when length = 18', () => {
expect(shortenGooglePayDescription(STRING_18_CHAR_LENGTH)).to.equal(STRING_18_CHAR_LENGTH)
})

it('should tuncate the description to 17 characters and add the elipses character when length > 18', () => {
expect(shortenGooglePayDescription(STRING_19_CHAR_LENGTH)).to.equal('abcdefghijklmnopq…')
})
})
})