Laravel GoCardless

时间:2017-01-17 17:34:59

标签: php laravel laravel-5 oauth

我正在将Laravel与GoCardless集成以允许我的用户进行卡支付但是我正在努力安装GoCardless php包装器。

我遵循了以下文档: 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);
    }
}

但是我收到了错误:

  

未找到类'App \ Http \ Controllers \ OAuth2 \ Client'

这是有道理的,因为我没有在我的控制器中定义它,但我想知道我会怎么做?

1 个答案:

答案 0 :(得分:1)

在你的控制器中试试这个:

use Oauth2;

或者,$client = new \OAuth2\Client(....请注意Oauth2之前的\