Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ghostiiq opened this issue May 30, 2014 · 0 comments
Closed

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

ghostiiq opened this issue May 30, 2014 · 0 comments

Comments

@ghostiiq
Copy link

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(
    )));

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant