【发布时间】: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" => null... 没有“paypal 链接”,所以redirect(null)返回Redirector而不是RedirectResponse -
@lagbox 搞定了
-
我终于找到了错误。问题是错误的文档和示例文件。
标签: laravel paypal paypal-sandbox