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

Fix/ Retrieve saved cards for at Profile System for PII accounts #664

Merged
merged 6 commits into from
Jun 28, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed
- Retrieve saved cards from a profile at my account for PII accounts

## [2.170.4] - 2024-06-27

### Added
- fallback value for administrativeAreaLevel1 for profile V2


## [2.170.3] - 2024-06-26

### Fixed
Expand Down
6 changes: 2 additions & 4 deletions node/clients/profile/profileV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,11 @@ export class ProfileClientV2 extends JanusClient {
}

public getUserPayments = (user: CurrentProfile, piiRequest?: PIIRequest) => {
const { userKey, alternativeKey } = this.getUserKeyAndAlternateKey(user)
const url = this.getPIIUrl(
`${this.baseUrl}/${userKey}/purchase-info/unmask`,
alternativeKey,
`${this.baseUrl}/${user.userId}/purchase-info`,
vmourac-vtex marked this conversation as resolved.
Show resolved Hide resolved
undefined,
piiRequest
)

return this.get(url, {
metric: 'profile-system-v2-getUserPayments',
}).catch<any>((e) => {
Expand Down
16 changes: 12 additions & 4 deletions node/resolvers/profile/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,26 @@ export function getAddresses(context: Context, currentUserProfile?: Profile) {

export async function getPayments(context: Context) {
const {
clients: { profile },
clients: { profile, licenseManagerExtended },
vtex: { currentProfile },
} = context

const { PIIEnabled } = await licenseManagerExtended.getCurrentAccount()
const paymentsRawData = await profile.getUserPayments(currentProfile, context)
const isPaymentDataEmpty = PIIEnabled
? !paymentsRawData[0]?.document?.paymentData
: !paymentsRawData?.paymentData

if (!paymentsRawData?.paymentData) {
if (isPaymentDataEmpty) {
return null
}

const addresses = await getAddresses(context)
const { availableAccounts } = JSON.parse(paymentsRawData.paymentData)

const paymentData = PIIEnabled
? paymentsRawData[0]?.document?.paymentData
: JSON.parse(paymentsRawData.paymentData)

const { availableAccounts } = paymentData

return availableAccounts.map((account: any) => {
const { bin, availableAddresses, accountId, ...cleanAccount } = account
Expand Down
Loading