1

我正在尝试PayPal在我的 Symfony2 应用程序上通过 IPN 实现支付。我正在使用 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等,我需要执行查询以有效更新数据库上的用户信用的所有数据。我管理那个问题,我错过了一些在我的服务器和贝宝服务器之间交换的令牌的理解。发送和获取额外信息的每一个帮助将不胜感激。

4

1 回答 1

0

如果我说对了,您需要在完成操作中使用 $paymentDetails 模型。如果是这样,请阅读 Payum 上的答案- 完成操作中的 PaymentDetails 对象在哪里

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

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

于 2014-05-31T10:47:37.393 回答