2016-03-27 9 views
0

私はominipayを自分のWebサイトでPayPal Express Checkoutと統合しようとしています。私は参照、日付、user_id、commande => [コマンドを保存しています:priceTTC、priceHT、住所、数量、トークン]を保存しているテーブルcommande(英語での注文)を持っています。私はこのエラーを持っているボタン有料でユーザーのクリックOmnipayとPayPal Expressチェックアウトの統合[symfony2]

:これは私のvalidation.html.twig

<form action="{{ path('postPayment', { 'id' : commande.id }) }}" 
    method="POST"/> 
    <input name="token" type="hidden" value="{{ commande.commande.token }}" /> 
    <input name="price" type="hidden" value="{{ commande.commande.priceTTC }}" /> 
    <input name="date" type="hidden" value="{{ commande.date|date('dmyhms') }}" /> 
    <button type="submit" class="btn btn-success pull-right">Pay</button> 
    </form> 

ある

Controller "FLY\BookingsBundle\Controller\PayController::postPaymentAction" for URI "/payment/2" is not callable.

をrouting.ymlの

postPayment: 
    pattern: /payment/{id} 
    defaults: { _controller: FLYBookingsBundle:Pay:postPayment } 

getSuccessPayment: 
    pattern: /success/{id} 
    defaults: { _controller: FLYBookingsBundle:Pay:getSuccessPayment } 

PayController.php

class PayController extends Controller 
{ 

    public function postPayment (Commandes $commande) 
    { 
     $params = array(
      'cancelUrl' => 'here you should place the url to which the users will be redirected if they cancel the payment', 
      'returnUrl' => 'here you should place the url to which the response of PayPal will be proceeded', // in your case    // you have registered in the routes 'payment_success' 
      'amount' => $commande->get('priceTTC'), 
     ); 

     session()->put('params', $params); // here you save the params to the session so you can use them later. 
     session()->save(); 

     $gateway = Omnipay::create('PayPal_Express'); 
     $gateway->setUsername('xxxxxxxxx-facilitator_api1.gmail.com'); // here you should place the email of the business sandbox account 
     $gateway->setPassword('xxxxxxxxxxxxxx'); // here will be the password for the account 
     $gateway->setSignature('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); // and the signature for the account 
     $gateway->setTestMode(true); // set it to true when you develop and when you go to production to false 
     $response = $gateway->purchase($params)->send(); // here you send details to PayPal 

     if ($response->isRedirect()) { 
      // redirect to offsite payment gateway 
      $response->redirect(); 
     } 
     else { 
      // payment failed: display message to customer 
      echo $response->getMessage(); 
     } 
    } 

public function getSuccessPayment (Auth $auth, Transaction $transaction) 
    { 
     $gateway = Omnipay::create('PayPal_Express'); 
     $gateway->setUsername('xxxxxxxxxxx-facilitator_api1.gmail.com\''); // here you should place the email of the business sandbox account 
     $gateway->setPassword('xxxxxxxxxxxxxxxx'); // here will be the password for the account 
     $gateway->setSignature('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); // and the signature for the account 
     $gateway->setTestMode(true); 
     $params = session()->get('params'); 
     $response = $gateway->completePurchase($params)->send(); 
     $paypalResponse = $response->getData(); // this is the raw response object 

     if(isset($paypalResponse['PAYMENTINFO_0_ACK']) && $paypalResponse['PAYMENTINFO_0_ACK'] === 'Success') { 
      // here you process the response. Save to database ... 

     } 
     else { 
      // Failed transaction ... 
     } 
    } 
} 
+0

これは、オムニペイの問題よりもsymfonyの問題に似ています。コントローラーの動作で何をしているのかは、全方位の観点からは正しいように見えますが、エラーメッセージは、symfonyルーターがコントローラーを見つけていないことを示しているようです。 私はsymfonyのエキスパートではありませんが、おそらくあなたのコントローラーアクションはpostPaymentの代わりにpostPaymentActionという名前にする必要がありますか? – delatbabel

+0

routing.ymlで経路を削除しましたが、私のコントローラの上に次のようなルートを作成しました: '/ ** * * @Route("/"、name =" pay ") * @Method(" GET ") * /'次にvalidation.html.twigで 'pay 'でパスを変更しました。それはうまくいくようですが、私がボタンをクリックすると、空白のページにリダイレクトされます。 'http://127.0.0.1/symfony/web/app_dev.php/?id = 34'。私はpaypalにリダイレクトする必要がありますので、ユーザーが支払いをすることができると思います...? – Sirius

+0

私はまた、postPaymentをpostPaymentActionに変更しました。今、私はこのエラーがあります: '名前空間" FLY \ BookingsBundle \ Controller "(" params '、$ params); put('私が持っているコントローラはsymfony2ではなくlaravelで動作するように作られているからです。 – Sirius

答えて

1

symfonyコントローラの呼び出し可能メソッドは、アクションワードで終了する必要があります。

public function postPayment(...) - >public function postPaymentAction(...)

はその後、あなたのコントローラのメソッドのいくつかは、彼らがlaravelベースの代わりに思えるので、symfony-有効ではありません。

// Laravel 
session()->put('params', $params); // here you save the params to the session so you can use them later. 
session()->save(); 

--> 
// Symfony 

use Symfony\Component\HttpFoundation\Request; 

public function postPaymentAction(Commandes $commande, Request $request) 

$request->getSession(); // The request should be incldued as an action parameter 
$session->set('params', $params); 

その後、Omnipay自体の使用について、私はsymfonyのコントローラ内のサードパーティのライブラリを使用すると、ひどい練習だと思います。

代わりにサービスを使用し、その構成(潜在的なパラメータ)から資格情報を渡すことをおすすめします。

http://symfony.com/doc/current/service_container.html

// Direct, bad practice 
$gateway = Omnipay::create('PayPal_Express'); 
$gateway->setUsername('xxxxxxxxx-facilitator_api1.gmail.com'); // here you should place the email of the business sandbox account 
$gateway->setPassword('xxxxxxxxxxxxxx'); // here will be the password for the account 
$gateway->setSignature('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); // and the signature for the account 
$gateway->setTestMode(true); // set it to true when you develop and when you go to production to false 

$response = $gateway->purchase($params)->send(); // here you send details to PayPal 

あなたも、すでにそれを行うためにサードパーティのバンドルを持っている:

https://github.com/colinodell/omnipay-bundle

// Using a Service to get a full-configured gateway 
$gateway = $this->get('omnipay')->getDefaultGateway(); 

$response = $gateway->purchase($params)->send(); 

あなたはまた、あなたのルーターファイル内のHTTPメソッドをロックすることができ、でも、オプションの場合:

postPayment: 
    pattern: /payment/{id} 
    method: POST 
    defaults: { _controller: FLYBookingsBundle:Pay:postPayment } 

getSuccessPayment: 
    pattern: /success/{id} 
    method: GET 
    defaults: { _controller: FLYBookingsBundle:Pay:getSuccessPayment } 
+0

ありがとうございます。私はすでに私の問題の解決策を見つけて、私はPayumでPaypalエクスプレスチェックアウトを使うことに決めました。私の次のプロジェクトでは、私はOmnipayを使用しようとし、あなたの答えが役に立つでしょう。 :) – Sirius

関連する問題