stripehandler

package
v0.0.0-...-e74d533 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2024 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ReturnStatus

type ReturnStatus struct {
	Status        string `json:"status"`
	CustomerEmail string `json:"customer_email"`
	FaucetPackage []byte `json:"faucet_package"`
	Recipient     string `json:"recipient"`
	Quantity      int64  `json:"quantity"`
}

ReturnStatus represents the response status and data returned by the client.

type StripeHandler

type StripeHandler struct {
	Key           string           // The API key for the Stripe account.
	ProductID     string           // The ID of the price associated with the product.
	DefaultAmount int64            // The default amount for the product.
	WebhookSecret string           // The secret used to verify Stripe webhook events.
	Storage       *storage.Storage // The storage instance for the faucet.
	Faucet        *faucet.Faucet   // The faucet instance.
	SessionLock   sync.RWMutex     // The lock for the session.
}

StripeHandler represents the configuration for the stripe a provider for handling Stripe payments.

func NewStripeClient

func NewStripeClient(key, productID, webhookSecret string, defaultAmount int64, faucet *faucet.Faucet, storage *storage.Storage) (*StripeHandler, error)

NewStripeClient creates a new instance of the StripeHandler struct with the provided parameters. It sets the Stripe API key, price ID, webhook secret, minimum quantity, maximum quantity, and default amount. Returns a pointer to the created StripeHandler.

func (*StripeHandler) CreateCheckoutSession

func (s *StripeHandler) CreateCheckoutSession(defaultAmount int64, to, returnURL, referral string) (*stripe.CheckoutSession, error)

CreateCheckoutSession creates a new Stripe checkout session. It takes the defaultAmount, to, and referral as parameters and returns a pointer to a stripe.CheckoutSession and an error. The defaultAmount parameter specifies the default quantity for the checkout session. The to parameter is the client reference ID for the checkout session. The referral parameter is the referral URL for the checkout session. The function constructs a stripe.CheckoutSessionParams object with the provided parameters and creates a new session using the session.New function. If the session creation is successful, it returns the session pointer, otherwise it returns an error.

func (*StripeHandler) HandleWebhook

func (s *StripeHandler) HandleWebhook(apiData *apirest.APIdata, sig string) (string, error)

HandleWebhook handles the incoming webhook event from Stripe. It takes the API data and signature as input parameters and returns the session ID and an error (if any). The request body and Stripe-Signature header are passed to ConstructEvent, along with the webhook signing key. If the event type is "checkout.session.completed", it unmarshals the event data into a CheckoutSession struct and returns the session ID. Otherwise, it returns an empty string.

func (*StripeHandler) RegisterHandlers

func (s *StripeHandler) RegisterHandlers(api *apirest.API)

Register the handlers URLs

func (*StripeHandler) RetrieveCheckoutSession

func (s *StripeHandler) RetrieveCheckoutSession(sessionID string) (*ReturnStatus, error)

RetrieveCheckoutSession retrieves a checkout session from Stripe by session ID. It returns a ReturnStatus object and an error if any. The ReturnStatus object contains information about the session status, customer email, faucet package, recipient, and quantity.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL