/** * @View() * @Route("/payment/done", name="app_payment_done") * @param Request $request * @return JsonResponse */ public function paymentDoneAction(Request $request) { $token = $this->get('payum.security.http_request_verifier')->verify($request); $identity = $token->getDetails(); $model = $this->get('payum')->getStorage($identity->getClass())->find($identity); $gateway = $this->get('payum')->getGateway($token->getGatewayName()); // or Payum can fetch the model for you while executing a request (Preferred). $gateway->execute($status = new GetHumanStatus($token)); $payment = $status->getFirstModel(); $paymentSuccess = false; $mailSent = false; $order = null; if ($status->isAuthorized()) { $entityManager = $this->getDoctrine()->getEntityManager(); $order = $entityManager->getRepository('AppBundle:TicketsOrder')->find($payment->getOrderId()); $order->setValidate(true); $entityManager->flush(); $ticketsSender = $this->get('app.tickets_sender'); try { $ticketsSender->sendTickets($order); $mailSent = true; } catch (\Swift_TransportException $e) { // the mail is not sent } $paymentSuccess = true; } return array('paymentSuccess' => $paymentSuccess, 'mailSent' => $mailSent, 'order' => $order); }
/** * @test */ public function shouldNotMatchOthersThenCapturedStatus() { $statusRequest = new GetHumanStatus(new \stdClass()); $statusRequest->markCaptured(); $this->assertTrue($statusRequest->isCaptured()); $this->assertFalse($statusRequest->isCanceled()); $this->assertFalse($statusRequest->isSuspended()); $this->assertFalse($statusRequest->isAuthorized()); $this->assertFalse($statusRequest->isRefunded()); $this->assertFalse($statusRequest->isExpired()); $this->assertFalse($statusRequest->isPending()); $this->assertFalse($statusRequest->isFailed()); $this->assertFalse($statusRequest->isNew()); $this->assertFalse($statusRequest->isUnknown()); }
public function viewAction(Request $request) { $token = $this->getHttpRequestVerifier()->verify($request); $gateway = $this->getPayum()->getGateway($token->getGatewayName()); try { $gateway->execute(new Sync($token)); } catch (RequestNotSupportedException $e) { } $gateway->execute($status = new GetHumanStatus($token)); $refundToken = null; if ($status->isCaptured() || $status->isAuthorized()) { $refundToken = $this->getTokenFactory()->createRefundToken($token->getGatewayName(), $status->getFirstModel(), $request->getUri()); } return $this->render('AcmePaymentBundle:Details:view.html.twig', array('status' => $status->getValue(), 'payment' => htmlspecialchars(json_encode(iterator_to_array($status->getFirstModel()), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)), 'gatewayTitle' => ucwords(str_replace(array('_', '-'), ' ', $token->getGatewayName())), 'refundToken' => $refundToken)); }
/** * @Security("has_role('ROLE_STUDENT')") */ public function paymentDoneAction(Request $request) { $token = $this->get('payum.security.http_request_verifier')->verify($request); $identity = $token->getDetails(); $model = $this->get('payum')->getStorage($identity->getClass())->find($identity); $gateway = $this->get('payum')->getGateway($token->getGatewayName()); // you can invalidate the token. The url could not be requested any more. // $this->get('payum.security.http_request_verifier')->invalidate($token); // Once you have token you can get the model from the storage directly. //$identity = $token->getDetails(); //$details = $payum->getStorage($identity->getClass())->find($identity); // or Payum can fetch the model for you while executing a request (Preferred). $gateway->execute($status = new GetHumanStatus($token)); $details = $status->getFirstModel(); // you have order and payment status // so you can do whatever you want for example you can just print status and payment details. if ($status->isAuthorized() || $status->isCaptured()) { $request->getSession()->getFlashBag()->add('success', 'offer.flash.canceled'); } return new JsonResponse(array('status' => $status->getValue(), 'details' => iterator_to_array($details))); }
/** * @test */ public function shouldMarkCaptureIfStatusIsClosed() { $action = new StatusAction(); $action->execute($status = new GetHumanStatus(['http_status_code' => 200, 'transaction' => ['response_code' => 20000, 'status' => 'closed']])); $this->assertTrue($status->isAuthorized()); }
/** * @test */ public function shouldMarkAuthorizedIfStatusPaidAndCaptureSetFalse() { $action = new StatusAction(); $model = array('status' => Constants::STATUS_PAID, 'captured' => false); $action->execute($status = new GetHumanStatus($model)); $this->assertTrue($status->isAuthorized()); }
/** * @test */ public function shouldMarkAuthorizedIfAuthResultIsAuthorized() { $action = new StatusAction(); $action->execute($status = new GetHumanStatus(['authResult' => 'AUTHORISED'])); $this->assertTrue($status->isAuthorized()); }
/** * @test */ public function shouldMarkAuthorizedIfStatusAccepted() { $action = new StatusAction(); $action->execute($getStatus = new GetHumanStatus(array('status' => \KlarnaFlags::ACCEPTED))); $this->assertTrue($getStatus->isAuthorized()); }
/** * @test */ public function shouldNotMatchOthersThenPayedoutStatus() { $getStatus = new GetHumanStatus(new \stdClass()); $getStatus->markPayedout(); $this->assertTrue($getStatus->isPayedout()); $this->assertFalse($getStatus->isCaptured()); $this->assertFalse($getStatus->isAuthorized()); $this->assertFalse($getStatus->isExpired()); $this->assertFalse($getStatus->isCanceled()); $this->assertFalse($getStatus->isPending()); $this->assertFalse($getStatus->isFailed()); $this->assertFalse($getStatus->isNew()); $this->assertFalse($getStatus->isUnknown()); }