2013-03-03 4 views
8

私はJMSPaymentCoreBundleJMSPaymentPaypalBundleと使用しようとしていますが、どのように行うのか明確な例は見つかりません。PayPal in Symfony2

私はドキュメントに記載されているすべての手順を実行しており、動作させることができません。誰でも助けてくれますか?支払命令を作成するための

+0

働いていないとはどういう意味ですか?あなたはどこまで手に入れましたか? – hacfi

答えて

8

デフォルトの方法は、jms_choose_payment_methodフォームである:

$form = $this->getFormFactory()->create('jms_choose_payment_method', null, array(
     'amount' => 12.99, 
     'currency' => 'EUR', 
     'default_method' => 'payment_paypal', // Optional 
     'predefined_data' => array(
      'paypal_express_checkout' => array(
       'return_url' => $this->get('router')->generate('payment_complete', array(
        'number' => $order->getOrderNumber(), 
       ), true), 
       'cancel_url' => $this->get('router')->generate('payment_cancel', array(
        'number' => $order->getOrderNumber(), 
       ), true) 
      ), 
     ), 
    )); 

また、手動での支払い命令を作成することができます。

 use JMS\Payment\CoreBundle\Entity\ExtendedData; 
     use JMS\Payment\CoreBundle\Entity\Payment; 
     use JMS\Payment\CoreBundle\PluginController\Result; 
     use JMS\Payment\CoreBundle\Plugin\Exception\ActionRequiredException; 
     use JMS\Payment\CoreBundle\Plugin\Exception\Action\VisitUrl; 
     use JMS\Payment\CoreBundle\Entity\PaymentInstruction; 


     $extendedData = new ExtendedData(); 
     $extendedData->set('return_url', $this->get('router')->generate('payment_complete', array(
       'number' => $order->getOrderNumber(), 
      ), true)); 

     $extendedData->set('cancel_url', $this->get('router')->generate('payment_cancel', array(
       'number' => $order->getOrderNumber(), 
      ), true)); 

     $instruction = new PaymentInstruction((float)$order->getCharge() > 0 ? $order->getCharge() : $order->getAmount(), 'EUR', 'paypal_express_checkout', $extendedData); 
     $this->get('payment.plugin_controller')->createPaymentInstruction($instruction); 

     $order->setPaymentInstruction($instruction); 
     $em = $this->get('doctrine.orm.entity_manager'); 
     $em->persist($order); 
     $em->flush(); 

マイpayment_completeルートは次のようになります。

public function completeAction(Booking $order) 
{ 
    $instruction = $order->getPaymentInstruction(); 
    if (($instruction->getAmount() - $instruction->getDepositedAmount()) > 0) { 
     if (null === $pendingTransaction = $instruction->getPendingTransaction()) { 
      $payment = $this->get('payment.plugin_controller')->createPayment($instruction->getId(), $instruction->getAmount() - $instruction->getDepositedAmount()); 
     } else { 
      $payment = $pendingTransaction->getPayment(); 
     } 

     $result = $this->get('payment.plugin_controller')->approveAndDeposit($payment->getId(), $payment->getTargetAmount()); 
     if (Result::STATUS_PENDING === $result->getStatus()) { 
      $ex = $result->getPluginException(); 

      if ($ex instanceof ActionRequiredException) { 
       $action = $ex->getAction(); 

       if ($action instanceof VisitUrl) { 
        return new RedirectResponse($action->getUrl()); 
       } 

       throw $ex; 
      } 
     } else if (Result::STATUS_SUCCESS !== $result->getStatus()) { 
      throw new \RuntimeException('Transaction was not successful: '.$result->getReasonCode()); 
     } 
    } 

    $order->setTransactionAmount((float)$order->getAmount()); 
    $creditPurchased = (float)$order->getCharge() > (float)$order->getAmount() ? (float)$order->getCharge() - (float)$order->getAmount() : 0; 
    $em->persist($order); 
    $em->flush(); 

http://jmsyst.com/bundles/JMSPaymentCoreBundle/master/usage

+0

私はちょうどあなたが支払う金額と "今支払う"ボタンを言うことができるフォームが必要です。:D 私はこの正確なすべての支払いバンドルのデータフローを理解していないと思う。なぜ支払い命令が注文と同じではないのですか? これは間違いありませんか? 1金額を書き込むために入力があるフォームをレンダリングします(注文の作成と書き出し)。 2 postデータとorderNumberを送信して、 "支払方法の選択"フォームで(以前のフォーム内で)payment_detailsルートをレンダリングします。 3 Orderエンティティを更新し、他のすべてをフラッシュします。 – Xavi

19

Payum bundlebridgeでの支払いをサポートしています。このリンクには、開始方法が記載されています。

  • 担保キャプチャアクション:バンドルの

    使い方はあなたにいくつかの利点を提供します。

  • クレジットカードフォームをお持ちの場合は、クレジットカードをご利用いただけます。
  • 設定が簡単IPN。通知アクションも保護されています。
  • すべてのomnipayゲートウェイ(25 +)、jmsプラグイン(+ 10)およびペイダムネイティブlibsの組み込みサポート。
  • Payum paypal libは、定期払いとデジタル商品を箱から取り出してサポートします。
  • ストレージは支払いプロセスに統合されているため、失われた可能性のあるデータについて心配する必要はありません。
  • ドメインにやさしい。確かにPayumはいくつかのモデルを提供していますが、それらを使用するようにあなたを制限するものではありません。
  • すでにPSR-0ロガーをサポートしています。 devでは、実行されたpayumアクションを簡単なデバッグに記録します(symfonyのプロファイルログタブを参照)。
  • 複数の支払い設定が可能です(EUの場合は1つ、米国の場合は1つのPaypalアカウント)
  • 非常にカスタマイズ可能です。カスタムPayumアクション、拡張機能、またはストレージを追加します。
  • 起動に役立つsymfonyサンドボックス(code | web)があります。

P.それは機能の完全なリストではありません。