我已经设置了一个简单的快速结账Paypal,在开发模式下一切正常,但我在生产模式下有错误。
不能使用Symfony \ Component \ HttpFoundation \ RedirectResponse类型的对象作为数组
$responseArray = $this->requestPaypal('SetExpressCheckout', array(
'RETURNURL' => 'http://returnUrl.fr/member/payment/confirm/validate/membership/'.$ref,
'CANCELURL' => 'http://cancelUrl.fr/member/payment/cancel',
'PAYMENTREQUEST_0_AMT' => $info['price'], # amount of transaction \
'PAYMENTREQUEST_0_CURRENCYCODE' => 'EUR', # currency of transaction \
'PAYMENTREQUEST_0_DESC0' => $info['description'],
'PAYMENTREQUEST_0_CUSTOM' => $info['time'],
));
$token = $responseArray['TOKEN']; // Error line
$payPalUrl = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&useraction=commit&token='.$token.'';
return $this->redirect($payPalUrl);
METHOD RequestPaypal:
public function requestPaypal($method, $params)
{
$params = array_merge($params, array(
'METHOD' => $method,
'VERSION' => $this->getParameter('version'),
'USER' => $this->getParameter('username'),
'SIGNATURE' => $this->getParameter('signature'),
'PWD' => $this->getParameter('password'),
));
$params = http_build_query($params);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $this->getParameter('endpoint'),
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $params,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_VERBOSE => 1
));
$response = curl_exec($curl);
$responseArray = array();
parse_str($response, $responseArray);
if(curl_errno($curl))
{
$errors = curl_error($curl);
$this->addFlash('danger', $errors);
curl_close($curl);
return $this->redirectToRoute('payment');
}
if($responseArray['ACK'] == 'Success')
{
curl_close($curl);
}
return $responseArray;
}
我认为由于paypal / sandbox,代码在prod中不起作用。
请帮助
尼克
答案 0 :(得分:0)
正如我所看到的,你面临CURL错误,你的代码执行这段代码:if(curl_errno($ curl)){...}。我假设方法$ this-> redirectToRoute返回RedirectResponse对象。之后,您尝试在RedirectResponse对象上获取“TOKEN”元素,这会导致错误。要解决此问题,请添加条件以检查方法requestPaypal是否返回RedirectResponse对象并将RedirectResponse从您的控制器返回到带有Flash消息的“payment”路由,其中包含CURL错误消息。
此代码应该处理这种情况:
var request = require('supertest');
var url = "http://yourapi.com:4000";
this.timeout(15000);
describe('GET /', function() {
it('Should be status code 200', function(done) {
request(url).get('/').expect(200, done);
});
});