[英]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.