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
const express = require('express') | |
const app = express() | |
app.use(express.json()) | |
app.post('/checkout', async function (req, res) { | |
console.log(req.body) | |
res.send({ | |
url: 'https://example.com' | |
}) |
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
module.exports = { | |
// -- snip | |
serverMiddleware: [ | |
'~/server/api' | |
] | |
} |
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
<div v-if="error" class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative mb-8 checkout-error" role="alert"> | |
<strong class="font-bold">Something went wrong!</strong> | |
<span class="block sm:inline">Something went wrong checking you out, please try again</span> | |
</div> |
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
export default { | |
// -- snip | |
data () { | |
return { | |
error: null | |
} | |
}, | |
// -- snip | |
methods: { | |
async checkout (cart, e) { |
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
const cart = [{ | |
name: 'Nike Free Flynit', | |
description: 'Ideal for runs up to 3 miles, the Nike Free RN Flyknit 3.0 delivers a lace-free design so you can slip in and hit your stride.', | |
amount: 110, | |
image: '/images/product-1.jpg', | |
cartID: '45429317-eaf5-4c93-b0cd-bd2a8ffe26b0', | |
quantity: 1 | |
}] |
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
// -- snip | |
async checkout (cart, e) { | |
e.preventDefault() | |
try { | |
const res = await axios.post('/api/v1/checkout', cart, { | |
timeout: 1000 | |
}) | |
global.location.replace(res.data.url) | |
} catch (e) { | |
console.log('Something went wrong', e) |
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
import axios from 'axios' | |
// -- snip | |
export default { | |
// -- snip | |
methods: { | |
checkout (cart, e) { | |
e.preventDefault() | |
} | |
} |
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
<button class="btn mt-4" @click="creditCartCheckout()"> | |
Checkout | |
</button> |