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

Add an option for crypto-checkout #727

Merged
merged 2 commits into from
Mar 21, 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ beforeEach(() => {
browserEnv.restore();
});

test('checkout method should return a PromiEvent', () => {
test('checkout method should return a PromiEvent', async () => {
const magic = createMagicSDK();

magic.nft.request = jest.fn().mockReturnValue({
status: 'complete',
viewInWallet: true,
status: 'processed',
});

magic.nft.checkout({
const response = await magic.nft.checkout({
contractId: '1cd4cfe8-b997-466e-8b0d-ff1177222ba4',
contractAddress: '0x375625833431b22623ce222e55b1cd15a459ba49',
tokenId: '1',
Expand All @@ -22,8 +21,44 @@ test('checkout method should return a PromiEvent', () => {
quantity: 1,
});

expect(response.status).toBe('processed');

const requestPayload = magic.nft.request.mock.calls[0][0];
console.log(requestPayload.params);

expect(requestPayload.method).toBe('magic_nft_checkout');
expect(requestPayload.params).toMatchObject([
{
contractId: '1cd4cfe8-b997-466e-8b0d-ff1177222ba4',
contractAddress: '0x375625833431b22623ce222e55b1cd15a459ba49',
tokenId: '1',
name: 'NFT Checkout Test',
imageUrl: 'https://nft-cdn.alchemy.com/matic-mumbai/382ceb42f28fb4df0d12897d5d433084',
quantity: 1,
},
]);
});

test('checkout method can add isCryptoCheckoutEnabled to request payload', async () => {
const magic = createMagicSDK();

magic.nft.request = jest.fn().mockReturnValue({
status: 'processed',
});

const response = await magic.nft.checkout({
contractId: '1cd4cfe8-b997-466e-8b0d-ff1177222ba4',
contractAddress: '0x375625833431b22623ce222e55b1cd15a459ba49',
tokenId: '1',
name: 'NFT Checkout Test',
imageUrl: 'https://nft-cdn.alchemy.com/matic-mumbai/382ceb42f28fb4df0d12897d5d433084',
quantity: 1,
isCryptoCheckoutEnabled: true,
});

expect(response.status).toBe('processed');

const requestPayload = magic.nft.request.mock.calls[0][0];

expect(requestPayload.method).toBe('magic_nft_checkout');
expect(requestPayload.params).toMatchObject([
{
Expand All @@ -33,6 +68,7 @@ test('checkout method should return a PromiEvent', () => {
name: 'NFT Checkout Test',
imageUrl: 'https://nft-cdn.alchemy.com/matic-mumbai/382ceb42f28fb4df0d12897d5d433084',
quantity: 1,
isCryptoCheckoutEnabled: true,
},
]);
});
4 changes: 3 additions & 1 deletion packages/@magic-sdk/types/src/modules/nft-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type NFTResponseStatus = 'cancelled' | 'processed' | 'declined' | 'expired';
export type NFTResponseStatus = 'cancelled' | 'pending' | 'processed' | 'declined' | 'expired';

export type NFTResponse = {
status: NFTResponseStatus;
Expand Down Expand Up @@ -44,6 +44,8 @@ export interface NFTCheckoutRequest {
imageUrl: string;
quantity?: number; // default is 1
walletAddress?: string; // default is user's wallet address
// If enabled, the user will be able to pay with crypto. the default is false
isCryptoCheckoutEnabled?: boolean;
}

export type NFTCheckoutResponse = NFTResponse;
Expand Down
Loading