gpt4 book ai didi

php - PayPal API 无法连接

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

这是我的情况,我正在尝试将我的 PayPal API 详细信息插入到为我开发的应用程序中。 PayPal API 详细信息作为占位符提供,并且运行良好。然而,当我插入我的电源时,它每次都会失败。我意识到这是非常模糊的,您可能无法帮助我进行如此概括,但是任何提示都会有所帮助!代码如下。此外,如果您知道我可以获得有关正在发生的事情(错误代码等)的更多详细信息的方法,这也会有所帮助,这样我也可以进行更多研究。

最后,我之前想到的解决方案是,我需要升级账户,但是我只需要知道我是否需要添加信用卡或银行。

<?php 
class PaymentController extends BaseController {
public function PPHttpPost($methodName_, $nvpStr_) {

$PayPalMode = 'live';
$PayPalApiUsername = 'usergame';
$PayPalApiPassword = 'passhole';
$PayPalApiSignature = 'siggypoo';
$PayPalCurrencyCode = 'USD';
$PayPalReturnURL = URL::to('/paypal/enter');
$PayPalCancelURL = URL::to('/paypal/enter');


$API_UserName = urlencode($PayPalApiUsername);
$API_Password = urlencode($PayPalApiPassword);
$API_Signature = urlencode($PayPalApiSignature);

$str = '';
foreach ($nvpStr_ as $key => $nvp) {
$str .= '&' . $key . '=' . urlencode($nvp);
}

if($PayPalMode=='sandbox')
{
$paypalmode = '.sandbox';
}
else
{
$paypalmode = '';
}

$API_Endpoint = "https://api-3t".$paypalmode.".paypal.com/nvp";
$version = urlencode('76.0');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);

$nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$str";

curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);

$httpResponse = curl_exec($ch);

if(!$httpResponse) {
exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')');
}

$httpResponseAr = explode("&", $httpResponse);

$httpParsedResponseAr = array();
foreach ($httpResponseAr as $i => $value) {
$tmpAr = explode("=", $value);
if(sizeof($tmpAr) > 1) {
$httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
}
}

if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
}

return $httpParsedResponseAr;
}

public function PaymentController() {


$this->data = array(
'PAYMENTREQUEST_0_AMT' => Config::get('app.sponsor_price_per_month'),
'PAYMENTREQUEST_0_CURRENCY' => 'USD',
'RETURNURL' => URL::to('/paypal/enter'),
'CANCELURL' => URL::to('/paypal/enter'),
'NOSHIPPING' => 1,
'REQCONFIRMSHIPPING' => 0,
'L_PAYMENTREQUEST_0_ITEMCATEGORY0' => 'Digital',
'L_PAYMENTREQUEST_0_NAME0' => '30 Days Sponsorship',
'L_PAYMENTREQUEST_0_DESC0' => 'Sponsored status on Nae for 30 days.',
'L_PAYMENTREQUEST_0_AMT0' => Config::get('app.sponsor_price_per_month'),
'L_PAYMENTREQUEST_0_QTY0' => 1,
'L_PAYMENTREQUEST_0_TAXAMT0' => 0,
);
}

public function exitpage() {

if (!Auth::check()) {
return Redirect::to('/account/login');
} else {
$user = Auth::user();
}

if (!$server = $user->server) {
return Redirect::to('/account/server');
}

if (strtotime($server->sponsored) > time()) {
return Redirect::to('/account/server');
}

$out = $this->PPHttpPost('SetExpressCheckout', $this->data);

if (strtoupper($out["ACK"]) == "SUCCESS" || strtoupper($out["ACK"]) == "SUCCESSWITHWARNING") {

return Redirect::to('https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=' . $out["TOKEN"]);
} else {

return View::make('standard')->
with('title', 'Sponsor Server')->
nest('content', 'pages.sponsor', array(
'level' => 'warning',
'message' => 'Error processing payment! You have not been charged, please try again. TOKEN'
));

}
}

public function enter() {

if (!Auth::check()) {
return Redirect::to('/account/login');
} else {
$user = Auth::user();
}

if (!$server = $user->server) {
return Redirect::to('/account/server');
}

if (strtotime($server->sponsored) > time()) {
return Redirect::to('/account/server');
}

$data = array(
'TOKEN' => Input::get('token'),
'PAYERID' => Input::get('PayerID'),
'PAYMENTACTION' => 'SALE',
'AMT' => Config::get('app.sponsor_price_per_month'),
'CURRENCYCODE' => 'USD'
);

$out = $this->PPHttpPost('DoExpressCheckoutPayment', $data);

if (strtoupper($out["ACK"]) == "SUCCESS" || strtoupper($out["ACK"]) == "SUCCESSWITHWARNING") {

$server->sponsored = date('Y-m-d H:i:s', time() + (30 * 24 * 60 * 60));
$server->save();

return Redirect::to('/account/server');
} else {
return View::make('standard')->
with('title', 'Sponsor Server')->
nest('content', 'pages.sponsor', array(
'level' => 'warning',
'message' => 'Error processing payment! You have not been charged, please try again. 2nd'
));
}
}
}

最佳答案

您可能混淆了实时凭证和沙盒凭证。代码片段默认采用实时模式。

关于排查错误,可以看response and error code部分和 detailed error code文档

关于php - PayPal API 无法连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18906441/

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