Download the PHP package craftcms/stripe without Composer

On this page you can find all versions of the php package craftcms/stripe. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package stripe

Stripe for Craft CMS

Connect your Craft content to Stripe’s powerful billing tools, and build a streamlined storefront.

Requirements

This plugin requires Craft CMS 5.3.0 or later, and a Stripe account with access to developer features.

[!TIP] Transitioning from Craft Commerce? Check out the dedicated migration section.

Installation

You can install this plugin via the in-app the command line.

Plugin Store

Visit the Plugin Store screen of your installation’s control panel, then search for Stripe.

Click the Install button, then check out the configuration instructions!

Composer

These instructions assume you are using DDEV, but you can run similar commands in other environments. Open up a terminal and run…

Configuration

The Stripe plugin builds its configuration from three sources:

API Keys

Stripe uses a pair of “publishable” and “secret” keys to communicate with their API. In your Stripe account, switch into Test mode, then visit the Developer section and grab your development keys.

[!NOTE] Read more about Stripe API Keys.

Add these keys to your project’s .env file:

Then, in the control panel, visit StripeSettings, and enter the variable names you chose, in the respective fields. Craft will provide suggestions based on what it discovers in the environment.

Webhooks

Webhooks are essential for the plugin to work correctly—they allow changes to product data and off-platform customer activity to be rapidly synchronized into your site.

[!TIP] Be sure and perform an initial synchronization to import existing Stripe data.

To test webhooks in your local development environment, we recommend using the Stripe CLI to create a tunnel and forward events. Follow the installation instructions for your platform, then run:

[!NOTE] The hostname you provide here should agree with how you access the project, locally—Stripe does not need to be able to resolve it on the public internet for testing webhooks to be delivered!

The CLI will let you know when it’s ready, and output a webhook signing secret starting with whsec_. Add this value to your .env file, and return to the StripeSettings in the control panel

Synchronization

Webhooks keep product and customer data synchronized between Stripe and Craft, but they will only report changes.

You have two options for doing an initial import of Stripe data:

Content + Fields

Stripe products, prices, and subscriptions are all stored as elements in Craft. This means that they have access to the full suite of content modeling tools you would expect!

Field layouts for each element type are managed in the plugin’s Settings screen.

Product URLs

In addition to a field layout, product elements support URI Format and Template settings, which work just like they do on other element types: when a product’s URL is requested, Craft loads the element and passes it to the specified template under a product variable.

[!NOTE] Prices and subscriptions do not have their own URLs. You can use query parameters or custom routes to load those elements in response to specific URI patterns.

Migrating from Craft Commerce

Users of our full-featured ecommerce system, Craft Commerce can migrate existing subscriptions to the standalone Stripe plugin without losing any customer data.

Once you have fully upgraded to Craft 5.1 and Craft Commerce 5.0, follow the normal configuration instructions, above. Then, run this pair of console commands:

API Changes

You will interact with subscriptions differently than in Craft Commerce, as they have shifted to more closely resemble Stripe’s billing architecture than the legacy single-item “plans”:


Storefront

Once you have populated your Craft project with data from Stripe (via webhooks), you can begin scaffolding your content and storefront.

[!TIP] The reference section has information about each type of object you’re apt to encounter in the system.

Listing Products

Individual products automatically get URLs based on their URI format, but it is up to you how they are gathered and displayed.

To get a list of products, use the craft.stripeProducts element query factory:

The Product Template

On an individual product’s page, Craft provides the current product under a product variable:

Any custom fields you’ve configured for products will be available as properties, just as they are for other element types:

Prices

Like Craft Commerce, Stripe uses “products” as a means of logically grouping goods and services—the things your customers actually buy are called “prices.”

The Stripe plugin handles this relationship using nested elements. Each product element will own one or more price elements, and expose them via a prices property or getPrices() method:

Checkout Links

When a customer is ready to buy a product or start a subscription, you’ll provide a checkout link. Checkout links are special, secure, parameterized URLs that exist as part of a checkout session for a pre-configured list of items. Stripe has no “cart,” per se; instead, products are purchased piecemeal.

Clicking a checkout link takes the customer to Stripe’s hosted checkout page, where they can complete a payment using whatever methods are available and enabled in your account.

To output a checkout link, use the stripeCheckoutUrl() function:

[!TIP] Passing false as the second parameter to the stripeCheckoutUrl() allows you to create an anonymous checkout URL.

Checkout Form

As an alternative to generating static Checkout links, you can build a form that sends a list of items and other params to Craft, which will create a checkout session on-the-fly, then redirect the customer to the Stripe-hosted checkout page:

[!TIP] By default, the currently logged-in user will be used.

To allow an anonymous checkout, you can add {{ hiddenInput('customer', 'false') }} to the form.

If you use this method, you can pass custom field values that should be saved in Craft against a newly created Subscription. These values need to be passed as fields[<fieldHandle>]. For example:

Billing Portal

Customers can manage their subscriptions and payment methods via Stripe’s hosted billing portal. You can generate a URL to a customer’s billing portal using the currentUser.getStripeBillingPortalSessionUrl() method:

The method takes a returnUrl parameter that specifies the URL to redirect the customer to after they have finished managing their subscriptions and payment methods.

In addition to this method, there is also currentUser.getStripeBillingPortalSessionPaymentMethodUpdateUrl(), which generates a URL for the customer to update their default payment method.

This uses the Stripe flow type to deep link directly to the payment method update screen.

Element API

Our Element API plugin works great with Stripe! All three plugin-provided element types (products, prices, and subscriptions) can be used in your element-api.php config file:

Other Features

Product Field

Create a Stripe Products field and add it to a field layout to relate product elements to other content throughout the system.

Direct API Access

The plugin exposes its Stripe API client for advanced usage. In Twig, you would access it via craft.stripe.api.client:

In PHP, you can make the equivalent call like this:

[!WARNING] We cannot provide support for customizations that involve direct use of Stripe APIs. If you find yourself needing access to specific APIs during the course of your project, consider starting a discussion!

Tips, Troubleshooting, FAQ

Where do I change a product’s title?

Product and price titles are kept in sync with Stripe to make them easily identifiable in both spaces.

If you would like to customize product names in Craft, create a plain text field and add it to the product field layout. Stripe will only ever display the canonical title at checkout or on invoices, so it is important you have a way for customers to identify which products are which—and not re-use product definitions for other goods.

I can’t create a webhook.

If Craft can't write to a .env file in the project root, you may need to manually create a webhook in the Stripe dashboard, then expose it to the environment:

[!WARNING] In this case, the environment variable names are strict!


Reference

Twig Filters

The plugin provides four new Twig filters:

In most cases, you will want to use the unitPrice filter, as it will provide the most complete information about a price. All filters should be passed the price’s data property, which is the raw Price object from Stripe:

CLI

To view all available console commands, run ddev craft help. The Stripe plugin adds two main groups of commands:

Craft Commerce Migration

Migrates preexisting Craft Commerce subscriptions to records compatible with the Stripe plugin.

Atomic Synchronization

You can synchronize everything at once…

…or just pull in slices of it:


Extending

Synchronization Events

The Stripe plugin emits events just before updating each product, price, or subscription element during a synchronization. A synchronization may occur via the CLI, control panel utility, or in response to a webhook.

Class + Event Event Model $source
craft\stripe\services\Products::EVENT_BEFORE_SYNCHRONIZE_PRODUCT craft\stripe\events\StripeProductSyncEvent Product
craft\stripe\services\Prices::EVENT_BEFORE_SYNCHRONIZE_PRICE craft\stripe\events\StripePriceSyncEvent Price
craft\stripe\services\Subscriptions::EVENT_BEFORE_SYNCHRONIZE_SUBSCRIPTION craft\stripe\events\StripeSubscriptionSyncEvent Subscription

You can set $event->isValid to prevent updates from being persisted during the synchronization.

Checkout Events

Customize the parameters sent to Stripe when generating a Checkout session by listening to the craft\stripe\services\Checkout::EVENT_BEFORE_START_CHECKOUT_SESSION event. The craft\stripe\events\CheckoutSessionEvent will have a params property containing the request data that is about to be sent with the Stripe API client. You may modify or extend this data to suit your application—whatever the value of the property is after all handlers have been invoked is passed verbatim to the API client:


All versions of stripe with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
craftcms/cms Version ^5.5.0
stripe/stripe-php Version ^13|^14
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package craftcms/stripe contains the following files

Loading the files please wait ....