-
Notifications
You must be signed in to change notification settings - Fork 2
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
Crypto payments #284
Open
AlanBreck
wants to merge
14
commits into
main
Choose a base branch
from
crypto-payments
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Crypto payments #284
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1346478
chore(deps): update dependency @sveltejs/adapter-node to v5.2.6 (#278)
renovate[bot] 29fc028
chore(deps): update dependency tailwindcss to v3.4.13 (#280)
renovate[bot] 9214629
fix(deps): update @brave/leo digest to c56905a (#277)
renovate[bot] 82c2802
chore(deps): update dependency @sveltejs/kit to v2.7.0 (#279)
renovate[bot] c5f953f
chore(deps): update @brave/leo digest to 24fc785 (#282)
renovate[bot] fa82bb4
chore(deps): update aws-actions/amazon-ecs-render-task-definition dig…
renovate[bot] 948a912
WIP: feat: adds crypto payments
AlanBreck 5b77109
WIP
AlanBreck d4287b4
crypto UI wip
AlanBreck 2d99161
fixup! crypto UI wip
AlanBreck 8b8a08e
adds cancellation and success for radom
AlanBreck 98d8f4d
updates readme
AlanBreck fc9a209
set chargeCustomerNetworkFee to false
AlanBreck c66bf6e
fixup! WIP
AlanBreck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,166 @@ | ||
import { PUBLIC_ASSETS_PATH } from '$env/static/public'; | ||
import { describe, expect, test } from 'vitest'; | ||
import { CreateCheckoutSessionError, formatCheckoutSessionParams } from './checkoutSession'; | ||
import { radomAdapter } from './providers/radom'; | ||
import { stripeAdapter } from './providers/stripe'; | ||
|
||
const requestBody = { | ||
items: [ | ||
{ id: 'clwsmtxpp0000zo6dwkmvu76n', quantity: '1' }, | ||
{ id: 'clwsmtxrj0004zo6dsqvo4b7t', quantity: '1' } | ||
], | ||
shippingAddress: { | ||
AlanBreck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
name: 'John Smith', | ||
address1: '123 Main Street', | ||
city: 'Springfield', | ||
zip: '12345', | ||
country_code: 'US', | ||
state_code: 'IL', | ||
calling_code: 'US+1', | ||
phone: '' | ||
} | ||
}; | ||
|
||
test('Fails when no order items are included in request body', async () => { | ||
const improperRequestBody = structuredClone(requestBody); | ||
improperRequestBody.items = []; | ||
|
||
await expect(async () => | ||
formatCheckoutSessionParams(improperRequestBody, stripeAdapter) | ||
).rejects.toThrowError(CreateCheckoutSessionError.EMPTY_CART); | ||
}); | ||
|
||
test('Fails when shipping data is malformed', async () => { | ||
const improperRequestBody = structuredClone(requestBody) as any; | ||
delete improperRequestBody.shippingAddress.address1; | ||
|
||
await expect(async () => | ||
formatCheckoutSessionParams(improperRequestBody, stripeAdapter) | ||
).rejects.toThrowError(CreateCheckoutSessionError.INVALID_SHIPPING_ADDRESS); | ||
}); | ||
|
||
describe('Stripe', () => { | ||
const expectedStripeCheckoutSessionData = { | ||
line_items: [ | ||
{ | ||
price_data: { | ||
currency: 'USD', | ||
product_data: { | ||
name: 'Brave | BAT Desk Mat', | ||
images: [ | ||
`${PUBLIC_ASSETS_PATH}/b2847030ab3d174e3788ebf17ebc9e90ef26db4bbba6730b91039912666d078a.png` | ||
], | ||
metadata: { printfulVariantId: '3826891072', baseVariantId: 14942 } | ||
}, | ||
unit_amount: 3500 | ||
}, | ||
quantity: 1 | ||
}, | ||
{ | ||
price_data: { | ||
currency: 'USD', | ||
product_data: { | ||
name: 'Brave Lion Fleece Zip Up Hoodie / 2XL', | ||
images: [ | ||
`${PUBLIC_ASSETS_PATH}/a996ac2653c1f945483cb2bdabb72e232de591b913148aa708107d4ac9d44053.png` | ||
], | ||
metadata: { printfulVariantId: '3576357951', baseVariantId: 15042 } | ||
}, | ||
unit_amount: 4595 | ||
}, | ||
quantity: 1 | ||
} | ||
], | ||
mode: 'payment', | ||
success_url: 'http://localhost:5173/success/{CHECKOUT_SESSION_ID}/?provider=stripe', | ||
cancel_url: 'http://localhost:5173/cart/?session_id={CHECKOUT_SESSION_ID}&provider=stripe', | ||
allow_promotion_codes: true, | ||
shipping_options: [ | ||
{ | ||
shipping_rate_data: { | ||
display_name: 'Standard (Estimated delivery: Jul 24-Jul 29)', | ||
type: 'fixed_amount', | ||
metadata: { printful_shipping_rate_id: 'STANDARD' }, | ||
fixed_amount: { amount: 399, currency: 'USD' }, | ||
delivery_estimate: { | ||
minimum: { unit: 'day', value: 4 }, | ||
maximum: { unit: 'day', value: 7 } | ||
} | ||
} | ||
} | ||
], | ||
invoice_creation: { enabled: true } | ||
}; | ||
|
||
test('Converts request body to Stripe checkout session data', async () => { | ||
expect(await formatCheckoutSessionParams(requestBody, stripeAdapter)).toMatchObject( | ||
expectedStripeCheckoutSessionData | ||
); | ||
}); | ||
}); | ||
|
||
describe('Radom', () => { | ||
const expectedRadomCheckoutSessionData = { | ||
lineItems: [ | ||
{ | ||
itemData: { | ||
name: 'Brave | BAT Desk Mat', | ||
description: 'Quantity: 1', | ||
price: 35, | ||
imageUrl: | ||
'https://cdn.store.bravesoftware.com/b2847030ab3d174e3788ebf17ebc9e90ef26db4bbba6730b91039912666d078a.png', | ||
currency: 'USD' | ||
} | ||
}, | ||
{ | ||
itemData: { | ||
name: 'Brave Lion Fleece Zip Up Hoodie / 2XL', | ||
description: 'Quantity: 1', | ||
price: 45.95, | ||
imageUrl: | ||
'https://cdn.store.bravesoftware.com/a996ac2653c1f945483cb2bdabb72e232de591b913148aa708107d4ac9d44053.png', | ||
currency: 'USD' | ||
} | ||
}, | ||
{ | ||
itemData: { | ||
name: 'Standard (Estimated delivery: Jul 24-Jul 29)', | ||
price: 3.99, | ||
currency: 'USD' | ||
} | ||
} | ||
], | ||
currency: 'USD', | ||
gateway: { | ||
managed: { | ||
methods: [ | ||
{ | ||
network: 'SepoliaTestnet', | ||
token: '0x5D684d37922dAf7Aa2013E65A22880a11C475e25', | ||
discountPercentOff: 0.2 | ||
}, | ||
{ network: 'SepoliaTestnet', token: '0xa4fCE8264370437e718aE207805b4e6233638b9E' }, | ||
{ network: 'SepoliaTestnet', token: '0xE50d86c6dE38F9754f6777d2925377564Bf79482' }, | ||
{ | ||
network: 'PolygonTestnet', | ||
token: '0xd445cAAbb9eA6685D3A512439256866563a16E93', | ||
discountPercentOff: 0.2 | ||
}, | ||
{ network: 'PolygonTestnet', token: '0x8f8b1972eea072C3C228EbE8f9FEADe03927D70F' }, | ||
{ network: 'PolygonTestnet', token: '0x70BE8802e2F3C6652B7e0814B478f66Ec52d9d88' }, | ||
{ network: 'SolanaDevnet', token: '4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU' } | ||
] | ||
} | ||
}, | ||
successUrl: 'http://localhost:5173/success/{CHECKOUT_SESSION_ID}/?provider=radom', | ||
cancelUrl: 'http://localhost:5173/cart/?session_id={CHECKOUT_SESSION_ID}&provider=radom', | ||
chargeCustomerNetworkFee: true, | ||
customizations: { allowDiscountCodes: true } | ||
}; | ||
|
||
test('Converts request body to Radom checkout session data', async () => { | ||
expect(await formatCheckoutSessionParams(requestBody, radomAdapter)).toMatchObject( | ||
expectedRadomCheckoutSessionData | ||
); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These were already previously audited - no concerns with the additional dependencies.