Ecosyste.ms: Packages

An open API service providing package, version and dependency metadata of many open source software ecosystems and registries.

Top 8.2% on proxy.golang.org

proxy.golang.org : github.com/andrewpillar/stripeutil

package stripeutil provides some utility functions and data structures for working with the Stripe API for builing a SaaS application. This provides simple ways of creating Customers and Subscriptions, and storing them in a user defined data store along with their PaymentMethods and Invoices. This also provides a simple way of handling webhook events that are emitted from Stripe. stripeutil.Stripe is the main way to interact with the Stripe API. This is supposed to be used along with the stripeutil.Store interface which allows for storing the resources retrieved from Stripe. Below is a brief example as to how this library would be used to implement a subscription flow, the above code will first lookup the customer via the given stripeutil.Store implementation we pass. If a customer cannot be found then one is created in Stripe with the given email address and subsequently stored, before being returned. After this, we then retrieve the given payment method from Stripe, and pass this, along with the customer to the Subscribe call. We also specify the request parameters we wish to have set when creating a subscription in Stripe. Under the hood, stripeutil.Stripe will do the following when Subscribe is called, - Retrieve the subscription for the given customer from the underlying store - Attach the given payment method to the given customer - Update the customer's default payment method to what was given - Store the given payment method in the underlying store - Return the subscription for the given customer, if one was found otherwise... - ...a new subscription is created for the customer, and returned if the invoice status is valid And below is how a cancellation flow of a subscription would work with this library, with the above, we lookup the customer similar to how we did before, and pass them to the Unsubscribe call. This will update the customer's subscription to cancel at the end period, and update the subscription in the underlying store. However, if the customer's subscription cannot be found in the underlying store, or is not valid then nothing happens and nil is returned. stripeutil.Store is an interface that allows for storing the resources retrieved from Stripe. An implementation of this interface for PostgreSQL comes with this library out of the box. stripeutil.Stripe, depends on this interface for storing the customer, invoice, and subscription invoices during the Subscribe flow. stripeutil.Stripe is what is primarily used for interfacing with the Stripe API. This depends on the stripeutil.Store interface, as previously mentioned, for storing the resources retrieved from Stripe. stripeutil.Params allows for specifying the request parameters to set in the body of the request sent to Stripe. This is encoded to x-www-url-formencoded, when sent in a request, for example, would be encoded to, stripeutil.Stripe has a Post method that accepts a stripeutil.Params argument, this can be used for making more explicit calls to Stripe, the returned *http.Response can be used as usual. stripeutil.Client is a thin HTTP client for the Stripe API. All HTTP requests made through this client will be configured to talk to Stripe. This is embedded inside of stripeutil.Stripe so you can do stuff like, for example, to get the customers you have. A new client can be created via stripeutil.NewClient, and through this you can configured which version of the Stripe API to use, If using an older/newer version of the Stripe API this way then it is highly recommended that you do not use stripeutil.Stripe and instead perform all interactions via stripeutil.Client. This is because stripeutil.Stripe relies on the stripe/stripe-go SDK, so the versions may not match if you do this.

Registry - Source - Documentation - JSON
purl: pkg:golang/github.com/andrewpillar/stripeutil
Keywords: go, stripe, stripe-api
License: MIT
Latest release: almost 3 years ago
First release: almost 3 years ago
Namespace: github.com/andrewpillar
Stars: 3 on GitHub
Forks: 0 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 21 days ago

    Loading...
    Readme
    Loading...