diff --git a/packages/core/src/i18n/messages/en.json b/packages/core/src/i18n/messages/en.json index 270d536b59..b10e600a02 100644 --- a/packages/core/src/i18n/messages/en.json +++ b/packages/core/src/i18n/messages/en.json @@ -1,5 +1,6 @@ { "error": { + "paypal-order-without-payments": "No payments were captured in this order", "paypal-order-details-failed": "Failed to get PayPal order details", "paypal-create-order-failed": "Failed to create PayPal order", "paypal-refund-failed": "PayPal refund failed", @@ -66,12 +67,8 @@ "unauthorized": "The credentials did not match. Please check and try again" }, "errorResult": { - "PAYPAL_ORDER_WITHOUT_PAYMENTS": "The PayPal order does not have any payments", "MULTIPLE_CAPTURES": "Multiple captures assigned to this order", "PAYPAL_PAYMENT_NOT_CAPTURED": "Capture is not completed", - "PAYPAL_ORDER_STATUS_NOT_CREATED": "Payment authorization failed. Payment status must be 'CREATED'", - "PAYPAL_ORDER_WITHOUT_AUTHORIZATIONS": "The PayPal order does not have any authorizations", - "PAYPAL_ORDER_MATCH_INVALID": "The PayPal order does not match the internal order", "ALREADY_LOGGED_IN_ERROR": "Cannot set a Customer for the Order when already logged in", "ALREADY_REFUNDED_ERROR": "Cannot refund an OrderItem which has already been refunded", "CANCEL_ACTIVE_ORDER_ERROR": "Cannot cancel OrderLines from an Order in the \"{ orderState }\" state", diff --git a/packages/payments-plugin/e2e/paypal-payment.e2e-spec.ts b/packages/payments-plugin/e2e/paypal-payment.e2e-spec.ts index 791aeb4c73..b0699d5122 100644 --- a/packages/payments-plugin/e2e/paypal-payment.e2e-spec.ts +++ b/packages/payments-plugin/e2e/paypal-payment.e2e-spec.ts @@ -193,7 +193,9 @@ describe('PayPal payments', () => { it('Should fail when no active order is set', async ({ expect }) => { await shopClient.asUserWithCredentials(customers[0].emailAddress, 'test'); const createOrderPromise = shopClient.query(CREATE_PAYPAL_ORDER); - await expect(createOrderPromise).rejects.toThrowError('Session has no active order'); + await expect(createOrderPromise).rejects.toThrowError( + 'No active Order could be determined nor created', + ); }); it('Should fail when not in ArrangingPayment state', async ({ expect }) => { await shopClient.asUserWithCredentials(customers[0].emailAddress, 'test'); @@ -208,7 +210,9 @@ describe('PayPal payments', () => { await setShipping(shopClient); const createOrderPromise = shopClient.query(CREATE_PAYPAL_ORDER); - await expect(createOrderPromise).rejects.toThrowError('Order must be in arranging payment state'); + await expect(createOrderPromise).rejects.toThrowError( + 'A Payment may only be added when Order is in "ArrangingPayment" state', + ); }); it('Should create an order with correct content', async ({ expect }) => { let createOrderRequest: CreatePayPalOrderRequest | undefined; @@ -356,20 +360,14 @@ describe('PayPal payments', () => { it('Should print error message when orderId is not set', async ({ expect }) => { await shopClient.asUserWithCredentials(customers[0].emailAddress, 'test'); - const addPaymentToOrderResult = await shopClient.query(ADD_PAYMENT_TO_ORDER, { - input: { - method: methodCode, - metadata: {}, - }, - }); - expect(addPaymentToOrderResult).toEqual({ - addPaymentToOrder: { - message: 'The payment failed', - errorCode: 'PAYMENT_FAILED_ERROR', - paymentErrorMessage: - '"orderId" must be set in metadata. Call "createPayPalOrder" to get order id', - }, - }); + await expect( + shopClient.query(ADD_PAYMENT_TO_ORDER, { + input: { + method: methodCode, + metadata: {}, + }, + }), + ).rejects.toThrow('The argument "orderId" is required'); }); it('Should return validation result if validation fails', async ({ expect }) => { await shopClient.asUserWithCredentials(customers[0].emailAddress, 'test'); @@ -427,7 +425,7 @@ describe('PayPal payments', () => { addPaymentToOrder: { message: 'The payment failed', errorCode: 'PAYMENT_FAILED_ERROR', - paymentErrorMessage: 'Payment authorization failed. Error while accessing PayPal.', + paymentErrorMessage: 'Payment authorization failed. Error while accessing PayPal', }, }); }); @@ -492,12 +490,6 @@ describe('PayPal payments', () => { }, { id: 'T_3', - state: 'Error', - transactionId: null, - method: methodCode, - }, - { - id: 'T_4', state: 'Authorized', transactionId: paypalOrderId, method: methodCode, @@ -559,14 +551,14 @@ describe('PayPal payments', () => { // We use the last payment of the previous describe block that was successful. const { settlePayment } = await adminClient.query(SETTLE_PAYMENT, { - id: 'T_4', + id: 'T_3', }); expect(settlePayment).toEqual({ errorCode: 'SETTLE_PAYMENT_ERROR', message: 'Settling the payment failed', __typename: 'SettlePaymentError', - paymentErrorMessage: 'No authorizations found in order details.', + paymentErrorMessage: 'No authorizations found in order details', }); }); it('Should capture order and return success', async ({ expect }) => { @@ -631,7 +623,7 @@ describe('PayPal payments', () => { }); expect(settlePayment).toEqual({ - id: 'T_5', + id: 'T_4', transactionId: paypalOrderId, amount: 120990, method: methodCode, @@ -721,7 +713,7 @@ describe('PayPal payments', () => { expect(reauthorizeRequestCount).toBe(1); expect(settlePayment).toEqual({ - id: 'T_6', + id: 'T_5', transactionId: paypalOrderId, amount: 120990, method: methodCode, @@ -749,7 +741,7 @@ describe('PayPal payments', () => { ], shipping: 1000, adjustment: 119900, - paymentId: 'T_5', + paymentId: 'T_4', reason: 'Test refund', }, }), @@ -788,7 +780,7 @@ describe('PayPal payments', () => { ], shipping: 1000, adjustment: 119900, - paymentId: 'T_5', + paymentId: 'T_4', reason: 'Test refund', }, }), @@ -824,7 +816,7 @@ describe('PayPal payments', () => { amount: 120990, shipping: 0, adjustment: 0, - paymentId: 'T_5', + paymentId: 'T_4', reason: 'Test refund', }, }); @@ -872,7 +864,7 @@ describe('PayPal payments', () => { amount: 120000, shipping: 0, adjustment: 0, - paymentId: 'T_6', + paymentId: 'T_5', reason: 'Test refund', }, }); @@ -883,7 +875,7 @@ describe('PayPal payments', () => { amount: 990, shipping: 0, adjustment: 0, - paymentId: 'T_6', + paymentId: 'T_5', reason: 'Test refund', }, }); diff --git a/packages/payments-plugin/src/paypal/paypal-order.service.ts b/packages/payments-plugin/src/paypal/paypal-order.service.ts index c5f144ed63..631e60c392 100644 --- a/packages/payments-plugin/src/paypal/paypal-order.service.ts +++ b/packages/payments-plugin/src/paypal/paypal-order.service.ts @@ -131,7 +131,8 @@ export class PayPalOrderService extends PayPalBaseService { return { state: 'Error' as const, amount: 0, - errorMessage: 'errorResult.PAYPAL_ORDER_MATCH_INVALID', + errorMessage: + 'PayPal order must have exactly one purchase_unit assigned. Please use "createPayPalOrder" to create a new order', }; } @@ -140,7 +141,7 @@ export class PayPalOrderService extends PayPalBaseService { return { state: 'Error' as const, amount: 0, - errorMessage: 'errorResult.PAYPAL_ORDER_MATCH_INVALID', + errorMessage: `Currency mismatch. Expected ${internalOrder.currencyCode}, got ${purchaseUnit.amount.currency_code}`, }; } @@ -148,7 +149,7 @@ export class PayPalOrderService extends PayPalBaseService { return { state: 'Error' as const, amount: 0, - errorMessage: 'errorResult.PAYPAL_ORDER_MATCH_INVALID', + errorMessage: `Reference ID mismatch. Expected ${internalOrder.code}, got ${purchaseUnit.reference_id ?? 'no reference id'}`, }; } @@ -157,7 +158,7 @@ export class PayPalOrderService extends PayPalBaseService { return { state: 'Error' as const, amount: 0, - errorMessage: 'errorResult.PAYPAL_ORDER_MATCH_INVALID', + errorMessage: `Amount mismatch. Expected ${orderTotal}, got ${purchaseUnit.amount.value}`, }; } @@ -165,7 +166,7 @@ export class PayPalOrderService extends PayPalBaseService { return { state: 'Error' as const, amount: 0, - errorMessage: 'errorResult.PAYPAL_ORDER_MATCH_INVALID', + errorMessage: 'Payee mismatch', }; } } diff --git a/packages/payments-plugin/src/paypal/paypal.handler.ts b/packages/payments-plugin/src/paypal/paypal.handler.ts index 6e1ee5b15a..1692782326 100644 --- a/packages/payments-plugin/src/paypal/paypal.handler.ts +++ b/packages/payments-plugin/src/paypal/paypal.handler.ts @@ -63,7 +63,7 @@ export const paypalPaymentMethodHandler = new PaymentMethodHandler({ return { state: 'Error' as const, amount: 0, - errorMessage: error.message, + errorMessage: 'Payment authorization failed. Error while accessing PayPal', }; } @@ -71,7 +71,7 @@ export const paypalPaymentMethodHandler = new PaymentMethodHandler({ return { state: 'Error' as const, amount: 0, - errorMessage: 'errorResult.PAYPAL_ORDER_WITHOUT_PAYMENTS', + errorMessage: 'Payment authorization failed. No payments found', }; } @@ -79,7 +79,7 @@ export const paypalPaymentMethodHandler = new PaymentMethodHandler({ return { state: 'Error' as const, amount: 0, - errorMessage: 'errorResult.PAYPAL_ORDER_WITHOUT_AUTHORIZATIONS', + errorMessage: 'Payment authorization failed. No authorizations found', }; } @@ -89,7 +89,7 @@ export const paypalPaymentMethodHandler = new PaymentMethodHandler({ return { state: 'Error' as const, amount: 0, - errorMessage: 'errorResult.PAYPAL_ORDER_STATUS_NOT_CREATED', + errorMessage: 'Payment authorization failed. Payment status must be "CREATED"', }; } @@ -107,7 +107,7 @@ export const paypalPaymentMethodHandler = new PaymentMethodHandler({ if (payment.state !== 'Authorized') { return { success: false, - errorMessage: 'errorResult.PAYPAL_ORDER_WITHOUT_AUTHORIZATIONS', + errorMessage: 'Payment is not authorized. Call "createPayment" to authorize payment', state: 'Error' as const, }; } @@ -121,7 +121,7 @@ export const paypalPaymentMethodHandler = new PaymentMethodHandler({ if (!authorizations?.length) { return { success: false, - errorMessage: 'errorResult.PAYPAL_ORDER_WITHOUT_AUTHORIZATIONS', + errorMessage: 'No authorizations found in order details', state: 'Error' as const, }; } @@ -153,11 +153,11 @@ export const paypalPaymentMethodHandler = new PaymentMethodHandler({ const captures = payments?.captures; if (!captures || !captures.length) { - throw new PayPalError('errorResult.PAYPAL_ORDER_WITHOUT_PAYMENTS'); + throw new PayPalError('No payments were captured in this order'); } if (captures.length !== 1) { - throw new PayPalError('errorResult.MULTIPLE_CAPTURES'); + throw new PayPalError('Multiple captures assigned to this order'); } const capture = captures[0];