Stripe API, Tutorials, Nova Framework

Getting Stripe API setup with Nova Framework

This post will guide you on using Stripe’s API with Nova Framework

Install Stripe’s PHP library by including it in your composer.json file:

composer require stripe/stripe-php

Before starting with Stripe create a Stripe.php file in app/Config and enter your API secret and public key, also set your webhookSecret if you plan on using Stripe’s webhooks.

Go to https://dashboard.stripe.com/account/apikeys to manage your API keys.

return array(
    'apiSecretKey' => 'your-secret-key-here',
    'apiPublicKey' => 'your-public-key-here',
    'webhookSecret' => 'your-webhook-key-here',
);

This allows the API to access the keys without having them littered in your code.

In the controller, you’ll be using with Stripe import the classes you’ll be using. 

The Config facade should also be imported: 

use Config;

use Stripe\Customer;
use Stripe\Charge;
use Stripe\Invoice;
use Stripe\Plan;
use Stripe\Stripe;
use Stripe\Subscription;
use Stripe\Webhook;

Now we need to provide Stripe the API Secret key this will be used for all API calls, using a before() method means all methods of the class will have access to this. Retrieve the key by calling Config::get followed by stripe, then the item in this case apiSecretKey. 

public function before()
{
    Stripe::setApiKey(Config::get('stripe.apiSecretKey'));
}

That’s it Nova is now ready to start making API calls with Stripe. 

David Carr

David Carr

For the past 12 years, I’ve been developing applications for the web using mostly PHP. I do this for a living and love what I do as every day there is something new and exciting to learn.

In my spare time, the web development community is a big part of my life. Whether managing online programming groups and blogs or attending a conference, I find keeping involved helps me stay up to date. This is also my chance to give back to the community that helped me get started, a place I am proud to be apart of.

Besides programming I love spending time with friends and family and can often be found together going out catching the latest movie, staying in playing games on the sofa or planning a trip to someplace I’ve never been before.