douvcpx6526 2014-05-30 13:30
浏览 73

难以使用payum Bundle管理数据

I'm tryng to implement PayPal payment via IPN on my Symfony2 application. I'm using the PayumBundle and Payum Express Check out, I've followed the istructions, and the system works fine in the sand-box environment.

Here are my Controllers:

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');
}

With the base configuration I'm able to set the almount of the payment, and send to the PayPal page, the user is able to put his login and pass a pay, the callback is correctly intercepted from the controller and processed captureDoneAction(). Now my problem is to add additional information to send to PayPal that it should return to me, like the User_id , the almount, etc, all data I need to extecute the queries to effectly update the user credit on my database. I admin that problamy I miss something in the understand of the token excanged between my server and paypal server. Every help to send and grab additional iformation will be alot will be appreciated.

  • 写回答

1条回答 默认 最新

  • dphnn333971 2014-05-31 10:47
    关注

    If I get you right you need a $paymentDetails model in you done action. If so read the answer on Payum - PaymentDetails object in done action where is

    You can extend this model 'Acme\MyBundle\Entity\PaymentDetails' and add a relation with your user and some other fields that not need to paypal but could be used by you.

    By the way you do echo from the controller. It is not Symfony way, Concat all the html to the variable and return it with Response object.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题