Solid wrapper for Stripe.js

Overview

solid-stripe

Solid wrapper for Stripe.js

Installation

To configure your project add these packages:

pnpm add @stripe/stripe-js solid-stripe

In your server-side app, add the official server-side/node version of Stripe too:

pnpm add stripe

We will use solid-start in all of the examples.

Docs

Set up Stripe

Add your private and public keys to your environment:

VITE_STRIPE_PUBLIC_KEY=pk_test_...
VITE_STRIPE_SECRET_KEY=sk_test_...

In your payment page, initialize Stripe and add a <StripeProvider> component:

import { createSignal, onMount, Show } from 'solid-js';

const App = () => {
  const [stripe, setStripe] = createSignal<Stripe | null>(null);

  onMount(async () => {
    const result = await loadStripe(import.meta.env.VITE_STRIPE_PUBLIC_KEY);
    setStripe(result);
  });

  return (
    <Show when={stripe()} fallback={<div>Loading stripe...</div>}>
      <StripeProvider stripe={stripe()}>
        {/* this is where your Stripe components go */}
      </StripeProvider>
    </Show>
  );
};

Creating a payment intent

Before making a charge, Stripe should be notified by creating a payment intent. This must happen server-side to avoid anyone tampering with the amount.

Let's add a src/lib/create-payment-intent.js to our solid-start project to create a payment intent:

import Stripe from 'stripe';

const stripe = new Stripe(import.meta.env.VITE_STRIPE_SECRET_KEY);

export default function createPaymentIntent() {
  return stripe.paymentIntents.create({
    amount: 1069,
    currency: 'eur',
    automatic_payment_methods: { enabled: true },
  });
}

Accepting payments

There are several types of payment you can accept:

You might also like...

Solid.js library adding a services layer for global shared state.

Solid.js library adding a services layer for global shared state.

Solid Services Services are "global" objects useful for features that require shared state or persistent connections. Example uses of services might i

Dec 30, 2022

solid material ui port (ported from blazor port)

solid-material-ui solid material ui port (porting from blazor port) In preparation for solid hack Turbo Mono-repository is used for component package

Apr 30, 2022

Solid hooks for Firebase v9.

solid-firebase Solid hooks for Firebase. Quick start Install it: yarn add firebase solid-firebase Configure firebase app: import { render } from 'soli

Dec 23, 2022

[WIP] A solid directive for adding colorful shadows to images.

solid-cosha A solid directive for adding colorful shadows to images (based on cosha). Quick start Install it: yarn add solid-cosha Use it: import { co

Feb 3, 2022

Add cmd+k interface to your solid site

solid-ninja-keys Add cmd+k interface to your solid site. Built on top of ninja-keys. Quick start Install it: yarn add solid-ninja-keys Use it: import

Dec 19, 2022

A helper to use immer as Solid.js Signal to drive state

Solid Immer A helper to use immer as Solid.js Signal to drive state. Installation $ npm install solid-immer Usage Use createImmerSignal to create a im

Nov 22, 2022

Simple Solid primitive unit test utility.

solid-primitive-test-util Simple Solid primitive unit test utility. Install pnpm add solid-primitive-test-util -D Example Basic Usage Let's say we hav

Mar 21, 2022

Adds full-text search to Community Solid Server. Powered by atomic-server

Solid Search for Community Solid Server This is an extension / plugin for the Community Solid Server. It adds full-text search to the Community Solid

Jun 6, 2022

Melon.js game engine bindings for Solid

Melon Solid This project fuses the awesome frameworks Melon.js (for game development) and Solid.js (for making websites). By combining them together y

Oct 4, 2022
Comments
  • TypeError: EventEmitter is not a constructor at new Stripe

    TypeError: EventEmitter is not a constructor at new Stripe

    @wobsoriano First of all, thank you for this library! I'm getting the following error though and I'm not too sure why?

    Maybe you can help me: image

    I have a feeling its to do with the server function not running on the server. ~/utils/create-payment-intent.ts

    import Stripe from 'stripe'
    
    const stripe = new Stripe(import.meta.env.VITE_STRIPE_SECRET_KEY, {
      apiVersion: '2022-08-01',
    })
    
    export default function createPaymentIntent() {
      return stripe.paymentIntents.create({
        amount: 1069,
        currency: 'eur',
        automatic_payment_methods: { enabled: true },
      })
    }
    

    Have you ran into this issue before?

    Thanks in advance!

    opened by Sananes 1
Releases(v0.2.4)
Owner
Robert Soriano
[object Object]
Robert Soriano
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Generate Stripe-like API Documentation

Generate Stripe-like API Documentation Get Started Today Table of contents Usage Inputs Contributing Licence Usage Start by creating a documentation o

Theneo 12 Sep 15, 2022
A wee E-Commerce website powered by Stripe, Auth0, Strapi and Next.js

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Simo Edwin 66 Dec 19, 2022
A minimal e-commerce store using Gatsby, SANITY, Stripe, Use-Shopping-Cart and Netlify

?? Gatsby Starter Stripemart Like a supermarket but for Stripe. No ongoing monthly costs. Perfect for artists, creators and independent builders doing

Eric Howey 26 Nov 14, 2022
An Open Source Remix template that integrates Stripe Subscriptions, Social Authentication, Testing and a few more features. PostgreSQL version. Deploys to Fly.io

Live Demo · Twitter An open source Remix Stack that integrates Stripe Subscriptions, Social Authentication, Testing and a few more features. PostgreSQ

xo 25 Dec 7, 2022
An Open Source Remix template that integrates Stripe Subscriptions, Social Authentication, Testing and a few more features. SQLite version. Deploys to Fly.io

Live Demo · Twitter An Open Source Remix template that integrates Stripe Subscriptions, Social Authentication, Testing and a few more features. SQLite

xo 135 Dec 31, 2022
NextJS E-commerce starter kit with Sanity.io and Stripe API 🛍

?? Next.js Sanity E-commerce Starter Kit A Next.js E-commerce app with Sanity.io and Stripe API. Built with TailwindCSS framework & SASS CSS extension

Lougie Quisel 11 Dec 29, 2022
Generate meshes from signed distance functions and constructive solid geometry operations.

sdf-csg Generate meshes from signed distance functions and constructive solid geometry operations. This library is heavily based upon Inigo Quilez's 3

Rye Terrell 151 Oct 24, 2022