【问题标题】:Srmklive\PayPal error "Object of class Illuminate\Routing\Redirector could not be converted to string" trying express checkout in sandboxSrmklive\PayPal 错误“无法将类 Illuminate\Routing\Redirector 的对象转换为字符串”尝试在沙盒中快速结帐
【发布时间】:2020-10-22 23:47:33
【问题描述】:

您好,我正在尝试使用 Srmklive\PayPal 将 Paypal 集成到 Laravel 5.8 项目中。 我遵循文档并像这样配置我的应用程序:

这是控制器:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Srmklive\PayPal\Services\ExpressCheckout;


class PayPalController extends Controller
{
/**
 * Responds with a welcome message with instructions
 *
 * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
 */
public function payment()
{
    $data = [];
    $data['items'] = [
        [
            'name' => 'ItSolutionStuff.com',
            'price' => 100,
            'desc'  => 'Description for ItSolutionStuff.com',
            'qty' => 1
        ]
    ];

    $data['invoice_id'] = 1;
    $data['invoice_description'] = "Order #{$data['invoice_id']} Invoice";
    $data['return_url'] = route('payment.success');
    $data['cancel_url'] = route('payment.cancel');
    $data['total'] = 100;

    $provider = new ExpressCheckout;
    $response = $provider->setCurrency('EUR')->setExpressCheckout($data);
    //dd($response);

    return redirect($response['paypal_link']);
}

/**
 * Responds with a welcome message with instructions
 *
 * @return \Illuminate\Http\Response
 */
public function cancel()
{
    dd('Your payment is canceled. You can create cancel page here.');
}

/**
 * Responds with a welcome message with instructions
 *
 * @return \Illuminate\Http\Response
 */
public function success(Request $request)
{
    $response = $provider->getExpressCheckoutDetails($request->token);

    if (in_array(strtoupper($response['ACK']), ['SUCCESS', 'SUCCESSWITHWARNING'])) {
        dd('Your payment was successfully. You can create success page here.');
    }

    dd('Something is wrong.');
}
}

这些是路线:

Route::get('payment', 'PayPalController@payment')->name('payment');
Route::get('cancel', 'PayPalController@cancel')->name('payment.cancel');
Route::get('payment/success', 'PayPalController@success')->name('payment.success');

最后这是我放入 .env 文件的内容:

PAYPAL_SANDBOX_API_USERNAME=sb-xxxxxxxx.com
PAYPAL_SANDBOX_API_PASSWORD=KxxxxxxxxxWA
PAYPAL_SANDBOX_API_SECRET=Exxxxxxxxxxxxx
PAYPAL_SANDBOX_API_CERTIFICATE=

点击支付按钮时出现的错误是“类 Illuminate\Routing\Redirector 的对象无法转换为字符串”

这是控制器中生成的$response转储的内容

感谢您的帮助

【问题讨论】:

  • 抱歉我忘记了转储内容:array:10 [▼ "TIMESTAMP" => "2020-07-02T11:20:27Z" "CORRELATIONID" => "4983ab115332a" "ACK" => "失败”“VERSION”=>“123”“BUILD”=>“54686869”“L_ERRORCODE0”=>“10002”“L_SHORTMESSAGE0”=>“安全错误”“L_LONGMESSAGE0”=>“安全标头无效”“L_SEVERITYCODE0” => "错误" "paypal_link" => null ]
  • 最好将转储放在已编辑的问题中以提高可读性。
  • 欢迎来到 SO ... "paypal_link" =&gt; null ... 没有“paypal 链接”,所以 redirect(null) 返回 Redirector 而不是 RedirectResponse
  • @lagbox 搞定了
  • 我终于找到了错误。问题是错误的文档和示例文件。

标签: laravel paypal paypal-sandbox


【解决方案1】:

这是我的 $provider 变量的转储......我真的不知道在哪里可以找到错误......似乎一切都正确设置了

Srmklive\PayPal\Services\ExpressCheckout {#299 ▼
  -client: GuzzleHttp\Client {#300 ▼
  -config: array:9 [▶]
 }
-httpClientConfig: array:2 [▶]
  -certificate: ""
+mode: "sandbox"
#post: Illuminate\Support\Collection {#321 ▼
  #items: array:21 [▼
  "L_PAYMENTREQUEST_0_NAME0" => "ItSolutionStuff.com"
  "L_PAYMENTREQUEST_0_AMT0" => 100
  "L_PAYMENTREQUEST_0_DESC0" => "Description for ItSolutionStuff.com"
  "L_PAYMENTREQUEST_0_QTY0" => 1
  "PAYMENTREQUEST_0_ITEMAMT" => 100
  "PAYMENTREQUEST_0_AMT" => 100
  "PAYMENTREQUEST_0_PAYMENTACTION" => "Sale"
  "PAYMENTREQUEST_0_CURRENCYCODE" => "EUR"
  "PAYMENTREQUEST_0_DESC" => "Order #1 Invoice"
  "PAYMENTREQUEST_0_INVNUM" => 1
  "NOSHIPPING" => 1
  "RETURNURL" => "http://127.0.0.1:8000/payment/success"
  "CANCELURL" => "http://127.0.0.1:8000/cancel"
  "LOCALE" => "en_US"
  "L_BILLINGTYPE0" => "MerchantInitiatedBilling"
  "L_BILLINGAGREEMENTDESCRIPTION0" => "Order #1 Invoice"
  "USER" => "sb-4lmkp2417467_api1.business.example.com"
  "PWD" => "KWP3ZMXTAABSECWA"
  "SIGNATURE" => "ENX8hFsccoYGDiPXfROILYkMlkRTCkdCRdBQZ-prMaOGLpE7sm7TRaZSFFd4KQI14LAShVhvDZN9sSDh"
  "VERSION" => 123
  "METHOD" => "SetExpressCheckout"
    ]
  }
 -config: array:12 [▼
"username" => "sb-4lmkp2417467_api1.business.example.com"
"password" => "KWP3ZMXTAABSECWA"
"secret" => "ENX8hFsccoYGDiPXfROILYkMlkRTCkdCRdBQZ-prMaOGLpE7sm7TRaZSFFd4KQI14LAShVhvDZN9sSDh"
"certificate" => ""
"app_id" => "APP-80W284485P519543T"
"signature" => "ENX8hFsccoYGDiPXfROILYkMlkRTCkdCRdBQZ-prMaOGLpE7sm7TRaZSFFd4KQI14LAShVhvDZN9sSDh"
"api_url" => "https://api-3t.sandbox.paypal.com/nvp"
"gateway_url" => "https://www.sandbox.paypal.com"
"ipn_url" => "https://ipnpb.sandbox.paypal.com/cgi-bin/webscr"
"payment_action" => "Sale"
"notify_url" => ""
"locale" => ""
  ]
  -subtotal: 100
  -currency: "EUR"
  -billingType: "MerchantInitiatedBilling"
  -options: []
  -paymentAction: "Sale"
  -locale: "en_US"
  -apiUrl: "https://api-3t.sandbox.paypal.com/nvp"
  -notifyUrl: ""
  -httpBodyParam: "form_params"
  -validateSSL: true
}

【讨论】:

    猜你喜欢
    • 2019-11-12
    • 2020-02-03
    • 1970-01-01
    • 2012-10-25
    • 2013-06-26
    • 2016-06-01
    • 2020-05-13
    • 1970-01-01
    • 2016-09-12
    相关资源
    最近更新 更多