-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore. payment methods refactoring (#358)
- Loading branch information
Showing
6 changed files
with
119 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,6 @@ | ||
import { PaymentMethodStatusEnum } from "../../../../generated/definitions/pagopa/walletv3/PaymentMethodStatus"; | ||
import { PaymentMethodsResponse } from "../../../../generated/definitions/pagopa/walletv3/PaymentMethodsResponse"; | ||
import { Range } from "../../../../generated/definitions/pagopa/walletv3/Range"; | ||
import { paymentMethodsDB } from "../persistence/paymentMethods"; | ||
|
||
export const allPaymentMethods: PaymentMethodsResponse = { | ||
paymentMethods: [ | ||
{ | ||
id: "1", | ||
name: "CARDS", | ||
description: "Carta di credito", | ||
status: PaymentMethodStatusEnum.ENABLED, | ||
paymentTypeCode: "CARDS", | ||
ranges: [ | ||
{ | ||
min: 0, | ||
max: 1000 | ||
} as Range | ||
] | ||
}, | ||
{ | ||
id: "2", | ||
name: "PAYPAL", | ||
description: "PayPal", | ||
asset: | ||
"https://github.com/pagopa/io-services-metadata/blob/master/logos/apps/paypal.png?raw=true", | ||
status: PaymentMethodStatusEnum.ENABLED, | ||
paymentTypeCode: "PAYPAL", | ||
ranges: [ | ||
{ | ||
min: 0, | ||
max: 500 | ||
} as Range | ||
] | ||
} | ||
] | ||
paymentMethods: paymentMethodsDB | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { faker } from "@faker-js/faker"; | ||
import { format } from "date-fns"; | ||
import { PaymentMethodResponse } from "../../../../generated/definitions/pagopa/walletv3/PaymentMethodResponse"; | ||
import { PaymentMethodStatusEnum } from "../../../../generated/definitions/pagopa/walletv3/PaymentMethodStatus"; | ||
import { Range } from "../../../../generated/definitions/pagopa/walletv3/Range"; | ||
import { | ||
BrandEnum, | ||
WalletInfoDetails | ||
} from "../../../../generated/definitions/pagopa/walletv3/WalletInfoDetails"; | ||
import { getRandomEnumValue } from "../../../payloads/utils/random"; | ||
|
||
export const paymentMethodsDB: ReadonlyArray<PaymentMethodResponse> = [ | ||
{ | ||
id: "1", | ||
name: "CARDS", | ||
description: "Carte di credito o debito", | ||
asset: "https://assets.cdn.platform.pagopa.it/creditcard/generic.png", | ||
status: PaymentMethodStatusEnum.ENABLED, | ||
paymentTypeCode: "CP", | ||
ranges: [ | ||
{ | ||
min: 0, | ||
max: 1000 | ||
} as Range | ||
] | ||
}, | ||
{ | ||
id: "2", | ||
name: "PAYPAL", | ||
description: "PayPal", | ||
asset: "https://assets.cdn.platform.pagopa.it/apm/paypal.png", | ||
status: PaymentMethodStatusEnum.ENABLED, | ||
paymentTypeCode: "PPAL", | ||
ranges: [ | ||
{ | ||
min: 0, | ||
max: 500 | ||
} as Range | ||
] | ||
}, | ||
{ | ||
id: "3", | ||
name: "BANCOMATPAY", | ||
description: "BANCOMAT Pay", | ||
asset: "https://assets.cdn.platform.pagopa.it/apm/bancomatpay.png", | ||
status: PaymentMethodStatusEnum.ENABLED, | ||
paymentTypeCode: "BPAY", | ||
ranges: [ | ||
{ | ||
min: 0, | ||
max: 1000 | ||
} as Range | ||
] | ||
} | ||
]; | ||
|
||
export const generateWalletDetailsByPaymentMethod = ( | ||
paymentMethodId: number | ||
): WalletInfoDetails => { | ||
switch (paymentMethodId) { | ||
case 1: | ||
default: | ||
return { | ||
type: "CARDS", | ||
lastFourDigits: faker.finance.mask(4, false, false), | ||
expiryDate: format(faker.date.future(3), "yyyyMM"), | ||
brand: getRandomEnumValue(BrandEnum) | ||
}; | ||
case 2: | ||
return { | ||
type: "PAYPAL", | ||
abi: faker.random.numeric(5), | ||
maskedEmail: faker.internet.email() | ||
}; | ||
case 3: | ||
return { | ||
type: "BPAY", | ||
maskedNumber: faker.phone.number(), | ||
instituteCode: faker.random.numeric(5), | ||
bankName: faker.finance.accountName() | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,54 @@ | ||
import { faker } from "@faker-js/faker"; | ||
import * as E from "fp-ts/lib/Either"; | ||
import { WalletApplication } from "../../../../generated/definitions/pagopa/walletv3/WalletApplication"; | ||
import { WalletApplicationStatusEnum } from "../../../../generated/definitions/pagopa/walletv3/WalletApplicationStatus"; | ||
import { WalletInfo } from "../../../../generated/definitions/pagopa/walletv3/WalletInfo"; | ||
import { BrandEnum } from "../../../../generated/definitions/pagopa/walletv3/WalletInfoDetails"; | ||
import { WalletStatusEnum } from "../../../../generated/definitions/pagopa/walletv3/WalletStatus"; | ||
import { allPaymentMethods } from "../payloads/paymentMethods"; | ||
import { getWalletTypeFromPaymentMethodId } from "../utils/onboarding"; | ||
import { WalletApplicationStatusEnum } from "../../../../generated/definitions/pagopa/walletv3/WalletApplicationStatus"; | ||
import { WalletApplication } from "../../../../generated/definitions/pagopa/walletv3/WalletApplication"; | ||
|
||
const userWallets = new Map<string, WalletInfo>(); | ||
import { generateWalletDetailsByPaymentMethod } from "./paymentMethods"; | ||
|
||
const addUserWallet = (walletId: string, wallet: WalletInfo) => { | ||
userWallets.set(walletId, wallet); | ||
}; | ||
const userWallets = new Map<WalletInfo["walletId"], WalletInfo>(); | ||
|
||
const getUserWallets = () => Array.from(userWallets.values()); | ||
|
||
const getUserWalletInfo = (walletId: string) => userWallets.get(walletId); | ||
const getUserWalletInfo = (walletId: WalletInfo["walletId"]) => | ||
userWallets.get(walletId); | ||
|
||
const addUserWallet = (wallet: WalletInfo) => { | ||
userWallets.set(wallet.walletId, wallet); | ||
}; | ||
|
||
const generateUserWallet = (paymentMethodId: string) => { | ||
const removeUserWallet = (walletId: WalletInfo["walletId"]) => { | ||
userWallets.delete(walletId); | ||
}; | ||
|
||
const generateUserWallet = (paymentMethodId: number) => { | ||
const walletId = (getUserWallets().length + 1).toString(); | ||
const expiryDate = faker.date.future(); | ||
const details = generateWalletDetailsByPaymentMethod(paymentMethodId); | ||
|
||
const randomWallet: WalletInfo = { | ||
creationDate: new Date(), | ||
paymentMethodId, | ||
walletId, | ||
paymentMethodId: paymentMethodId.toString(), | ||
status: WalletStatusEnum.CREATED, | ||
creationDate: faker.date.past(2), | ||
updateDate: faker.date.past(1), | ||
applications: [ | ||
{ | ||
name: "PAGOPA", | ||
status: WalletApplicationStatusEnum.ENABLED | ||
} | ||
], | ||
status: WalletStatusEnum.CREATED, | ||
updateDate: new Date(), | ||
paymentMethodAsset: | ||
"https://github.com/pagopa/io-services-metadata/blob/master/logos/apps/carte-pagamento.png?raw=true", | ||
walletId, | ||
details: { | ||
type: getWalletTypeFromPaymentMethodId(paymentMethodId), | ||
maskedEmail: "***[email protected]", | ||
abi: faker.datatype.string(4), | ||
brand: BrandEnum.MASTERCARD, | ||
expiryDate: expiryDate.toISOString(), | ||
bankName: faker.name.fullName(), | ||
lastFourDigits: "0000" | ||
} | ||
details | ||
}; | ||
addUserWallet(walletId, randomWallet); | ||
addUserWallet(randomWallet); | ||
return randomWallet; | ||
}; | ||
|
||
const removeUserWallet = (walletId: string) => { | ||
userWallets.delete(walletId); | ||
}; | ||
|
||
const generateWalletData = () => { | ||
generateUserWallet( | ||
faker.helpers.arrayElement(allPaymentMethods.paymentMethods).id | ||
); | ||
generateUserWallet(3); | ||
generateUserWallet(2); | ||
generateUserWallet(1); | ||
}; | ||
|
||
const updateUserWalletApplication = ( | ||
|
@@ -76,7 +68,7 @@ const updateUserWalletApplication = ( | |
} as WalletApplication) | ||
) | ||
}; | ||
addUserWallet(walletId, wallet); | ||
addUserWallet(wallet); | ||
return E.right(wallet); | ||
} | ||
return E.left("Wallet not found"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters