Skip to content

Commit

Permalink
stripe-3d
Browse files Browse the repository at this point in the history
  • Loading branch information
scottyzen committed Mar 9, 2024
1 parent 1a73b34 commit 51d4b0e
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 38 deletions.
17 changes: 17 additions & 0 deletions functions/stripe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const stripe = require('stripe')('sk_test_51KoqfeLqZEQtkS6nsr2zulvLqgTfgozVLzNFGpc2NPPEdCMbd2ZXL1QaPGLHc0PyhZ3SbLN8D9RWouiHz6VwX6l300HHCwEO1h');

exports.handler = async (event, context) => {
console.log('LAMBDA FUNCTION RAN', event, context);
try {
const paymentIntent = await stripe.paymentIntents.create({
amount: 1099,
currency: 'usd',
});
return {
statusCode: 200,
body: JSON.stringify({ ...paymentIntent }),
};
} catch (error) {
console.log(error);
}
};
8 changes: 7 additions & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

[build]
command = "nuxi generate"
functions = "functions"

[[redirects]]
from = '/api/*'
to = '/.netlify/functions/:splat'
status = 200

[[headers]]
for = "/*.js"
Expand All @@ -28,4 +34,4 @@
[[headers]]
for = "/*.webp"
[headers.values]
Cache-Control = "public, max-age=31536000, immutable"
Cache-Control = "public, max-age=31536000, immutable"
55 changes: 33 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"dependencies": {
"@stripe/stripe-js": "^2.4.0",
"@vueform/slider": "^2.1.10",
"@vueuse/core": "^10.9.0"
"@vueuse/core": "^10.9.0",
"stripe": "^14.19.0"
},
"devDependencies": {
"@nuxt/image": "^1.3.0",
Expand Down
2 changes: 1 addition & 1 deletion woonuxt_base/components/filtering/OnSaleFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const checkboxClicked = (e) => {

<template>
<div>
<div class="flex font-semibold mt-8 leading-none justify-between items-center" @click="isOpen = !isOpen">
<div class="cursor-pointer flex font-semibold mt-8 leading-none justify-between items-center" @click="isOpen = !isOpen">
<span>Sale Products Only</span>
<Icon name="ion:chevron-down-outline" class="transform" :class="isOpen ? 'rotate-180' : ''" />
</div>
Expand Down
2 changes: 1 addition & 1 deletion woonuxt_base/components/filtering/StarRatingFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const radioClicked = (rating: string): void => {

<template>
<div>
<div class="flex font-semibold mt-8 leading-none justify-between items-center" @click="isOpen = !isOpen">
<div class="cursor-pointer flex font-semibold mt-8 leading-none justify-between items-center" @click="isOpen = !isOpen">
<span>{{ $t('messages.shop.rating') }}</span>
<Icon v-show="isOpen" name="ion:chevron-up-outline" />
<Icon v-show="!isOpen" name="ion:chevron-down-outline" />
Expand Down
38 changes: 26 additions & 12 deletions woonuxt_base/pages/checkout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,52 @@ const isInvalidEmail = ref(false);
const instanceOptions = ref({});
const elementsOptions = ref({});
const cardOptions = ref({ hidePostalCode: true });
const stripeLoaded = ref(false);
const card = ref();
const elms = ref();
const stripe = stripeKey ? await loadStripe(stripeKey) : null;
console.log('stripe', stripe);
// Initialize Stripe.js
onBeforeMount(() => {
if (query.cancel_order) window.close();
if (!stripeKey) {
console.error('Stripe key is not set');
return;
}
const stripePromise = loadStripe(stripeKey);
stripePromise.then(() => {
stripeLoaded.value = true;
});
});
const payNow = async () => {
buttonText.value = t('messages.general.processing');
// paymentIntents
const { client_secret } = await fetch('/api/stripe', {
method: 'GET',
headers: { 'Content-Type': 'application/json' },
}).then((res) => res.json());
console.log({ client_secret });
try {
if (orderInput.value.paymentMethod === 'stripe') {
const cardElement = card.value.stripeElement;
const { source } = await elms.value.instance.createSource(cardElement);
console.log({ cardElement });
// const { source } = await elms.value.instance.createSource(cardElement);
const { error, paymentIntent } = await stripe.confirmCardPayment(client_secret, {
payment_method: {
card: cardElement,
billing_details: {
name: 'Jenny Rosen',
email: '[email protected]',
},
},
});
console.log({ error, paymentIntent });
orderInput.value.metaData.push({ key: '_stripe_source_id', value: source.id });
orderInput.value.transactionId = source.created?.toString() || '';
}
} catch (error) {
console.error('Error:', error);
buttonText.value = t('messages.shop.placeOrder');
}
proccessCheckout();
// proccessCheckout();
};
const checkEmailOnBlur = (email) => {
Expand Down

0 comments on commit 51d4b0e

Please sign in to comment.