php 如何解决我的Stripe Connect入职流程的“Header may not contain more than a single header,new line detected”问题?

6l7fqoea  于 11个月前  发布在  PHP
关注(0)|答案(1)|浏览(215)

我不是最好的程序员,这是我的第一个大项目。这里的脚本主要是注册过程后的重定向。一切正常,直到你点击“注册”按钮,然后你得到一个耀斑错误。入职流程是在条纹连接Express帐户。我使用MySQL的数据库和Laravel框架的代码。请帮助我,我已经在这个错误3天了。我将非常感谢任何帮助!
Flare错误显示“Header may not contain more than a single header,new line detected”和我的index.php文件。下面是我的索引文件的一小部分:

namespace App\Http\Controllers;

require_once('vendor/autoload.php');

use Illuminate\Support\Facades\Auth;
use Stripe\Stripe;
use Stripe\Account;
use Stripe\AccountLink;
use App\Models\User;
use Illuminate\Support\Facades\Crypt;
use Carbon\Carbon;
use Stripe\ApiOperations;
use Illuminate\Http;

class StripeConnectController extends Controller
{
    public function StripeOnboarding101(){
        $user = Auth::user();

        /** @var User $user */
        if (empty($user->stripe_on_boarding_completed_at)) {
            $stripeSecret = env('STRIPE_SECRET');
            $stripe::setApiKey($stripeSecret);
            $stripe = new \Stripe\StripeClient ($stripeSecret);

            if (empty($user->stripe_connect_id)) {
                /** @var Account $account */
                $account = Account::create([
                    'type'         => 'express',
                    'email'        => $user->email,
                    'country'      => 'SE',
                    'capabilities' => [
                        'card_payments' => ['requested' => true],
                        'transfers'     => ['requested' => true],
                    ],
                    'settings'     => [
                        'payouts' => [
                            'schedule' => [
                                'interval' => 'manual',
                            ],
                        ],
                    ],
                ]);

                $user->stripe_connect_id = $account->id;
                $user->save();
            }

            $user->fresh();

            $onBoardLink = AccountLink::create([
                'account'     => $user->stripe_connect_id,
                'refresh_url' => route('onBoardCancel'),
                'return_url'  => route('onBoardResult', Crypt::encrypt($user->stripe_connect_id)),
                'type'        => 'account_onboarding',
            ]);

            //  ob_clean();

            // Open a new window alternative TEST; $javascript = "<script>window.open('{$onBoardLink->url}', '_blank');</script>";
        }

        $loginLink = $this->stripeClient->accounts->createLoginLink($user->stripe_connect_id, []);
        return redirect($loginLink->url);
    }

    public function onBoardResult($encodedToken)
    {
        /** @var User $user */
        $user = User::whereStripeConnectId(Crypt::decrypt($encodedToken))->firstOrFail();

        $user->stripe_on_boarding_completed_at = Carbon::now();
        $user->save();

        return redirect(route('create/campaign'));
    }

    public function onBoardCancel()
    {
        return redirect(route('dashboard'));
    }

字符串
以下是我的Stripe onboarding路线:

Route::middleware(['web', 'auth'])->group(function () {
    Route::get('dashboard', 'DashboardController@index')->name('dashboard');});

// Exempt the Stripe onboarding route from the RedirectIfAuthenticated middleware
Route::get('/stripeonboarding', 'StripeConnectController@StripeOnboarding101')->name('StripeOnboarding101')->withoutMiddleware(['guest'])


这是我注册时的RegisterController在我的页面上。

namespace App\Http\Controllers\Auth;

use App\Models\User;
use Validator;
use App\Models\AdminSettings;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\RegistersUsers;
use Mail;
use App\Http\Controllers\StripeConnectController;

class RegisterController extends Controller
{
    use RegistersUsers;

    /**
     * Where to redirect users after login / registration.
     *
     * @var string
     */
    protected function redirectTo()
    {
        return redirect()->action([StripeConnectController::class,'StripeOnboarding101']);
    }

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        $settings = AdminSettings::first();
        $data['_captcha'] = $settings->captcha;

        $messages = [
            'countries_id.required' => trans('misc.please_select_country'),
            'g-recaptcha-response.required_if' => trans('admin.captcha_error_required'),
            'g-recaptcha-response.captcha' => trans('admin.captcha_error'),
        ];

        return Validator::make($data, [
            'name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|min:6|confirmed',
            'countries_id'     => 'required',
            'agree_gdpr' => 'required',
            'g-recaptcha-response' => 'required_if:_captcha,==,on|captcha'
        ],$messages);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
        $settings    = AdminSettings::first();

        // Verify Settings Admin
        if( $settings->email_verification == 1 ) {

            $confirmation_code = str_random(100);
            $status = 'pending';

            //send verification mail to user
            $_username      = $data['name'];
            $_email_user    = $data['email'];
            $_title_site    = $settings->title;
            $_email_noreply = $settings->email_no_reply;

            Mail::send('emails.verify', array('confirmation_code' => $confirmation_code, 'title_site' => $_title_site ),
         function($message) use (
                $_username,
                $_email_user,
                $_title_site,
                $_email_noreply
         ) {
                $message->from($_email_noreply, $_title_site);
                $message->subject(trans('users.title_email_verify'));
                $message->to($_email_user,$_username);
            });
        } else {
            $confirmation_code = '';
            $status            = 'active';
        }

        $token = str_random(75);

        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
            'countries_id' => $data['countries_id'],
            'avatar' => 'default.jpg',
            'status' => $status,
            'role' => 'normal',
            'token' => $token,
            'confirmation_code' => $confirmation_code
        ]);
    }

    protected function redirectToStripeOnboarding(User $user)
    {
        // Call the Stripe onboarding logic here
        $this->StripeOnboarding101($user);

        // Redirect the user to a specific URL after Stripe onboarding
        return redirect()->route('organization.dashboard'); // Adjust the route as needed
    }

    public function showRegistrationForm()
    {
        $settings = AdminSettings::first();

        if($settings->registration_active == 'on')  {
            return view('auth.register');
        } else {
            return redirect('/');
        }
    }
}


以下是我的错误日志:

[2023-12-28 17:46:39] development.ERROR: Header may not contain more than a single header, new line detected {"userId":27,"exception":"[object] (ErrorException(code: 0): Header may not contain more than a single header, new line detected at /home/..../public_html/vendor/symfony/http-foundation/Response.php:376) [stacktrace] 
#0 /home/capitalpal/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(255): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()

#1 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->Illuminate\\Foundation\\Bootstrap\\{closure}()

#2 /home/capitalpal/public_html/vendor/symfony/http-foundation/Response.php(376): header()

#3 /home/capitalpal/public_html/vendor/symfony/http-foundation/Response.php(424): Symfony\\Component\\HttpFoundation\\Response->sendHeaders()

#4 /home/capitalpal/public_html/index.php(55): Symfony\\Component\\HttpFoundation\\Response->send()

#5 {main}
"}


我也有一个重定向刀片文件时,点击注册按钮,但我不怀疑,它是错误的.而且,再次,我会非常感谢任何帮助.如果任何人都在他们的项目做了这太我会很感激,如果我能看到他们的脚本和比较等的一部分.
我试着做一个JavaScript行,而不是打开一个新的窗口,但这根本不起作用。我已经更新了与Composer的供应商文件,并重新安装供应商文件夹,我已经更新了laravel(v10.38.2),条纹PHP库(v10.21.0)和PHP到8.2

gojuced7

gojuced71#

Laravel Middleware: Header may not contain more than a single header, new line detected中提供的答案类似,问题在于RegisterController上的redirectTo()方法应该返回重定向路径的字符串,但您当前返回的是完整的重定向响应对象。
更新此方法以返回要重定向到的路径:

protected function redirectTo()
{
    // Use the action() helper to convert the action to a path.
    return action([StripeConnectController::class, 'StripeOnboarding101']);
}

字符串

相关问题