Skip to content

Instantly share code, notes, and snippets.

View Joe8Bit's full-sized avatar
👋
@banked is hiring! Reach out!

Joe Pettersson Joe8Bit

👋
@banked is hiring! Reach out!
View GitHub Profile
@Joe8Bit
Joe8Bit / api.js
Created March 3, 2020 20:41
Example store - express basic
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'
})
@Joe8Bit
Joe8Bit / nuxt.js
Created March 3, 2020 20:40
Example store - nuxt config
module.exports = {
// -- snip
serverMiddleware: [
'~/server/api'
]
}
@Joe8Bit
Joe8Bit / error.html
Created March 3, 2020 19:18
Example store - Error HTML
<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>
@Joe8Bit
Joe8Bit / checkout.js
Created March 3, 2020 19:17
Example store - error handling
export default {
// -- snip
data () {
return {
error: null
}
},
// -- snip
methods: {
async checkout (cart, e) {
@Joe8Bit
Joe8Bit / example.js
Last active March 4, 2020 08:41
Example store - cart example
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
}]
@Joe8Bit
Joe8Bit / checkout.js
Last active March 4, 2020 08:40
Example store - API call
// -- 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)
@Joe8Bit
Joe8Bit / checkout.js
Created March 3, 2020 19:13
Example store - checkout implementation
import axios from 'axios'
// -- snip
export default {
// -- snip
methods: {
checkout (cart, e) {
e.preventDefault()
}
}
@Joe8Bit
Joe8Bit / banked-button.css
Created March 3, 2020 19:11
Example store - Banked button CSS
.btn-banked {
@apply text-white text-xl;
background: #000;
}
@Joe8Bit
Joe8Bit / banked-button.html
Last active March 3, 2020 21:02
Example store - Banked button
<button class="btn mt-4" @click="creditCartCheckout()">
Checkout
</button>
<button class="btn btn-banked mt-4" @click="checkout(cart, $event)">
Checkout with Banked :
</button>
@Joe8Bit
Joe8Bit / cc.html
Last active March 3, 2020 21:03
Example store - Credit Card Checkout
<button class="btn mt-4" @click="creditCartCheckout()">
Checkout
</button>