【发布时间】:2020-10-02 14:49:07
【问题描述】:
过去 5 年似乎没有人试图让 PayPal 与 PHP 上的 Laravel 网站合作,所以我现在强行询问。
我正在使用这个包:https://github.com/srmklive/laravel-paypal
我正在向 PayPal 发送这个:
array:6 [▼
"items" => array:2 [▼
0 => array:3 [▼
"name" => "Product 1"
"price" => 9.99
"qty" => 1
]
1 => array:3 [▼
"name" => "Product 2"
"price" => 4.99
"qty" => 2
]
]
"return_url" => "https://github.com/payment/success"
"invoice_id" => "PAYPALDEMOAPP_1"
"invoice_description" => "Order #PAYPALDEMOAPP_1 Invoice"
"cancel_url" => "https://github.com/cart"
"total" => 19.97
]
这些值当然纯粹是为了测试,但它们应该可以工作。
但是,我收到此错误:
array:3 [▼
"type" => "error"
"message" => ""
"paypal_link" => null
]
我的代码如下所示:
public function start()
{
$provider = new ExpressCheckout();
$data = [];
$data['items'] = [
[
'name' => 'Product 1',
'price' => 9.99,
'qty' => 1,
],
[
'name' => 'Product 2',
'price' => 4.99,
'qty' => 2,
],
];
$data['return_url'] = 'https://github.com/payment/success';
$data['invoice_id'] = 'PAYPALDEMOAPP_' . 1;
$data['invoice_description'] = "Order #{$data['invoice_id']} Invoice";
$data['cancel_url'] = 'https://github.com/cart';
// $data['return_url'] = url('/payment/success');
// $data['cancel_url'] = url('/cart');
$total = 0;
foreach($data['items'] as $item) {
$total += $item['price'] * $item['qty'];
}
$data['total'] = $total;
$response = $provider->setExpressCheckout($data);
dd($response);
return redirect($response['paypal_link']);
}
这些值与https://github.com/srmklive/laravel-paypal-demo/使用的值完全相同
这是一个工作演示!
我进一步调查了它,发现请求在包中发送,它向https://api-3t.sandbox.paypal.com/nvp发送一个POST请求,当我在邮递员中使用相同的postdata重新创建请求时,我得到ACK=Failure&L_ERRORCODE0=81002&L_SHORTMESSAGE0=Unspecified%20Method&L_LONGMESSAGE0=Method%20Specified%20is%20not%20Supported&L_SEVERITYCODE0=Error,这是我认为真实的错误。
如果有人可以提供帮助,那就太好了!
【问题讨论】: