<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jonathan</title>
    <description>The latest articles on DEV Community by Jonathan (@jmkweb).</description>
    <link>https://dev.to/jmkweb</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F399007%2F703f65a0-b130-46cf-bea8-d2cb52fccba7.png</url>
      <title>DEV Community: Jonathan</title>
      <link>https://dev.to/jmkweb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jmkweb"/>
    <language>en</language>
    <item>
      <title>Integrating Stripe Payment Elements in Nuxt 3</title>
      <dc:creator>Jonathan</dc:creator>
      <pubDate>Wed, 19 Jun 2024 14:36:31 +0000</pubDate>
      <link>https://dev.to/jmkweb/integrating-stripe-payment-elements-in-nuxt-3-5d2j</link>
      <guid>https://dev.to/jmkweb/integrating-stripe-payment-elements-in-nuxt-3-5d2j</guid>
      <description>&lt;p&gt;This guide will show you how to integrate Stripe's Payment Element into a Nuxt 3 application to process payments for purchasing a cat. We'll cover setting up Stripe on both the client and server sides, and handling the payment process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A Nuxt 3 application set up.&lt;/li&gt;
&lt;li&gt;Stripe account with API keys (STRIPE_SECRET_KEY and STRIPE_PUBLIC_KEY).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1 - Install Stripe
&lt;/h2&gt;

&lt;p&gt;Install the necessary Stripe packages:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install @stripe/stripe-js stripe&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2 - Configure Environment Variables
&lt;/h2&gt;

&lt;p&gt;Add your Stripe API keys to the .env file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NUXT_STRIPE_PUBLIC_KEY=your_public_key_here
STRIPE_SECRET_KEY=your_secret_key_here
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: Create a Server API Endpoint
&lt;/h2&gt;

&lt;p&gt;Create an endpoint to handle the creation of PaymentIntents. Create a file in this directory:&lt;code&gt;server/api/stripe.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Stripe from 'stripe';

export default defineEventHandler(async (event) =&amp;gt; {
  const body = await readBody(event);
  const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);

  try {
    const paymentIntent = await stripe.paymentIntents.create({
      amount: Number(body.amount), // Amount in cents
      currency: 'usd',
      automatic_payment_methods: { enabled: true },
    });

    return {
      client_secret: paymentIntent.client_secret
    };
  } catch (error) {
    console.error('Error creating PaymentIntent:', error);
    throw createError({
      statusCode: 500,
      statusMessage: 'Error creating payment intent',
    });
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 4: Set Up the Basic Nuxt Page
&lt;/h2&gt;

&lt;p&gt;Create a component for purchasing a cat that integrates the Payment Element and handles the payment process.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pages/purchase/[catId].vue&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;template&amp;gt;
  &amp;lt;div&amp;gt;
    &amp;lt;h1&amp;gt;Purchase Cat {{ catId }}&amp;lt;/h1&amp;gt;
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt;Select your favorite cat and proceed to checkout.&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;

    &amp;lt;!-- Payment form for Stripe Payment Element --&amp;gt;
    &amp;lt;form @submit.prevent="pay"&amp;gt;
      &amp;lt;div class="border border-gray-500 p-2 rounded-sm" id="payment-element"&amp;gt;&amp;lt;/div&amp;gt;
      &amp;lt;p id="payment-error" role="alert" class="text-red-700 text-center font-semibold"&amp;gt;&amp;lt;/p&amp;gt;
      &amp;lt;button
        :disabled="isProcessing"
        type="submit"
        class="mt-4 bg-gradient-to-r from-[#FE630C] to-[#FF3200] w-full text-white text-[21px] font-semibold p-1.5 rounded-full"
        :class="isProcessing ? 'opacity-70' : 'opacity-100'"
        id="processing"
        aria-label="loading"
      &amp;gt;
        &amp;lt;p v-if="isProcessing"&amp;gt;I'm processing payment&amp;lt;/p&amp;gt;
        &amp;lt;div v-else&amp;gt;Buy Now&amp;lt;/div&amp;gt;
      &amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/template&amp;gt;

&amp;lt;script setup&amp;gt;
import { ref, onMounted } from 'vue';
import { useRoute } from 'vue-router';
import { loadStripe } from '@stripe/stripe-js';
import { useRuntimeConfig } from '#app';

// Accessing environment variables
const config = useRuntimeConfig();
const stripePk = config.public.STRIPE_PUBLIC_KEY;

const route = useRoute();
const catId = route.params.catId; // Get the cat ID from the URL
const isProcessing = ref(false);
let stripe;
let elements;
let paymentElement;
let clientSecret;

const total = 2000; // Example fixed amount for purchasing a cat in cents ($20)

onMounted(async () =&amp;gt; {
  await initializeStripe();
});

const initializeStripe = async () =&amp;gt; {
  stripe = await loadStripe(stripePk);

  // Create a payment intent on your server
  const res = await fetch('/api/stripe', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      amount: total // Fixed amount in cents
    })
  });

  const result = await res.json();
  clientSecret = result.client_secret;

  elements = stripe.elements({ clientSecret });

  // Create and mount the Payment Element
  paymentElement = elements.create('payment');
  paymentElement.mount('#payment-element');

  isProcessing.value = false;
};

const pay = async () =&amp;gt; {
  isProcessing.value = true;

  try {
    const { error } = await stripe.confirmPayment({
      elements,
      confirmParams: {
        payment_method_data: {
          billing_details: {
            name: 'John Doe',
            email: 'john.doe@example.com',
            phone: '+1234567890',
          },
        },
      },
      redirect: 'if_required' // Stay on the same page unless redirect is necessary
    });

    if (error) {
      console.error('Payment error:', error);
      document.querySelector('#payment-error').textContent = error.message;
      isProcessing.value = false;
    } else {
      console.log('Payment succeeded');
      // Handle post-payment success actions, like showing a success message
    }
  } catch (error) {
    console.error('Payment processing error:', error);
    document.querySelector('#payment-error').textContent = 'An error occurred. Please try again.';
    isProcessing.value = false;
  }
};
&amp;lt;/script&amp;gt;

&amp;lt;style scoped&amp;gt;
/* Add any styles you want to apply to the purchase page */
&amp;lt;/style&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This tutorial shows how to integrate Stripe's Payment Element into a Nuxt 3 application for a fictional online cat purchase scenario. You can further customize the form, handle additional payment methods, or expand functionality as needed.&lt;/p&gt;

&lt;p&gt;For more detailed information, refer to the Stripe Payment Element documentation.&lt;/p&gt;

</description>
      <category>stripe</category>
      <category>nuxt</category>
      <category>vue</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Arcanium.art v1.0 Launch</title>
      <dc:creator>Jonathan</dc:creator>
      <pubDate>Thu, 23 May 2024 16:08:47 +0000</pubDate>
      <link>https://dev.to/jmkweb/arcaniumart-v10-launch-491d</link>
      <guid>https://dev.to/jmkweb/arcaniumart-v10-launch-491d</guid>
      <description>&lt;p&gt;After what felt like an eternity in Beta, I'm thrilled to roll out &lt;a href="https://arcanium.art/"&gt;Arcanium.art&lt;/a&gt; version 1.0 to the masses. It's been a rollercoaster of bugs, eureka moments, and a fair share of coffee-fueled late nights. But now, it's ready for prime time!&lt;/p&gt;

&lt;p&gt;For those out of the loop—and let's be honest, that’s probably most of you—Arcanium is a Stable Diffusion art generator that prides itself on a slick user experience and foolproof simplicity. It survived a grueling six months in Alpha, where I juggled user feedback, tackled bugs, occasionally threw my hands up in frustration, took some sanity breaks, and then dove back in. Just your typical startup drama.&lt;/p&gt;

&lt;p&gt;The loudest piece of feedback was clear: “Let me dip my toes in before I dive into the premium pool!” So, I’ve tweaked a few knobs and buttons to make that happen:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enjoy 5 free credits refreshed daily to get your art fix.&lt;/li&gt;
&lt;li&gt;Enter our Community Showcase competition to snag 250 credits—on the house.&lt;/li&gt;
&lt;li&gt;Our new Discord Bot is playing cop, keeping the showcase entries clean and the art generation orderly.&lt;/li&gt;
&lt;li&gt;We've spruced up the app to feel more like, well, an app, and less like a secret society.&lt;/li&gt;
&lt;li&gt;Choose between flaunting your creations publicly or keeping them under wraps.&lt;/li&gt;
&lt;li&gt;Upgraded models and sharper, more curated LoRA’s.&lt;/li&gt;
&lt;li&gt;Keep Plus membership is a steal at just $9 for unlimited access.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As always, I’m here, learning on the fly and tweaking as we go. Is a product ever really finished, or just less beta?&lt;/p&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>beta</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
