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

feat(Payments): [#176364017] Use /v1/psps/selected instead of deprecated /v1/psps #2675

Merged
merged 3 commits into from
Jan 5, 2021
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
51 changes: 46 additions & 5 deletions ts/api/pagopa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
GetPspListUsingGETT,
getPspUsingGETDecoder,
GetPspUsingGETT,
getSelectedPspUsingGETDecoder,
getTransactionsUsingGETDecoder,
getTransactionUsingGETDecoder,
GetTransactionUsingGETT,
Expand Down Expand Up @@ -272,6 +273,37 @@ const getPspList: GetPspListUsingGETTExtra = {
response_decoder: getPspListUsingGETDecoder(PspListResponse)
};

type PspParams = {
readonly Bearer: string;
readonly idWallet: string;
readonly idPayment: string;
readonly language: string;
};
export type GetSelectedPspUsingGETTExtra = r.IGetApiRequestType<
PspParams,
"Authorization",
never,
| r.IResponseType<200, PspListResponse>
| r.IResponseType<401, undefined>
| r.IResponseType<403, undefined>
| r.IResponseType<404, undefined>
>;
const getPspQuery = (params: PspParams) => {
const { idPayment, idWallet, language } = params;
return {
idPayment,
idWallet,
language
};
};
const getPspSelected: GetSelectedPspUsingGETTExtra = {
method: "get",
url: () => "/v1/psps/selected",
query: getPspQuery,
headers: ParamAuthorizationBearerHeader,
response_decoder: getSelectedPspUsingGETDecoder(PspListResponse)
};

type GetAllPspListUsingGETTExtra = MapResponseType<
GetAllPspsUsingGETT,
200,
Expand All @@ -281,11 +313,7 @@ type GetAllPspListUsingGETTExtra = MapResponseType<
const getAllPspList: GetAllPspListUsingGETTExtra = {
method: "get",
url: () => "/v1/psps/all",
query: ({ idPayment, idWallet, language }) => ({
idPayment,
idWallet,
language
}),
query: getPspQuery,
headers: ParamAuthorizationBearerHeader,
response_decoder: getPspListUsingGETDecoder(PspListResponse)
};
Expand Down Expand Up @@ -540,6 +568,19 @@ export function PaymentManagerClient(
idWallet,
language: getLocalePrimaryWithFallback()
}),
getPspSelected: (
idPayment: TypeofApiParams<GetAllPspsUsingGETT>["idPayment"],
idWallet: TypeofApiParams<GetAllPspsUsingGETT>["idWallet"]
) =>
flip(
withPaymentManagerToken(
createFetchRequestForApi(getPspSelected, options)
)
)({
idPayment,
idWallet,
language: getLocalePrimaryWithFallback()
}),
getPsp: (id: TypeofApiParams<GetPspUsingGETT>["id"]) =>
flip(withPaymentManagerToken(createFetchRequestForApi(getPsp, options)))({
id
Expand Down
12 changes: 7 additions & 5 deletions ts/sagas/wallet/pagopaApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,14 +435,16 @@ export function* paymentFetchPspsForWalletRequestHandler(
pmSessionManager: SessionManager<PaymentManagerToken>,
action: ActionType<typeof paymentFetchPspsForPaymentId["request"]>
) {
const apiGetPspList = pagoPaClient.getPspList(
const apiGetPspSelected = pagoPaClient.getPspSelected(
action.payload.idPayment,
action.payload.idWallet
action.payload.idWallet.toString()
);
const apiGetPspSelectedWithRefresh = pmSessionManager.withRefresh(
apiGetPspSelected
);
const getPspListWithRefresh = pmSessionManager.withRefresh(apiGetPspList);
try {
const response: SagaCallReturnType<typeof getPspListWithRefresh> = yield call(
getPspListWithRefresh
const response: SagaCallReturnType<typeof apiGetPspSelectedWithRefresh> = yield call(
apiGetPspSelectedWithRefresh
);
if (response.isRight()) {
if (response.value.status === 200) {
Expand Down
4 changes: 1 addition & 3 deletions ts/screens/wallet/payment/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ export const dispatchPickPspOrConfirm = (dispatch: Dispatch) => (
dispatch(
paymentFetchPspsForPaymentId.request({
idPayment,
// provide the idWallet to the getPsps request only if the wallet has
// a preferred PSP
idWallet: selectedWallet.psp ? selectedWallet.idWallet : undefined,
idWallet: selectedWallet.idWallet,
onFailure: () => onFailure("FETCH_PSPS_FAILURE"),
onSuccess: successAction => {
// filter PSPs for the current locale only (the list will contain
Expand Down
2 changes: 1 addition & 1 deletion ts/store/actions/wallet/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const paymentCheck = createAsyncAction(

type PaymentFetchPspsForPaymentIdRequestPayload = Readonly<{
idPayment: string;
idWallet?: number;
idWallet: number;
onSuccess?: (
action: ActionType<typeof paymentFetchPspsForPaymentId["success"]>
) => void;
Expand Down