Reputation: 2360
I'm integrating Laravel with GoCardless to allow my users to take card payments however I'm struggling installing the GoCardless php wrapper.
I've followed the following doc: https://developer.gocardless.com/getting-started/partners/building-an-authorisation-link/
It says to use the following, am I right in saying this will go in my controller? surely with Laravel I wouldnt need to require the vendor/autoload?
<?php
require 'vendor/autoload.php';
// You should store your client ID and secret in environment variables rather than
// committing them with your code
$client = new OAuth2\Client(getenv('GOCARDLESS_CLIENT_ID'), getenv('GOCARDLESS_CLIENT_SECRET'));
$authorizeUrl = $client->getAuthenticationUrl(
// Once you go live, this should be set to https://connect.gocardless.com. You'll also
// need to create a live app and update your client ID and secret.
'https://connect-sandbox.gocardless.com/oauth/authorize',
'https://acme.enterprises/redirect',
['scope' => 'read_write', 'initial_view' => 'login']
);
// You'll now want to direct your user to the URL - you could redirect them or display it
// as a link on the page
header("Location: " . $authorizeUrl);
Apologies, if someone can point me in the right direction I would appreciate.
My controller currently looks like.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class goCardlessController extends Controller
{
public function index()
{
$client = new OAuth2\Client(env('GOCARDLESS_CLIENT_ID'), env('GOCARDLESS_CLIENT_SECRET'));
$authorizeUrl = $client->getAuthenticationUrl(
'https://connect-sandbox.gocardless.com/oauth/authorize',
'REDIRECT_URL',
['scope' => 'read_write', 'initial_view' => 'login']
);
header("Location: " . $authorizeUrl);
}
}
but I get the error:
Class 'App\Http\Controllers\OAuth2\Client' not found
Which makes sense because I haven't defined it in my controller but Im wondering how I would do this?
Upvotes: 2
Views: 904
Reputation: 9465
Try this in your controller:
use Oauth2;
Or alternatively, $client = new \OAuth2\Client(....
Do note the \ before Oauth2
Upvotes: 1