php - 沙盒 Paypal 结帐(PHP、Laravel)
问题描述
我正在尝试对我的 Laravel Api(连接到 Ionic 应用程序)实施 Paypal 的结帐,当我在应用程序中按下按钮进行结帐并在登录屏幕中转到 Paypal(到目前为止一切顺利)时,它卡住了。我觉得很奇怪,因为它不允许我使用我的沙盒帐户甚至我的真实帐户登录,错误是一样的:“您的某些信息不正确。请重试。” 通过打开开发人员工具,这些是我得到的错误(见截图)。我真的找不到我在这里犯错的地方。也许你可以帮助我。下面是屏幕截图和将结帐到 Paypal 的代码。让我知道我是否应该在这里添加任何额外的信息!非常感谢!
错误 1: ,调查控制台错误之一:
Route::middleware('auth:api')->post('/paypal', function (Request $request) {
$user = $request->user();
$data = $request->all();
$list_products_id = $data;
$products = [];
$total = 0;
$titles = '';
foreach($list_products_id as $key => $value) {
$product = Product::find($value);
if($product){
$products[$key] = $product;
$total += $product->price;
$titles .= $product->title." ";
}
}
if($total){
$paypal = config('app.paypal', "sandbox");
if($paypal == "sandbox"){
$userProvider = 'In my app I have the sandbox business credentials here';
$pwdProvider = 'In my app I have the sandbox business credentials here';
$signProvider = 'In my app I have the sandbox business credentials here';
$url = 'https://api-3t.sandbox.paypal.com/nvp';
$url2 = 'https://www.sandbox.paypal.com/cgi-bin/webscr?%s';
} else {
$userProvider = '';
$pwdProvider = '';
$signProvider = '';
$url = 'https://api-3t.paypal.com/nvp';
$url2 = 'https://www.paypal.com/cgi-bin/webscr?%s';
}
$data = [];
$data['USER'] = $userProvider;
$data['PWD'] = $pwdProvider;
$data['SIGNATURE'] = $signProvider;
$data['METHOD'] = 'SetExpressCheckout';
$data['VERSION'] = '108';
$data['LOCALECODE'] = 'en_US';
$data['L_PAYMENTREQUEST_0_NAME0'] = "Products Orders";
$data['L_PAYMENTREQUEST_0_DESC0'] = $titles;
$data['PAYMENTREQUEST_0_AMT'] = number_format($total, 2).'';
$data['PAYMENTREQUEST_0_CURRENCYCODE'] = 'EUR';
$data['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Sale';
$data['L_PAYMENTREQUEST_0_QTY0'] = '1'; //number of the same product the user is ordering
$data['L_PAYMENTREQUEST_0_AMT0'] = number_format($total, 2).'';
$data['L_BILLINGAGREEMENTDESCRIPTION0'] = $titles;
$data['CANCELURL'] = url('/');
$data['RETURNURL'] = url('/');
// curl
$data = http_build_query($data);
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($curl);
curl_close($curl);
$nvp = array();
if (preg_match_all('/(?<name>[^\=]+)\=(?<value>[^&]+)&?/', $response, $matches)) {
foreach ($matches['name'] as $offset => $name) {
$nvp[$name] = urldecode($matches['value'][$offset]);
}
}
if(isset($nvp['ACK']) && $nvp['ACK'] == "Success" ){
$query = array(
'cmd' => '_express-checkout',
'token' => $nvp['TOKEN']
);
$redirectURL = sprintf($url2, http_build_query($query));
return ['date'=>$redirectURL];
}else{
return ['status'=>'error purchasing! - 1'];
}
}
echo "total: " . $total;
return ['status'=>'error purchasing! - 2'];
});
解决方案
所以我对我的沙盒帐户进行了密码重置,并且成功了!
推荐阅读
- spring-cloud - Spring Boot、Spring-Kafka 和 Spring-Cloud 兼容性
- pentaho - 如何使用 sql db 发布 Pentaho 报告?
- c# - 我应该在课堂上的哪个位置填充 MemoryCache?
- c# - WPF 在固定位置放置标签
- operating-system - 如何使用 os2 创建 mbed 项目?
- neo4j - SDN参数化RelationshipEntity类型
- c# - Converting Entity to DTO along with child entities
- php - php根据一些共同的值合并数组的两个元素并添加其他值
- hive - 我们可以预测 Hive SELECT * 查询结果的顺序吗?
- c++ - 矩阵的最大值和在同一循环中保存索引