/** * @test */ public function shouldMarkCapturedIfValidHashAndDetails() { $action = new StatusAction(); $action->setApi(new Api(['alternate_passphrase' => 'passphares', 'payee_account' => 'account', 'display_name' => 'payment', 'sandbox' => true])); $model = [Api::FIELD_V2_HASH => '3236C385DF3288D5EA29A7B7B418185E', Api::FIELD_PAYEE_ACCOUNT => 'account', Api::FIELD_PAYER_ACCOUNT => 'account', Api::FIELD_PAYMENT_AMOUNT => 0.01, Api::FIELD_PAYMENT_BATCH_NUM => 1, Api::FIELD_PAYMENT_ID => 15, API::FIELD_PAYMENT_UNITS => 'USD', API::FIELD_SUGGESTED_MEMO => 'test payment', API::FIELD_TIMESTAMPGMT => 1456652247]; $action->execute($status = new GetHumanStatus($model)); $this->assertTrue($status->isCaptured()); }
public function doneAction(Request $request) { $storage = $this->get('payum')->getStorage('challenge\\PaymentBundle\\Entity\\Orders'); $em = $this->getDoctrine()->getManager(); $token = $this->get('payum.security.http_request_verifier')->verify($request); $payment = $this->get('payum')->getGateway($token->getGatewayName()); $payment->execute($status = new GetHumanStatus($token)); if ($status->isCaptured()) { $order = $status->getFirstModel(); $order->setPayer(true); $storage->update($order); } return $this->redirect($this->generateUrl('user_lobby_acheter')); }
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 shouldNotMatchOthersThenSuspendedStatus() { $statusRequest = new GetHumanStatus(new \stdClass()); $statusRequest->markSuspended(); $this->assertTrue($statusRequest->isSuspended()); $this->assertFalse($statusRequest->isCaptured()); $this->assertFalse($statusRequest->isExpired()); $this->assertFalse($statusRequest->isCanceled()); $this->assertFalse($statusRequest->isPending()); $this->assertFalse($statusRequest->isFailed()); $this->assertFalse($statusRequest->isNew()); $this->assertFalse($statusRequest->isUnknown()); }
/** * @test */ public function shouldNotMarkCapturedIfStatusPaidAndCaptureSetTrueButPaidNotTrue() { $action = new StatusAction(); $model = array('status' => Constants::STATUS_PAID, 'captured' => true, 'paid' => false); $action->execute($status = new GetHumanStatus($model)); $this->assertFalse($status->isCaptured()); $this->assertTrue($status->isUnknown()); }
/** * @test */ public function shouldMarkCapturedIfExecCodeSuccessful() { $action = new StatusAction(); $action->execute($status = new GetHumanStatus(array('EXECCODE' => Api::EXECCODE_SUCCESSFUL))); $this->assertTrue($status->isCaptured()); }
/** * @test */ public function shouldMarkCaptureIfAuthResultIsCapture() { $action = new StatusAction(); $action->execute($status = new GetHumanStatus(['authResult' => 'CAPTURE'])); $this->assertTrue($status->isCaptured()); }
/** * @test */ public function shouldMarkCapturedIfModelHasSuccefullyUsedTokenSet() { $action = new StatusAction(); $model = array( 'card' => array('foo'), 'captured' => true, 'paid' => true, ); $action->execute($status = new GetHumanStatus($model)); $this->assertTrue($status->isCaptured()); }
/** * @test */ public function shouldMarkCapturedIfInvoiceNumberSet() { $action = new StatusAction(); $action->execute($getStatus = new GetHumanStatus(array('invoice_number' => 'aNumber'))); $this->assertTrue($getStatus->isCaptured()); }
/** * @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()); }
/** * @Route("/payment/done", name="done") */ public function doneAction(Request $request) { $token = $this->get('payum.security.http_request_verifier')->verify($request); $gateway = $this->get('payum')->getGateway($token->getGatewayName()); // Once you have token you can get the model from the storage directly. //$identity = $token->getDetails(); //$payment = $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)); $payment = $status->getFirstModel(); //invalidate the token. The url cannot be requested any more. $this->get('payum.security.http_request_verifier')->invalidate($token); //if payment is successful if ($status->isCaptured()) { $manager = $this->get('oneup_uploader.orphanage_manager')->get('gallery'); if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) { throw $this->createAccessDeniedException(); } $logger = $this->get('logger'); try { $originalNames = $this->renameFiles(); $files = $manager->uploadFiles(); $files = $this->stampFiles($files); $protectedFiles = array(); foreach ($files as $file) { $protected = new ProtectedFile(); $protected->setUserID($this->getUser()->getId()); $protected->setFileName($file->getFilename()); $protected->setOriginalName($originalNames[pathinfo($file->getFilename(), PATHINFO_FILENAME)]); $protected->setExtension($file->getExtension()); $protected->setDateProtected(new \DateTime('now')); $protected->setRegistrationNumber(pathinfo($file->getFilename(), PATHINFO_FILENAME)); $protected->setFile($file); $em = $this->getDoctrine()->getManager(); $em->persist($protected); $em->flush(); $protectedFiles[] = $protected; } //send certification email $this->get('email.sender')->sendCertificationEmail($protectedFiles); $response = $this->render('payment/success.html.twig'); } catch (\Exception $e) { $logger->critical($e->getMessage()); $response = $this->render('payment/unsuccess.html.twig'); } } else { $response = $this->render('payment/unsuccess.html.twig'); } //after 3 seconds redirect to user's profile $response->headers->set('Refresh', '3; ' . $this->get('router')->generate('fos_user_profile_show')); return $response; //to be used for debugging purposes /*return new JsonResponse(array( 'status' => $status->getValue(), 'payment' => array( 'total_amount' => $payment->getTotalAmount(), 'currency_code' => $payment->getCurrencyCode(), 'details' => $payment->getDetails(), ), ));*/ }