2016-03-25 10 views
-1

私は簡単なエクスプレスチェックアウトPaypalを設定しましたが、Devモードではうまく動作しますが、運用モードでエラーがあります。Symfony Paypal「タイプとしてRedirectResponseのオブジェクトを配列として使用できません」

タイプのSymfony \コンポーネントのオブジェクトを使用することはできません\ 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); 

メソッド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; 
} 

私はコードがPRODでは動作しませていないと思いますpaypal/sandboxのために。私が見ることができるように

ヘルプしてください

ニック

+0

あなたは私が思うトリガエラーが含まれていません掲示コード。 '$ this-> requestPaypal()'メソッドを追加してください。 '$ this-> redirect()'にもドル記号がありません。 ... – mblaettermann

答えて

0

は、あなたがCURLエラーで直面し、あなたのコードは、コードブロックを実行します。if(curl_errno($カール)){...}。私は$ this-> redirectToRouteメソッドがRedirectResponseオブジェクトを返すと仮定します。その後、エラーを引き起こすRedirectResponseオブジェクトに "TOKEN"要素を取得しようとしています。この問題を解決するには、requestPaypalメソッドがRedirectResponseオブジェクトを返すかどうかを確認するための条件を追加して、CURLエラーメッセージを含むフラッシュメッセージを使用してコントローラから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'], 
     )); 

    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

このエラーは、生きているpaypalのすべてがうまくいけばサンドボックス付きのウェブサイトでのみ発生します – Nicks

+0

原因を特定するには、CURLエラーメッセージを読んでください。サンドボックスの無効な資格情報がある可能性があります。Paypalアカウントまたはサンドボックスが無効になっている可能性があります。 –

関連する問題