【问题标题】:Difficulty to Manage data with payum Bundle难以使用 payum Bundle 管理数据
【发布时间】:2014-07-20 06:51:04
【问题描述】:

我正在尝试在我的 Symfony2 应用程序上通过 IPN 实现PayPal 支付。 我正在使用 PayumBundle 和 Payum Express Check out,按照说明操作,系统在沙盒环境中运行良好。

这是我的控制器:

public function preparePaypalExpressCheckoutPaymentAction($almount)
{

    $paymentName = 'paypall';
    $storage = $this->get('payum')->getStorageForClass(
        'Acme\MyBundle\Entity\PaymentDetails',
        $paymentName
    );


    $paymentDetails = $storage->createModel();
    $paymentDetails['PAYMENTREQUEST_0_CURRENCYCODE'] = 'USD';
    $paymentDetails['PAYMENTREQUEST_0_AMT'] = $almount;
    //Aggiunti
    $paymentDetails['PAYMENTREQUEST_0_AMT'] = $almount;
    $paymentDetails['PAYMENTREQUEST_0_ITEMAMT'] = $almount;
    $paymentDetails['PAYMENTREQUEST_0_PAYMENTACTION'] = "sale";
    $paymentDetails['L_PAYMENTREQUEST_0_NAME0'] = "Recharge";
    $paymentDetails['L_PAYMENTREQUEST_0_QTY0'] = 1;
    $paymentDetails['L_PAYMENTREQUEST_0_AMT0'] = $almount;
    $paymentDetails['NOSHIPPING'] = Api::NOSHIPPING_NOT_DISPLAY_ADDRESS;
    $storage->updateModel($paymentDetails);

    $captureToken = $this->get('payum.security.token_factory')->createCaptureToken(
        $paymentName,
        $paymentDetails,
        'Genia_sepeda_quickpayResponse' // the route to redirect after capture;
    );

    $paymentDetails['INVNUM'] = $paymentDetails->getId();
    $paymentDetails['RETURNURL'] = $captureToken->getTargetUrl();
    $paymentDetails['CANCELURL'] = $captureToken->getTargetUrl();
    $storage->updateModel($paymentDetails);

    return $this->redirect($captureToken->getTargetUrl());

    ///////////////////////////////////////////

}

public function captureDoneAction(Request $request)
{
    $token = $this->get('payum.security.http_request_verifier')->verify($request);

    $payment = $this->get('payum')->getPayment($token->getPaymentName());

    $status = new BinaryMaskStatusRequest($token);
    $payment->execute($status);

    if ($status->isSuccess()) {
        // UPDATE USER DATA HERE
        $this->get('session')->getFlashBag()->set(
            'notice',
            'Successo!. Ricarica effettuata.'
        );
        $em = $this->get('doctrine')->getEntityManager();
        $user= $em->getRepository('AcmeMyBundle:User')->find(1); // JUST FOR TRY
        $credit=$user->getCredit();

        $em->persist($user)
        $em->flush();

    } else if ($status->isPending()) {
        $this->get('session')->getFlashBag()->set(
            'notice',
            'Pagamento In Sospeso. Il credito verrà aggiornato non appena il pagamento avrà successo.'
        );
    } else {
        $this->get('session')->getFlashBag()->set('error', 'Pagamento Fallito.');
    }
    foreach ($this->get('session')->getFlashBag()->get('notice', array()) as $message) {
        echo "<div class='flash-notice'>$message</div>";
    }
    foreach ($this->get('session')->getFlashBag()->get('error', array()) as $message) {
        echo "<div class='flash-notice'>$message</div>";
    }
    return new response("END");
    //return $this->redirect('homepage');
}

通过基本配置,我可以设置支付金额,并发送到 PayPal 页面,用户可以登录并通过支付,回调被控制器正确拦截并处理 captureDoneAction ()。 现在我的问题是添加其他信息以发送给PayPal,它应该返回给我,比如User_idalmount等,我需要执行查询以有效更新我的用户信用数据库。 我管理那个问题,我错过了一些在我的服务器和贝宝服务器之间交换的令牌的理解。我们将不胜感激任何帮助发送和获取额外信息的帮助。

【问题讨论】:

    标签: php symfony paypal doctrine-orm payum


    【解决方案1】:

    如果我说得对,您需要在完成操作中使用 $paymentDetails 模型。如果是这样,请阅读Payum - PaymentDetails object in done action where is上的答案

    您可以扩展此模型 'Acme\MyBundle\Entity\PaymentDetails' 并添加与您的用户的关系以及一些不需要贝宝但您可以使用的其他字段。

    顺便说一句,您从控制器执行echo。这不是 Symfony 的方式,将所有的 html 连接到变量中并用 Response 对象返回。

    【讨论】:

      猜你喜欢
      • 2016-07-21
      • 2017-10-03
      • 1970-01-01
      • 2016-05-03
      • 2015-03-24
      • 2010-09-29
      • 1970-01-01
      • 2014-07-20
      • 2016-09-20
      相关资源
      最近更新 更多