gpt4 book ai didi

php - 沙盒 Paypal 结帐(PHP,Laravel)

转载 作者:太空宇宙 更新时间:2023-11-03 16:21:13 26 4
gpt4 key购买 nike

我正在尝试对我的 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'];
});

最佳答案

所以我对我的沙箱帐户进行了密码重置,并且成功了!

关于php - 沙盒 Paypal 结帐(PHP,Laravel),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55957923/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com