Skip to content

Commit

Permalink
Use new getStripePaymentIntent endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
scottyzen committed Mar 16, 2024
1 parent 47a8712 commit 7fb5a74
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 42 deletions.
23 changes: 0 additions & 23 deletions functions/stripe.ts

This file was deleted.

6 changes: 0 additions & 6 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@

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

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

[[headers]]
for = "/*.js"
Expand Down
17 changes: 5 additions & 12 deletions woonuxt_base/components/shopElements/StripeElement.vue
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
<script setup>
const { cart } = useCart();
import { GqlGetStripePaymentIntent } from '#gql';
const { stripe } = defineProps(['stripe']);
const emit = defineEmits(['elements']);
let elements = null;
const refreshStripeElements = async () => {
const totalForStripe = Math.round(parseFloat(cart.value?.rawTotal) * 100);
if (!stripe || !cart.value || !totalForStripe) return;
const { client_secret } = await fetch('/api/stripe', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ amount: totalForStripe }),
}).then((res) => res.json());
if (!stripe) return;
const { stripePaymentIntent } = await GqlGetStripePaymentIntent();
const stripeEl = document.getElementById('stripe-payment');
elements = stripe?.elements({ clientSecret: client_secret });
const elements = stripe?.elements({ clientSecret: stripePaymentIntent.clientSecret });
const payEl = elements?.create('payment', { layout: 'tabs' });
if (payEl && stripeEl) {
Expand All @@ -25,6 +17,7 @@ const refreshStripeElements = async () => {
}
};
const { cart } = useCart();
watch(
() => cart.value,
(newVal) => {
Expand Down
5 changes: 4 additions & 1 deletion woonuxt_base/composables/useAuth.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { GqlLogin, GqlLogout, GqlRegisterCustomer, GqlResetPasswordEmail, GqlGetOrders } from '#gql';
import type { RegisterCustomerInput } from '#gql';

export const useAuth = () => {
const { refreshCart } = useCart();

Expand Down Expand Up @@ -51,7 +54,7 @@ export const useAuth = () => {
};

// Register the user
const registerUser = async (userInfo: CreateAccountInput): Promise<{ success: boolean; error: any }> => {
const registerUser = async (userInfo: RegisterCustomerInput): Promise<{ success: boolean; error: any }> => {
isPending.value = true;
try {
await GqlRegisterCustomer({ input: userInfo });
Expand Down
3 changes: 3 additions & 0 deletions woonuxt_base/composables/useCart.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { GqlGetCart, GqlAddToCart, GqlUpDateCartQuantity, GqlEmptyCart, GqlChangeShippingMethod, GqlApplyCoupon, GqlRemoveCoupons } from '#gql';
import type { AddToCartInput } from '#gql';

/**
* @name useCart
* @description A composable that handles the cart in local storage
Expand Down
9 changes: 9 additions & 0 deletions woonuxt_base/queries/getStripePaymentIntent.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
query getStripePaymentIntent {
stripePaymentIntent {
amount
clientSecret
error
id
currency
}
}

0 comments on commit 7fb5a74

Please sign in to comment.