-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
195 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { AppContext } from "../../mod.ts"; | ||
import { parseCookie } from "../../utils/vtexId.ts"; | ||
|
||
export interface DeleteCard { | ||
deletePaymentToken: boolean; | ||
} | ||
|
||
interface Props { | ||
id: string; | ||
} | ||
|
||
async function loader( | ||
{ id }: Props, | ||
req: Request, | ||
ctx: AppContext, | ||
): Promise<DeleteCard | null> { | ||
const { io } = ctx; | ||
const { cookie, payload } = parseCookie(req.headers, ctx.account); | ||
|
||
if (!payload?.sub || !payload?.userId) { | ||
return null; | ||
} | ||
|
||
const mutation = `mutation DeleteCreditCardToken($tokenId: ID!) { | ||
deletePaymentToken(tokenId: $tokenId) @context(provider: "vtex.my-cards-graphql@2.x") | ||
}`; | ||
|
||
try { | ||
return await io.query<DeleteCard, { tokenId: string }>({ | ||
query: mutation, | ||
variables: { tokenId: id }, | ||
}, { headers: { cookie } }); | ||
} catch (e) { | ||
console.error(e); | ||
return null; | ||
} | ||
} | ||
|
||
export default loader; |
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,55 @@ | ||
import { AppContext } from "../../mod.ts"; | ||
import { parseCookie } from "../../utils/vtexId.ts"; | ||
|
||
const query = `query getPaymentSystems { | ||
paymentSystems { | ||
name | ||
groupName | ||
requiresDocument | ||
displayDocument | ||
validator { | ||
regex | ||
mask | ||
cardCodeMask | ||
cardCodeRegex | ||
} | ||
} | ||
}`; | ||
|
||
export interface PaymentSystem { | ||
name: string; | ||
groupName: string; | ||
requiresDocument: boolean; | ||
displayDocument: boolean; | ||
validator: { | ||
regex: string | null; | ||
mask: string | null; | ||
cardCodeMask: string | null; | ||
cardCodeRegex: string | null; | ||
}; | ||
} | ||
|
||
export default async function loader( | ||
_props: unknown, | ||
req: Request, | ||
ctx: AppContext, | ||
) { | ||
const { io } = ctx; | ||
const { cookie, payload } = parseCookie(req.headers, ctx.account); | ||
|
||
if (!payload?.sub || !payload?.userId) { | ||
return null; | ||
} | ||
|
||
try { | ||
const data = await io.query<{ paymentSystems: PaymentSystem[] }, null>( | ||
{ query }, | ||
{ headers: { cookie } }, | ||
); | ||
|
||
return data.paymentSystems; | ||
} catch (e) { | ||
console.error(e); | ||
return null; | ||
} | ||
} |
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,61 @@ | ||
// fetch("https://www.als.com/_v/private/graphql/v1?workspace=master&maxAge=long&appsEtag=remove&domain=store&locale=en-US&__bindingId=d8649f18-3877-43de-88e6-c45a81eddc02", { | ||
// "headers": { | ||
// "content-type": "application/json", | ||
// }, | ||
// "body": "{\"operationName\":\"Payments\",\"variables\":{},\"extensions\":{\"persistedQuery\":{\"version\":1,\"sha256Hash\":\"95af11127e44f1857144e38f18635e0d085113c3bfdda3e4b8bc99ae63e14e60\",\"sender\":\"vtex.my-cards@1.x\",\"provider\":\"vtex.store-graphql@2.x\"}}}", | ||
// "method": "POST" | ||
// }) | ||
|
||
import { AppContext } from "../../mod.ts"; | ||
import { parseCookie } from "../../utils/vtexId.ts"; | ||
|
||
export interface Payment { | ||
accountStatus: string | null; | ||
cardNumber: string; | ||
expirationDate: string; | ||
id: string; | ||
isExpired: boolean; | ||
paymentSystem: string; | ||
paymentSystemName: string; | ||
} | ||
|
||
async function loader( | ||
_props: unknown, | ||
req: Request, | ||
ctx: AppContext, | ||
): Promise<Payment[] | null> { | ||
const { io } = ctx; | ||
const { cookie, payload } = parseCookie(req.headers, ctx.account); | ||
|
||
if (!payload?.sub || !payload?.userId) { | ||
return null; | ||
} | ||
|
||
const query = `query getUserPayments { | ||
profile { | ||
payments { | ||
accountStatus | ||
cardNumber | ||
expirationDate | ||
id | ||
isExpired | ||
paymentSystem | ||
paymentSystemName | ||
} | ||
} | ||
}`; | ||
|
||
try { | ||
const data = await io.query<{ profile: { payments: Payment[] } }, null>( | ||
{ query }, | ||
{ headers: { cookie } }, | ||
); | ||
|
||
return data.profile.payments; | ||
} catch (e) { | ||
console.error(e); | ||
return null; | ||
} | ||
} | ||
|
||
export default loader; |
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