Sylius:如果捕获令牌不在网址中,如何通知付款?

时间:2017-11-10 19:15:27

标签: symfony sylius

我正在使用Payum创建自己的付款包。我设法使用我的付款实体正确生成付款订单,我的捆绑包正确地重定向到我的实体的付款页面(用户输入他们的卡和PIN号码)。问题是我无法验证付款。我的付款实体只允许我配置一个付款确认异步调用网址(并且它不允许我在每个订单中发送带有通知网址的参数)。

如何获取付款令牌?有没有办法从订单ID中获取付款令牌然后验证它?

1 个答案:

答案 0 :(得分:0)

好的,我想我已经做到了。这是"解决方案":

首先,我必须使用控制器atached为通知创建一个URL。

payum_ceca_notification_url:
path: /payum/ceca/bank-notification
methods: [GET, POST]
defaults:
    _controller: CecaPlugin:Notify:do

然后在我的doAction中:

    public function doAction(Request $request):Response
    {
        $params = $request->request->all();
        $order_id = (int) $params['Num_operacion']; 

        $payment = $this->container->get('sylius.repository.payment')->findOneBy(['id' => $order_id]);

        $details = $payment->getDetails();
        $cecaOptions = array(
            'Environment' => $details['Environment'],
            'MerchantID' => $details['MerchantID'],
            'AcquirerBIN' => $details['AcquirerBIN'],
            'TerminalID' => $details['TerminalID'],
            'ClaveCifrado' => $details['ClaveCifrado']);
        $apiCeca = new ApiCeca($cecaOptions);
        $apiCeca->setFormHiddens(array(
            'Num_operacion' => $details['Num_operacion'],
            'Importe' => $details['Amount'],
            'URL_OK' => $details['url_ok'],
            'URL_NOK' => $details['url_nok'].'?pagocancelado=1'
        ));

        // check my sign vs the sign sent to me by payment entity 
        $apiCeca->checkTransaction($params);
        $payment->setState(PaymentInterface::STATE_COMPLETED);
        $payment->getOrder()->setPaymentState(OrderPaymentStates::STATE_PAID);
        $manager = $this->container->get('sylius.manager.payment');
        $manager->persist($payment);
        $manager->flush();

        return new Response();
    }

我知道这不是最优雅的解决方案,但它是一个有效的解决方案,将订单标记为付费。