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

Approved status not reached #53

Open
tworzenieweb opened this issue Nov 30, 2012 · 1 comment
Open

Approved status not reached #53

tworzenieweb opened this issue Nov 30, 2012 · 1 comment

Comments

@tworzenieweb
Copy link

Hi,

i was trying to make some custom action when PaymentInterface::STATE_APPROVED was reached.

I am logging all status changes:

Payment status changed from 6 to 2
Payment status changed from 2 to 8

And it is over transition form 8 to 1 is missing i thing.

The last state that is caught by listener is 8 - STATE_DEPOSITED

Also payment ends with this status. On the other hand in paypal dev accounts payment is verified and completed on both sides - client and store.

My code for the last step is very typical and based on doc.

/**
     * @Route("/payment/complete/{id}", name="payment_complete")
     * @Template()
     */
    public function paymentCompleteAction($id) {

        $order = $this->em->getRepository('WNCOrganizerBundle:Donate')->find($id);

        $instruction = $order->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('Transaction was not successful: '.$result->getReasonCode());
        }


    }

The listener looks like this:

class PaymentListener
{
    /**
     * @var EntityManager
     */
    private $em;

    private $logger;


    /**
     * @param EntityManager $em
     */
    public function __construct(EntityManager $em, LoggerInterface $logger)
    {
        $this->em = $em;
        $this->logger = $logger;
    }

    /**
     * @param PaymentStateChangeEvent $event
     */
    public function onPaymentStateChange(PaymentStateChangeEvent $event)
    {

      $this->logger->debug(sprintf('Payment status changed from %s to %s: ', $event->getOldState(), $event->getNewState()));

        switch ($event->getNewState()) {
            case PaymentInterface::STATE_APPROVED: {
                $donate = $this->em->getRepository('WNCOrganizerBundle:Order')->findOneByPaymentInstruction($event->getPaymentInstruction());

                $donate->setConfirmed(true);
                $this->em->persist($donate);
                $this->em->flush($donate);


            } break;
        }
    }
}
@mtotheikle
Copy link

Per the model diagram wouldn't the correct state changes be from:

Payment status changed from 6 to 2
Payment status changed from 2 to 1
Payment status changed from 1 to 8

This means that it goes from New -> Approving -> Approved -> Deposited since Deposited means that it was already approved.

ruudk pushed a commit to ruudk/JMSPaymentPaypalBundle that referenced this issue Apr 10, 2014
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

2 participants