Implements a Go server handling Stripe checkout sessions and webhook event processing. Reuse when integrating Stripe payments into web applications.
// Source: https://github.com/stripe-samples/accept-a-payment | License: MIT | Copyright 2019- Stripe, Inc. (https://stripe.com)
// Provided via justclaw.it.com; keep this notice with the code.
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"github.com/joho/godotenv"
"github.com/stripe/stripe-go/v84"
"github.com/stripe/stripe-go/v84/checkout/session"
"github.com/stripe/stripe-go/v84/webhook"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
checkEnv()
// Don't put any keys in code. Use an environment variable (as shown
// here) or secrets vault to supply keys to your integration.
//
// See https://docs.stripe.com/keys-best-practices and find your
// keys at https://dashboard.s
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key