/**
  * @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);
 }
Пример #2
0
 /**
  * {@inheritDoc}
  *
  * @param $request Authorize
  */
 public function execute($request)
 {
     RequestNotSupportedException::assertSupports($this, $request);
     /** @var $payment Payment */
     $payment = $request->getModel();
     $this->gateway->execute($status = new GetHumanStatus($payment));
     if ($status->isNew()) {
         $this->gateway->execute(new ObtainMissingDetailsRequest($payment, $request->getToken()));
         try {
             $this->gateway->execute($convert = new Convert($payment, 'array', $request->getToken()));
             $payment->setDetails($convert->getResult());
         } catch (RequestNotSupportedException $e) {
             $payumPayment = new PayumPayment();
             $payumPayment->setNumber($payment->getNumber());
             $payumPayment->setTotalAmount($payment->getTotalAmount());
             $payumPayment->setCurrencyCode($payment->getCurrencyCode());
             $payumPayment->setClientEmail($payment->getPayer()->getEmail());
             $payumPayment->setClientId($payment->getPayer()->getId() ?: $payment->getPayer()->getEmail());
             $payumPayment->setDescription($payment->getDescription() ?: sprintf('Payment %s', $payment->getNumber()));
             $payumPayment->setCreditCard($payment->getCreditCard());
             $payumPayment->setDetails($payment->getDetails());
             $this->gateway->execute($convert = new Convert($payumPayment, 'array', $request->getToken()));
             $payment->setDetails($convert->getResult());
         }
     }
     $details = ArrayObject::ensureArrayObject($payment->getDetails());
     try {
         $request->setModel($details);
         $this->gateway->execute($request);
     } finally {
         $payment->setDetails((array) $details);
     }
 }
 /**
  * @Route("/donePayment", name="payment_done" )
  */
 public function doneAction(Request $request)
 {
     $token = $this->get('payum.security.http_request_verifier')->verify($request);
     $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();
     //$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();
     // 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->getValue() === "pending" || $status->getValue() === "success" || $status->getValue() === "captured") {
         $em = $this->getDoctrine()->getManager();
         $usr = $this->get('security.context')->getToken()->getUser()->getUser();
         $usr->setPremium(true);
         $em->persist($usr);
         $em->flush();
         return $this->redirect($this->generateUrl('profile'));
     } else {
         //var_dump($status->getValue());
         return $this->redirect($this->generateUrl('get_premium'));
     }
 }
Пример #4
0
    /**
     * {@inheritDoc}
     *
     * @param Capture $request
     */
    public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);

        /** @var $order OrderInterface */
        $order = $request->getModel();

        $this->payment->execute($status = new GetHumanStatus($order));
        if ($status->isNew()) {
            $this->payment->execute(new FillOrderDetails($order, $request->getToken()));
        }

        $details = ArrayObject::ensureArrayObject($order->getDetails());

        $request->setModel($details);
        try {
            $this->payment->execute($request);

            $order->setDetails($details);
        } catch (\Exception $e) {
            $order->setDetails($details);

            throw $e;
        }
    }
Пример #5
0
 /**
  * @test
  */
 public function shouldMarkFailedIfHashIsInvalid()
 {
     $action = new StatusAction();
     $action->setApi(new Api(['alternate_passphrase' => 'passphares', 'payee_account' => 'account', 'display_name' => 'payment', 'sandbox' => true]));
     $model = [Api::FIELD_V2_HASH => 'invalid', 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->isFailed());
 }
Пример #6
0
 /**
  * @test
  */
 public function shouldMarkUnknownIfResultSuccessButTrxTypeNotPurchaseOne()
 {
     $action = new StatusAction();
     $status = new GetHumanStatus(array('TRXTYPE' => Api::TRXTYPE_CREDIT, 'RESULT' => Api::RESULT_SUCCESS));
     //guard
     $status->markNew();
     $action->execute($status);
     $this->assertTrue($status->isUnknown());
 }
 public function done($payum_token)
 {
     /** @var Request $request */
     $request = \App::make('request');
     $request->attributes->set('payum_token', $payum_token);
     $token = $this->getHttpRequestVerifier()->verify($request);
     $payment = $this->getPayum()->getPayment($token->getPaymentName());
     $payment->execute($status = new GetHumanStatus($token));
     return \Response::json(array('status' => $status->getValue(), 'details' => iterator_to_array($status->getFirstModel())));
 }
Пример #8
0
 public function verifyRequest(VerifyRequestCommand $command)
 {
     $token = $this->requestVerifier->verify($command->getRequest());
     $gateway = $this->registry->getGateway($token->getGatewayName());
     $gateway->execute($status = new GetHumanStatus($token));
     $payment = $status->getFirstModel();
     $this->requestVerifier->invalidate($token);
     $event = new RequestVerifiedEvent($status, $payment);
     $this->eventBus->handle($event);
 }
Пример #9
0
 /**
  * @param mixed $request
  *
  * @throws \Payum\Core\Exception\RequestNotSupportedException if the action dose not support the request.
  */
 public function execute($request)
 {
     /** @var $request Notify */
     RequestNotSupportedException::assertSupports($this, $request);
     $setPayU = new SetPayU($request->getToken());
     $setPayU->setModel($request->getModel());
     $this->gateway->execute($setPayU);
     $status = new GetHumanStatus($request->getToken());
     $status->setModel($request->getModel());
     $this->gateway->execute($status);
 }
Пример #10
0
 protected function _actionDone(KControllerContextInterface $context)
 {
     $token = $this->getHttpRequestVerifier()->verify($context->getRequest()->getQuery()->toArray());
     $identity = $token->getDetails();
     $model = $this->getPayum()->getStorage($identity->getClass())->find($identity);
     $this->setGateway($token->getGatewayName());
     $gateway = $this->getPayum()->getGateway($token->getGatewayName());
     $gateway->execute($status = new GetHumanStatus($model));
     $context->params = array('status' => $status, 'token' => $token);
     $this->getHttpRequestVerifier()->invalidate($token);
     $this->execute($status->getValue(), $context);
 }
 public function viewOrderAction(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));
     /** @var PaymentInterface $payment */
     $payment = $status->getFirstModel();
     return $this->render('AcmePaymentBundle:Details:viewOrder.html.twig', array('status' => $status->getValue(), 'payment' => htmlspecialchars(json_encode(array('client' => array('id' => $payment->getClientId(), 'email' => $payment->getClientEmail()), 'number' => $payment->getNumber(), 'description' => $payment->getCurrencyCode(), 'total_amount' => $payment->getTotalAmount(), 'currency_code' => $payment->getCurrencyCode(), 'details' => $payment->getDetails()), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)), 'gatewayTitle' => ucwords(str_replace(array('_', '-'), ' ', $token->getGatewayName()))));
 }
Пример #12
0
 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'));
 }
Пример #13
0
 /**
  * {@inheritDoc}
  *
  * @param Payout $request
  */
 public function execute($request)
 {
     RequestNotSupportedException::assertSupports($this, $request);
     /** @var $payout PayoutInterface */
     $payout = $request->getModel();
     $this->gateway->execute($status = new GetHumanStatus($payout));
     if ($status->isNew()) {
         $this->gateway->execute($convert = new Convert($payout, 'array', $request->getToken()));
         $payout->setDetails($convert->getResult());
     }
     $details = ArrayObject::ensureArrayObject($payout->getDetails());
     $request->setModel($details);
     try {
         $this->gateway->execute($request);
     } finally {
         $payout->setDetails($details);
     }
 }
Пример #14
0
 public function done(Request $request, $payum_token)
 {
     $request->attributes->set('payum_token', $payum_token);
     $token = $this->getPayum()->getHttpRequestVerifier()->verify($request);
     $gateway = $this->getPayum()->getGateway($token->getGatewayName());
     $gateway->execute($status = new GetHumanStatus($token));
     $status_txt = $status->getValue();
     $details = iterator_to_array($status->getFirstModel());
     if ($status_txt == "captured") {
         if ($details['approved'] == true && $details['declined'] == false) {
             $request->session()->put("payment_data", serialize($details));
             return redirect()->route("cart_done");
         } else {
             return redirect()->route("cart")->with("error", "Payment error , validation error ");
         }
     } else {
         return redirect()->route("cart")->with("error", "Payment error , statut not captured " . $status_txt);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function onPostExecute(Context $context)
 {
     if ($context->getPrevious()) {
         return;
     }
     /** @var Generic $request */
     $request = $context->getRequest();
     if (false == $request instanceof Generic) {
         return;
     }
     if ($request instanceof GetStatusInterface) {
         return;
     }
     if ($request->getFirstModel() instanceof Payment) {
         /** @var Payment $payment */
         $payment = $request->getFirstModel();
         $context->getGateway()->execute($status = new GetHumanStatus($payment));
         $payment->setStatus($status->getValue());
     }
 }
Пример #16
0
 /**
  * @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)));
 }
Пример #17
0
 /**
  * done.
  *
  * @method done
  *
  * @param \Illuminate\Http\Request $request
  * @param string                   $payumToken
  * @param callable                 $closure
  *
  * @return mixed
  */
 public function done(Request $request, $payumToken, callable $closure)
 {
     return $this->send($request, $payumToken, function ($gateway, $token, $httpRequestVerifier) use($closure) {
         $gateway->execute($status = new GetHumanStatus($token));
         $payment = $status->getFirstModel();
         return $closure($status, $payment, $gateway, $token, $httpRequestVerifier);
     });
 }
Пример #18
0
 /**
  * @test
  */
 public function shouldMarkUnknownIfExecCodeTimeOut()
 {
     $action = new StatusAction();
     $action->execute($status = new GetHumanStatus(array('EXECCODE' => Api::EXECCODE_TIME_OUT)));
     $this->assertTrue($status->isUnknown());
 }
Пример #19
0
 public function doneAction(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();
     if ($status == true) {
         // Validation email
         $message = \Swift_Message::newInstance()->setSubject('Validation de votre commande')->setFrom(array('*****@*****.**' => 'Apx Trade'))->setTo($this->container->get('security.context')->getToken()->getUser()->getEmailCanonical())->setCharset('utf-8')->setContentType('text/html')->setBody($this->renderView('EcommerceBundle:Default:SwiftLayout/validationOrder.html.twig', array('user' => $this->container->get('security.context')->getToken()->getUser())));
         $this->get('mailer')->send($message);
         $this->get('session')->getFlashBag()->add('success', 'Votre commande est valider avec success');
         return $this->redirect($this->generateUrl('invoices'));
     }
     $this->get('session')->getFlashBag()->add('warning', 'Une erreur est survenue lors du paiement');
     return $this->redirect($this->generateUrl('cart'));
     // you have order and payment status
     // so you can do whatever you want for example you can just print status and payment details.
     //return new JsonResponse(array(
     //    'status' => $status->getValue(),
     //    'details' => iterator_to_array($details),
     //));
 }
Пример #20
0
 /**
  * @test
  */
 public function shouldMarkUnknownIfAuthResultIsUnknown()
 {
     $action = new StatusAction();
     $action->execute($status = new GetHumanStatus(['authResult' => 'SomeStatus']));
     $this->assertTrue($status->isUnknown());
 }
Пример #21
0
 /**
  * @test
  */
 public function shouldMarkUnknownIfStatusCouldBeGuessed()
 {
     $action = new StatusAction();
     $model = array('card' => array('foo'), 'captured' => false, 'paid' => true);
     $status = new GetHumanStatus($model);
     $status->markPending();
     $action->execute($status);
     $this->assertTrue($status->isUnknown());
 }
 /**
  * @test
  */
 public function shouldMarkFailedIfRecurringStatusIsFailed()
 {
     $action = new PaymentDetailsStatusAction();
     $status = new GetHumanStatus(array('recurringStatus' => RecurringApi::RECURRINGSTATUS_FAILED, 'orderId' => 'anId', 'autoPay' => false));
     //guard
     $status->markUnknown();
     $action->execute($status);
     $this->assertTrue($status->isFailed());
 }
Пример #23
0
 /**
  * @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());
 }
Пример #24
0
 /**
  * @test
  */
 public function shouldMarkUnknownIfStatusUnknown()
 {
     $action = new StatusAction();
     $action->execute($getStatus = new GetHumanStatus(array('status' => 'unknown')));
     $this->assertTrue($getStatus->isUnknown());
 }
Пример #25
0
 /**
  * @test
  */
 public function shouldMarkUnknownIfStatusCouldBeGuessed()
 {
     $action = new StatusAction();
     $model = array('status' => 'unknown');
     $status = new GetHumanStatus($model);
     $status->markPending();
     $action->execute($status);
     $this->assertTrue($status->isUnknown());
 }
Пример #26
0
 /**
  * @test
  */
 public function shouldMarkRefundedIfRefundInvoiceNumberSet()
 {
     $action = new StatusAction();
     $action->execute($getStatus = new GetHumanStatus(array('refund_invoice_number' => 'aNum')));
     $this->assertTrue($getStatus->isRefunded());
 }
Пример #27
0
 /**
  * Offline Payment done
  */
 public function doneOfflineAction(Request $request)
 {
     $token = $this->get('payum.security.http_request_verifier')->verify($request);
     $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();
     $payment = $this->get('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));
     $orderManager = $this->get('hecommerce.order.manager');
     $order = $orderManager->loadOrderForConnectedUser();
     $paymentMethod = $this->get('hecommerce.paymentmethod.manager')->loadByName('offline');
     //$payment = $status->getFirstModel();
     if ($status->getValue() == 'captured') {
         //$order->setPaymentDate(new \DateTime());
         $order->setPaymentMethod($paymentMethod);
         $order->setPaymentDetails($payment);
         $orderManager->save($order);
         try {
             $confirmationEmailManager = $this->get('hecommerce.confirmationemail.manager');
             $confirmationEmail = $confirmationEmailManager->create();
             $confirmationEmail->setOrder($order);
             $confirmationEmail->setSendAt();
             $confirmationEmailManager->save($confirmationEmail);
             throw new Exception('Some Error Message');
         } catch (\Exception $e) {
             //send an email to the admin
             //var_dump($e->getMessage());
         }
         return $this->render('HeadooEcommerceBundle:Store:confirmation.html.twig');
     } else {
         return $this->render('HeadooEcommerceBundle:Store:fail.html.twig');
     }
 }
Пример #28
0
<?php

/**
 * @author      Peter Fox <*****@*****.**>
 * @copyright   Peter Fox 2014
 *
 * @package     payum-bitpay
 */
require_once __DIR__ . '/config.php';
use Payum\Core\Request\Capture;
use Payum\Core\Request\GetHumanStatus;
use PayumBitPay\Model\Transaction;
// Create the Transaction and configure the invoice request
$model = new Transaction();
$model->createRequest(0.0001, 'BTC')->setItemCode('TEST-ITEM-001')->setItemDesc('This is a test item using Payum BitPay')->setOrderID('TEST-ORDER-001');
// Request the invoice and check the current status
$payment = $registry->getPayment('bitpay');
$payment->execute(new Capture($model));
$payment->execute($status = new GetHumanStatus($model));
// If the status is new then it was created, BitPay will only make a request as complete
// when the invoice is paid and the blockchain has confirmed the payment which
// you would typically handle with HTTPS notifications
if ($status->isNew()) {
    echo "You can access your invoice at {$model->getResponse()->getUrl()}\n";
} else {
    if ($status->isFailed()) {
        echo "An error occured\n";
    } else {
        echo "Something went wrong but we don`t know the exact status\n";
    }
}
Пример #29
0
 /**
  * @test
  */
 public function shouldMarkUnknownIfStatusIsUnknown()
 {
     $action = new StatusAction();
     $action->execute($status = new GetHumanStatus(['http_status_code' => 200, 'transaction' => ['response_code' => 20000, 'status' => 'somestatus']]));
     $this->assertTrue($status->isUnknown());
 }
Пример #30
0
<?php

require '../vendor/autoload.php';
require 'config.php';
use Payum\Core\Request\GetHumanStatus;
$token = $requestVerifier->verify($_REQUEST);
$payment = $payum->getPayment($token->getPaymentName());
// you can invalidate the token. The url could not be requested any more.
// $requestVerifier->invalidate($token);
// Once you have token you can get the model from the storage directly.
//$identity = $token->getDetails();
//$order = $payum->getStorage($identity->getClass())->find($identity);
// or Payum can fetch the model for you while executing a request (Preferred).
$payment->execute($status = new GetHumanStatus($token));
$order = $status->getFirstModel();
header('Content-Type: application/json');
print_r(array('status' => $status->getValue(), 'order' => array('total_amount' => $order->getTotalAmount(), 'currency_code' => $order->getCurrencyCode(), 'details' => $order->getDetails())));