ETSGlobal / ETSPaymentDotpayBundle

A Dotpay provider for JMSPaymentCoreBundle
9 stars 13 forks source link

Omit ssl.dotpay.pl and redirecting to complete #9

Closed ghostiiq closed 10 years ago

ghostiiq commented 10 years ago

It's redirecting me to complete page, where I am receiving error: Attempted to call function "normalizer_normalize" from namespace "ETS\Payment\DotpayBundle\Tools" in line: $result = $this->ppc->approveAndDeposit($payment->getId(), $payment->getTargetAmount());

config.yml

ets_payment_dotpay: direct: id: XXX pin: XXX url: https://ssl.dotpay.pl/ type: 2 return_url: http://mieszkaniaplus.pl

PaymentControler.php

public function detailsAction($id)
{   
    $form = $this->get('form.factory')->create('jms_choose_payment_method', null, array(
        'amount'   => '0.01',
        'currency' => 'PLN',
        'default_method' => 'dotpay_direct', // Optional
        'predefined_data' => array(
            'dotpay_direct' => array(
                'street'    => '',
                'phone'     => '',
                'postcode'  => '',
                'lastname'  => '',
                'firstname' => '',
                'email'     => '',
                'country'   => 'Polska',
                'city'      => '',
                'lang'      => 'PL',
                'return_url' => $this->router->generate('payment_complete', array(
                    'id' => $id,
                ), true),
            ),
            'paypal_express_checkout' => array(
                'return_url' => $this->router->generate('payment_complete', array(
                    'id' => $id,
                ), true),
                'cancel_url' => $this->router->generate('ibw_mieszkaniedc_homepage', array(
                ), true)
            ),
        ),
    ));

    if ('POST' === $this->request->getMethod()) {
        $form->bind($this->request);

        if ($form->isValid()) {
            $this->ppc->createPaymentInstruction($instruction = $form->getData());

            $oferta = $this->em->getRepository('IbwMieszkanieDCBundle:Oferta')->find($id);
            if (!$oferta) {
                throw $this->createNotFoundException('Nie znaleziono danego ogłoszenia.');
            }

            $zamowienie=new Zamowienie($oferta);
            $zamowienie->setPaymentInstruction($instruction);
            $this->em->persist($zamowienie);
            $this->em->flush($zamowienie);

            return new RedirectResponse($this->router->generate('payment_complete', array(
                'id' => $id,
            )));
        }
    }

    return array(
        'form' => $form->createView(),
        'id'   => $id,
    );
}

public function completeAction($id)
{
    $zamowienie = $this->em->getRepository('IbwMieszkanieDCBundle:Zamowienie')->findOneByOferta($id);

    if (!$zamowienie) {
        throw $this->createNotFoundException('Nie znaleziono danego zamówienia.');
    }

    $instruction = $zamowienie->getPaymentInstruction();
    if (null === $pendingTransaction = $instruction->getPendingTransaction()) {
        $payment = $this->ppc->createPayment($instruction->getId(), $instruction->getAmount() - $instruction->getDepositedAmount());
    } else {
        $payment = $pendingTransaction->getPayment();
    }

    $result = $this->ppc->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('Transakcja nie powiodła się z powodu: '.$result->getReasonCode());
    }

    // payment was successful, do something interesting with the order
    $oferta = $this->em->getRepository('IbwMieszkanieDCBundle:Oferta')->find($id);
    $oferta->setCzyPromowane(true);
    $this->em->flush();

    return new RedirectResponse($this->router->generate('ibw_mieszkaniedc_homepage', array(
    )));

}