Merge pull request #586 from Safelite/feature/digital/SSR-1101.1

SSR-1101 Enable Paypal
This commit is contained in:
Josh Dassinger 2024-03-15 07:55:25 -05:00 committed by GitHub
commit 1537e4618b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 61 additions and 25 deletions

View file

@ -9,6 +9,7 @@ const queryStrings = Object.freeze({
CARD_TYPE: 'sgcardtype', CARD_TYPE: 'sgcardtype',
DISPLAY_PAY_IN_ADVANCE_ALERT: 'displayPayInAdvanceAlert', DISPLAY_PAY_IN_ADVANCE_ALERT: 'displayPayInAdvanceAlert',
ERROR: 'error', ERROR: 'error',
TOKEN: 'token',
LAST_FOUR: 'last_four', LAST_FOUR: 'last_four',
REFERENCE_NUMBER: 'req_reference_number', REFERENCE_NUMBER: 'req_reference_number',
REFERRAL_SEQ_NUM: 'referralseqnum', REFERRAL_SEQ_NUM: 'referralseqnum',

View file

@ -4,8 +4,8 @@ import { updateOrCreateISSCookie } from '@/helpers/cookie-helper';
/* /*
Encapsulates asynchronous Save Session logic inside a promise to allow for Save Session queuing Encapsulates asynchronous Save Session logic inside a promise to allow for Save Session queuing
*/ */
async function saveSessionHelper(store) { async function saveSessionHelper(store, { submitAfterSave }) {
const savedSessionInfo = await store.saveSession(); const savedSessionInfo = await store.saveSession({ submitAfterSave });
if (savedSessionInfo) { if (savedSessionInfo) {
store.setSaveSessionInfo(savedSessionInfo.data); store.setSaveSessionInfo(savedSessionInfo.data);
} }
@ -17,11 +17,11 @@ async function saveSessionHelper(store) {
This will also set Referral information in the store after saving, and then This will also set Referral information in the store after saving, and then
update the cookie. To force synchronous behavior pass in 'true' for shouldAwaitSaveSessionQueue update the cookie. To force synchronous behavior pass in 'true' for shouldAwaitSaveSessionQueue
*/ */
export async function saveSession({ shouldAwaitSaveSessionQueue = false }) { export async function saveSession({ shouldAwaitSaveSessionQueue = false, submitAfterSave = false }) {
const store = useMainStore(); const store = useMainStore();
const saveSessionPromise = store.applicationUser.saveSessionPromise const saveSessionPromise = store.applicationUser.saveSessionPromise
? store.applicationUser.saveSessionPromise.then(() => saveSessionHelper(store)) ? store.applicationUser.saveSessionPromise.then(() => saveSessionHelper(store, { submitAfterSave }))
: saveSessionHelper(store); : saveSessionHelper(store, { submitAfterSave });
store.setSaveSessionPromise(saveSessionPromise); store.setSaveSessionPromise(saveSessionPromise);

View file

@ -74,6 +74,7 @@ export default {
await this.processCreditCardResponse(); await this.processCreditCardResponse();
break; break;
case paymentMethods.PAYPAL: case paymentMethods.PAYPAL:
await this.processPaypalResponse();
break; break;
default: default:
console.log(`Unknown pay in advance type: ${payInAdvanceType}`); console.log(`Unknown pay in advance type: ${payInAdvanceType}`);

View file

@ -67,6 +67,10 @@ export default {
}); });
}, },
getAmountDue(lineItems) { getAmountDue(lineItems) {
if (!useMainStore().isNoComp && !useMainStore().policy.isITAC) {
return useMainStore().order.currentDeductible;
}
let amountDue = 0; let amountDue = 0;
if (lineItems.glassParts) { if (lineItems.glassParts) {
amountDue += this.getTotalPriceOfAllLineItemsAndChildParts( amountDue += this.getTotalPriceOfAllLineItemsAndChildParts(

View file

@ -1145,7 +1145,7 @@ export const useMainStore = defineStore({
this.applicationUser.crmCustomerId = response.crmCustomerId.toString(); this.applicationUser.crmCustomerId = response.crmCustomerId.toString();
}, },
saveSession() { saveSession({ submitAfterSave }) {
const { vehicle, damage, policy, customer, contactInfo, payment, const { vehicle, damage, policy, customer, contactInfo, payment,
lineItems, serviceLocation, schedule } = this.order; lineItems, serviceLocation, schedule } = this.order;
@ -1233,7 +1233,9 @@ export const useMainStore = defineStore({
coverageStatus: payment.insuranceCoverage?.coverageStatus, coverageStatus: payment.insuranceCoverage?.coverageStatus,
claimNumber: payment.insuranceCoverage?.claimNumber claimNumber: payment.insuranceCoverage?.claimNumber
}, },
parentAccountNumber: this.issConfig.parentAccountNumber parentAccountNumber: this.issConfig.parentAccountNumber,
paypalToken: payment.paypalToken,
isPaypal: payment.payInAdvanceType === paymentMethods.PAYPAL
}, },
serviceLocation: { serviceLocation: {
address: { address: {
@ -1274,7 +1276,8 @@ export const useMainStore = defineStore({
referralSequenceNumber: this.order.referralSequenceNumber, referralSequenceNumber: this.order.referralSequenceNumber,
eon: this.order.eon, eon: this.order.eon,
submitToMainframe: !!this.order.referralNumber, submitToMainframe: !!this.order.referralNumber,
loadedFromDupeCheck loadedFromDupeCheck,
submitAfterSave: !!submitAfterSave
}, },
additionalSuccessEventDataHandler: () => additionalSuccessEventDataHandler: () =>
`Email provided: ${customer.emailAddress ? 'true' : 'false'}` `Email provided: ${customer.emailAddress ? 'true' : 'false'}`

View file

@ -503,7 +503,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
await store.saveSession(); await store.saveSession({});
// Asserts // Asserts
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -517,7 +517,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(response)); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(response));
// Act // Act
const result = store.saveSession(); const result = store.saveSession({});
// Asserts // Asserts
await expect(result).resolves.toBe(response); await expect(result).resolves.toBe(response);
@ -537,7 +537,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
await store.saveSession(); await store.saveSession({});
// Asserts // Asserts
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -570,7 +570,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
await store.saveSession(); await store.saveSession({});
// Asserts // Asserts
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -612,7 +612,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
await store.saveSession(); await store.saveSession({});
// Assert // Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -659,7 +659,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
await store.saveSession(); await store.saveSession({});
// Asserts // Asserts
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -708,7 +708,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
await store.saveSession(); await store.saveSession({});
// Assert // Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -742,7 +742,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
await store.saveSession(); await store.saveSession({});
// Assert // Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -769,7 +769,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
await store.saveSession(); await store.saveSession({});
// Assert // Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -802,7 +802,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
await store.saveSession(); await store.saveSession({});
// Assert // Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -838,7 +838,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
await store.saveSession(); await store.saveSession({});
// Assert // Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -861,7 +861,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
await store.saveSession(); await store.saveSession({});
// Assert // Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -875,7 +875,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
await store.saveSession(); await store.saveSession({});
// Assert // Assert
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -888,7 +888,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
await store.saveSession(); await store.saveSession({});
// Asserts // Asserts
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -904,7 +904,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
await store.saveSession(); await store.saveSession({});
// Asserts // Asserts
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -927,7 +927,7 @@ describe('Store', () => {
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({})); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act // Act
await store.saveSession(); await store.saveSession({});
// Asserts // Asserts
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({ expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
@ -941,13 +941,27 @@ describe('Store', () => {
}) })
})); }));
}); });
it('calls api with expected submitAfterSave', async () => {
// Arrange
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve({}));
// Act
await store.saveSession({ submitAfterSave: true });
// Asserts
expect(globalMethods.callHttpClient).toHaveBeenCalledWith(expect.objectContaining({
payload: expect.objectContaining({
submitAfterSave: true
})
}));
});
it('api call throws exception', async () => { it('api call throws exception', async () => {
expect.assertions(2); expect.assertions(2);
const error = 'save session error'; const error = 'save session error';
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject(error)); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.reject(error));
// Act // Act
await store.saveSession().catch((e) => { await store.saveSession({}).catch((e) => {
expect(e).toEqual(error); expect(e).toEqual(error);
}); });
@ -1887,4 +1901,17 @@ describe('Store', () => {
expect(store.order.payment.payInAdvanceType).toEqual(paymentMethod); expect(store.order.payment.payInAdvanceType).toEqual(paymentMethod);
}); });
}); });
describe('updatePaypalToken method', () => {
it('paypalToken is valid when set', () => {
// Arrange
const paypalToken = getRandomString(6, 6);
// Act
store.updatePaypalToken(paypalToken);
// Assert
expect(store.order.payment.paypalToken).toEqual(paypalToken);
});
});
}); });