使用OmniPay的PayPal REST API在Laravel上给出了“ AUTHENTICATION_FAILURE”

时间:2018-07-29 19:10:56

标签: php laravel laravel-5 paypal omnipay

我正在尝试在Laravel 5.6上使用OmniPayOmniPay PayPal集成PayPal REST API。

我的gateway()函数:

public function gateway()
{
    // Create a gateway for the PayPal RestGateway
    $gateway = Omnipay::create('PayPal_Rest');

    // Initialise the gateway
    $gateway->initialize(array(
        'clientId' => config('services.paypal.clientid'),
        'secret' => config('services.paypal.secret'),
        'testMode' => config('services.paypal.testmode'), // Or false when you are ready for live transactions
    ));


    return $gateway;
}

在同一模型中购买功能:

public function purchase(array $parameters)
{
    $response = $this->gateway()
        ->purchase($parameters)
        ->send();

    return $response;
}

控制器中的结帐功能:

public function checkout($order_id, Request $request)
{
    $order = Order::findOrFail(decrypt($order_id));

    $paypal = new PayPal;

    $response = $paypal->purchase([
        'amount' => $paypal->formatAmount($order->amount),
        'transactionId' => $order->id,
        'currency' => 'USD',
        'cancelUrl' => $paypal->getCancelUrl($order),
        'returnUrl' => $paypal->getReturnUrl($order),
    ]);

    if ($response->isRedirect()) {
        $response->redirect();
    }

    return redirect()->back()->with([
        'message' => $response->getMessage(),
    ]);
}

clientId和Secret设置正确(尝试多次更改和重新输入,并且.env文件中的testMode设置为 true

每次尝试提交请求时,都会出现此错误:

  

由于身份验证凭据无效或缺少授权标头,导致身份验证失败。

这里可能是什么问题?

谢谢!

0 个答案:

没有答案