2016-03-25 17 views
-1

Basit bir ekspres ödeme PayPal'ı ayarladım, her şey Dev Mode'da gayet iyi çalışıyor ancak üretim modunda bir hatam var.Symfony Paypal "RedirectResponse türü nesne olarak nesne kullanılamıyor"

tip Symfony \ Component nesne kullanılamaz \ HttpFoundation \ RedirectResponse dizi olarak

$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); 

YÖNTEM 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; 
} 

ben kod eşya çalışmaz gelmez düşünüyorum Paypal/sandbox nedeniyle. Ben de görebileceğiniz gibi

Yardım Lütfen

Nic

+0

ne düşünüyorum tetikleme hata içermediğini yayınlanmıştır kodu. Lütfen '$ this-> requestPaypal()' yöntemini ekleyin. Ayrıca $ this-> yönlendirme() 'de bir dolar işareti eksik. Lütfen çalıştırdığınız kodu yayınlayın, bazı düzenlenmiş şeyler değil ... – mblaettermann

cevap

0

, sen CURL hata ile karşı karşıya ve kod kod bloğunu çalıştırır: if (curl_errno ($ curl)) {...}. $ This-> redirectToRoute yönteminin RedirectResponse nesnesini döndürdüğünü varsayalım. Bundan sonra, RedirectResponse nesnesinde "TOKEN" öğesini almaya çalışıyorsunuz, bu da hataya neden oluyor. Bu sorunu gidermek için, lütfen method requestPaypal'ın RedirectResponse nesnesini döndürüp döndürmediğini kontrol etmek için koşul ekleyin ve denetleyicinizden CURL hata mesajlarını içeren flash mesajla "ödeme" yoluna geri dönün.

Bu kod, bu durumun üstesinden olmalıdır:

$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'], 
     )); 

    if ($responseArray instanceof RedirectResponse) { 
     return $responseArray; 
    } 

    $token = $responseArray['TOKEN']; 

    $payPalUrl = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&useraction=commit&token='.$token.''; 

    return $this->redirect($payPalUrl); 
+0

Bu hata sadece sanal alanda üretim yapıyorsa, aksi halde canlı paypal her şey yolunda çalışıyorsa gerçekleşir – Nicks

+0

Nedenini belirlemek için CURL hata mesajlarını okumalısınız. Belki de sandbox Paypal hesabı için geçersiz kimlik bilgileriniz var veya sandbox devre dışı. –