Saving your Stripe API Keys

Now that you have installed the Stripe Payments plugin from the Craft CMS plugin store, you can now connect it to your Stripe account. You'll first need to retrieve your Stripe API, and then enter these credentials into the Stripe Payments Settings page.

Visit Stripe.com (opens new window) to get your API keys. Once you are on the Stripe webpage, sign in, and go to your dashboard and select Developers → API Keys from the menu. Make sure to have "Viewing Test Data" enabled to have Test mode enabled before your site go live.

Developer -> Api Keys (Stripe.com)

Please go ahead an open in a new tab the settings of the Stripe Payments plugin:  Stripe Payments → SettingsGeneral

For the next steps, you’re going to be switching between the 2 tabs and copy 4 keys from Stripe to be saved in the Stripe Payments plugin.

  1. Under your Stripe Payments settings, make sure that the "Test Mode" lightswitch is enabled.
  2. Back in your Stripe dashboard tab, please copy your Publishable key (starts with “pk_test_”), switching to your Stripe Payments Settings tab, and pasting it into the "Test Publishable Key" text box
  3. Now do the same for the Secret key (starts with “sk_test_”), and pasting it into the "Test Secret Key"  text box.

The next step is do the same for your live keys. Under your Stripe Payments settings, make sure that the "Test Mode" lightswitch is disabled.

  • Back in your Stripe dashboard tab, switch to Live mode (toggle “View Test Data” off), and repeat the above for your live keys.

# Saving the Stripe API keys via config file

If you don't want store your Stripe API keys in the database and add a security layer you can also store your Stripe API keys in your config/general.php config file in Craft 3 and config/custom.php config file in Craft 4, in the following example we're storing the API keys in the .env file and then retrieving the values in the config file:

# Migrating from Craft 3 to Craft 4

TIP

Craft 4, now requires store custom settings under the new config/custom.php file. Please make sure to migrate your stripePayments config settings to the config/custom.php file

 //config/custom.php
<?php
return [
    'stripePayments' => [
        'testPublishableKey' => getenv('YOUR_TEST_PUBLISHABLE_KEY'),
        'testSecretKey' => getenv('YOUR_TEST_SECRET_KEY'),
        'testMode' => true,
        // Optional -> This setting is only needed is Stripe Connect is enabled 
        'testClientId' => getenv('YOUR_TEST_CLIENT_ID'),
        // Optional -> if you want to check webhook signatures you can add the following setting (more info here https://stripe.com/docs/webhooks/signatures)
        'testWebhookSigningSecret' => getenv('TEST_WEBHOOK_SIGNING_SECRET')
    ]
];

Stripe Dashboard

Stripe Payments General Settings