Skip to content

Commit

Permalink
chore: [IOBP-1048] Delete transaction when interrupting a payment (#6494
Browse files Browse the repository at this point in the history
)

## Short description
This PR addresses the deletion of transaction payments when a user
interrupts the payment process by closing the in-app browser. This
implementation ensures that users who interrupt a payment and attempt to
pay again within a few minutes can do so without encountering the
"ongoing payment" error screen.

## List of changes proposed in this pull request
- Added the handler inside the `useWalletPaymentAuthorizationModal.tsx`
to delete the current transaction when the user closes the in-app
browser;
- Deleted the reducer handling of the
`paymentsDeleteTransactionAction.failure` action: We don't need to show
anything if the transaction deletion has failed, just navigate to the
correct screen.

## How to test
- Run the dev-server;
- Start a payment from the app until you reach the in-app browser
content;
- Close the in-app browser by tapping the "Cancel" button on the
top-left of the screen;
- Check that the app makes an HTTP request that deletes the current
transaction;

---------

Co-authored-by: Emanuele Dall'Ara <[email protected]>
  • Loading branch information
Hantex9 and LeleDallas authored Dec 5, 2024
1 parent a8e32df commit a94ca59
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ import { WALLET_WEBVIEW_OUTCOME_SCHEMA } from "../../common/utils/const";
import { storePaymentOutcomeToHistory } from "../../history/store/actions";
import {
WalletPaymentAuthorizePayload,
paymentsDeleteTransactionAction,
paymentsStartPaymentAuthorizationAction
} from "../store/actions/networking";
import { walletPaymentAuthorizationUrlSelector } from "../store/selectors/transaction";
import {
walletPaymentAuthorizationUrlSelector,
walletPaymentTransactionSelector
} from "../store/selectors/transaction";
import {
WalletPaymentOutcome,
WalletPaymentOutcomeEnum
Expand All @@ -37,6 +41,7 @@ export const useWalletPaymentAuthorizationModal = ({
const authorizationUrlPot = useIOSelector(
walletPaymentAuthorizationUrlSelector
);
const transactionPot = useIOSelector(walletPaymentTransactionSelector);

const [isPendingAuthorization, setIsPendingAuthorization] =
React.useState<boolean>(false);
Expand Down Expand Up @@ -86,6 +91,13 @@ export const useWalletPaymentAuthorizationModal = ({
handleAuthorizationOutcome(
WalletPaymentOutcomeEnum.IN_APP_BROWSER_CLOSED_BY_USER
);
if (pot.isSome(transactionPot)) {
dispatch(
paymentsDeleteTransactionAction.request(
transactionPot.value.transactionId
)
);
}
}
)
),
Expand All @@ -96,6 +108,7 @@ export const useWalletPaymentAuthorizationModal = ({
isLoading,
isPendingAuthorization,
authorizationUrlPot,
transactionPot,
handleAuthorizationResult,
handleAuthorizationOutcome,
dispatch
Expand Down
15 changes: 0 additions & 15 deletions ts/features/payments/checkout/store/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { Action } from "../../../../../store/actions/types";
import { NetworkError } from "../../../../../utils/errors";
import { getSortedPspList } from "../../../common/utils";
import { WalletPaymentStepEnum } from "../../types";
import { FaultCodeCategoryEnum } from "../../types/PaymentGenericErrorAfterUserCancellationProblemJson";
import { FaultCodeCategoryEnum as PaymentMethodNotAvailableEnum } from "../../types/PspPaymentMethodNotAvailableProblemJson";
import { WalletPaymentFailure } from "../../types/WalletPaymentFailure";
import {
Expand Down Expand Up @@ -266,20 +265,6 @@ const reducer = (
...state,
transaction: pot.toError(state.transaction, action.payload)
};
case getType(paymentsDeleteTransactionAction.failure):
return {
...state,
transaction: pot.toError(
state.transaction,
action.payload.kind === "generic"
? {
faultCodeCategory:
FaultCodeCategoryEnum.PAYMENT_GENERIC_ERROR_AFTER_USER_CANCELLATION,
faultCodeDetail: ""
}
: action.payload
)
};

// Authorization url
case getType(paymentsStartPaymentAuthorizationAction.request):
Expand Down

0 comments on commit a94ca59

Please sign in to comment.