我目前正在使用Paypal和https://github.com/srmklive/laravel-paypal进行PayPal结帐。我正在使用快速结帐,我对其进行了一些修改以适合我的项目的要求。在测试过程中,它尝试了几次,Paypal显示和付款正常执行,但是当我尝试运行完全相同的代码时。我收到此错误,我不知道这意味着什么。
我尝试检查我的路线,是否所有错误都发生在我的路线上,但所有路线都正常运行。我也尝试像dd(“ check”)一样转储并死掉,只是检查它是否真的进入了我的控制器并且确实如此。我在“ payCommission”方法中执行了此操作(这是我认为发生错误的位置)
这是我通往管制员的路线
Route::get('service/commissionfee/payment' , 'api\service\ExpressPaymentController@payCommission');
Route::get('paypal/ec-checkout-success', 'api\service\ExpressPaymentController@payCommissionSuccess');
<?php
namespace App\Http\Controllers\api\service;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Srmklive\PayPal\Services\ExpressCheckout;
class ExpressPaymentController extends Controller
{
protected $provider;
public function __construct()
{
try {
$this->provider = new ExpressCheckout();
}
catch(\Exception $e){
dd($e);
}
}
public function payCommission(Request $request)
{
$recurring = false;
$cart = $this->getCheckoutData($recurring);
try {
$response = $this->provider->setExpressCheckout($cart, $recurring);
return redirect($response['paypal_link']);
} catch (\Exception $e) {
dd($e);
return response()->json(['code' => 'danger', 'message' => "Error processing PayPal payment"]);
}
}
public function payCommissionSuccess(Request $request)
{
$recurring = false;
$token = $request->get('token');
$PayerID = $request->get('PayerID');
$cart = $this->getCheckoutData($recurring);
// ? Verify Express Checkout Token
$response = $this->provider->getExpressCheckoutDetails($token);
if (in_array(strtoupper($response['ACK']), ['SUCCESS', 'SUCCESSWITHWARNING'])) {
if ($recurring === true) {
$response = $this->provider->createMonthlySubscription($response['TOKEN'], 9.99, $cart['subscription_desc']);
if (!empty($response['PROFILESTATUS']) && in_array($response['PROFILESTATUS'], ['ActiveProfile', 'PendingProfile'])) {
$status = 'Processed';
} else {
$status = 'Invalid';
}
} else {
// ? Perform transaction on PayPal
$payment_status = $this->provider->doExpressCheckoutPayment($cart, $token, $PayerID);
$status = $payment_status['PAYMENTINFO_0_PAYMENTSTATUS'];
}
return response()->json(['success' => "payment complete"]);
}
}
private function getCheckoutData($recurring = false)
{
$data = [];
$order_id = 1;
$data['items'] = [
[
'name' => 'Product 1',
'price' => 9.99,
'qty' => 1,
],
];
$data['return_url'] = url('api/paypal/ec-checkout-success');
// !
$data['invoice_id'] = config('paypal.invoice_prefix').'_'.$order_id;
$data['invoice_description'] = "Commission Fee payment";
$data['cancel_url'] = url('/');
$total = 0;
foreach ($data['items'] as $item) {
$total += $item['price'] * $item['qty'];
}
$data['total'] = $total;
return $data;
}
}
我遇到错误
Object of class Illuminate\Routing\Redirector could not be converted to string
提前谢谢
答案 0 :(得分:0)
您可以只转到config / paypal.php并进行编辑
'invoice_prefix' => env('PAYPAL_INVOICE_PREFIX', 'Life_saver_'),
您可以像Life_saver_这样使用_下划线,也不要忘记最后使用下划线。