Loading...

Getting Stripe API setup with Nova Framework

David Carr

1 min read - 26th Aug, 2017

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. 

0 comments
Add a comment