2017-01-17 20 views
2

我正在將Laravel與GoCardless集成以允許我的用戶使用卡支付,但是我正在努力安裝GoCardless php包裝。Laravel GoCardless

我已經按照下面的文檔: https://developer.gocardless.com/getting-started/partners/building-an-authorisation-link/

報告說,使用下面的,我是不是說得這將在我的控制器去?肯定與Laravel我不需要供應商/自動加載?

<?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); 

道歉,如果有人能指出我在正確的方向,我將不勝感激。

我的控制器目前看起來像。

<?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); 
    } 
} 

,但我得到的錯誤:

Class 'App\Http\Controllers\OAuth2\Client' not found

,因爲我沒有在我的控制器中定義它,但我想知道我會怎麼做這哪有道理?

回答

1

在你的控制器試試這個:

use Oauth2; 

或者,$client = new \OAuth2\Client(....的oauth2

之前,請注意\