[英]How do I get PayPal to work with Laravel PHP?
似乎过去 5 年没有人试图让 PayPal 与 PHP 上的 Laravel 站点合作,所以我现在强行询问。
我正在使用这个 package: 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/
这是一个工作演示!
I looked into it further an found where the requests are sent within the package and it sends a POST Request to https://api-3t.sandbox.paypal.com/nvp and when I recreate the request with the same postdata in postman,我得到ACK=Failure&L_ERRORCODE0=81002&L_SHORTMESSAGE0=Unspecified%20Method&L_LONGMESSAGE0=Method%20Specified%20is%20not%20Supported&L_SEVERITYCODE0=Error
这是我认为真正的错误。
如果有人可以提供帮助,那就太好了!
仔细检查凭据是否配置正确。
validate_ssl
可能还需要设置为false
: https://github.com/srmklive/laravel-paypal/issues/229#issuecomment-472755054
您链接到的 package 是古老的,就 PayPal APIs go 而言已经过时了 2 代。 不要使用它。
Here is the current PHP SDK (not laravel specific): https://github.com/paypal/Checkout-PHP-SDK
它应该用于在您的服务器上创建两条路由,一条用于“设置事务”,另一条用于“捕获事务”。 这是一个指南: https://developer.paypal.com/docs/checkout/reference/server-integration/
这两条路由应该被这个前端代码调用: https://developer.paypal.com/demo/checkout/#/pattern/server
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.