/**
  * @Extra\Route(
  *   "/prepare_paypal_via_jms_plugin",
  *   name="acme_other_paypal_via_jms_plugin"
  * )
  *
  * @Extra\Template
  */
 public function prepareAction(Request $request)
 {
     $gatewayName = 'paypal_express_checkout_via_jms_plugin';
     $form = $this->createPurchaseForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $data = $form->getData();
         $paymentInstruction = new PaymentInstruction($data['amount'], $data['currency'], 'paypal_express_checkout');
         $paymentInstruction->setState(PaymentInstruction::STATE_VALID);
         $payment = new Payment($paymentInstruction, $data['amount']);
         $this->getDoctrine()->getManager()->persist($paymentInstruction);
         $this->getDoctrine()->getManager()->persist($payment);
         $this->getDoctrine()->getManager()->flush();
         $captureToken = $this->getTokenFactory()->createCaptureToken($gatewayName, $payment, 'acme_other_purchase_done_paypal_via_jms_plugin');
         $payment->getPaymentInstruction()->getExtendedData()->set('return_url', $captureToken->getTargetUrl());
         $payment->getPaymentInstruction()->getExtendedData()->set('cancel_url', $captureToken->getTargetUrl());
         //the state manipulations  is needed for saving changes in extended data.
         $oldState = $payment->getPaymentInstruction()->getState();
         $payment->getPaymentInstruction()->setState(PaymentInstruction::STATE_INVALID);
         $this->getDoctrine()->getManager()->persist($paymentInstruction);
         $this->getDoctrine()->getManager()->persist($payment);
         $this->getDoctrine()->getManager()->flush();
         $payment->getPaymentInstruction()->setState($oldState);
         $this->getDoctrine()->getManager()->persist($paymentInstruction);
         $this->getDoctrine()->getManager()->flush();
         return $this->redirect($captureToken->getTargetUrl());
     }
     return array('form' => $form->createView());
 }
 /**
  * @param Request $request
  * @param PaymentInstruction $instruction
  * @return Response
  * @throws \EgoPayException
  */
 public function callbackAction(Request $request, PaymentInstruction $instruction)
 {
     $client = $this->get('payment.egopay.client');
     $aResponse = $client->createSciCallback()->getResponse($request->request->all());
     if (null === ($transaction = $instruction->getPendingTransaction())) {
         return new Response('No pending transaction found for the payment instruction', 500);
     }
     $em = $this->getDoctrine()->getManager();
     $transaction->getExtendedData()->set('sId', $aResponse['sId']);
     $transaction->getExtendedData()->set('sDate', isset($aResponse['sDate']) ? $aResponse['sDate'] : '');
     $transaction->getExtendedData()->set('fAmount', $aResponse['fAmount']);
     $transaction->getExtendedData()->set('sCurrency', $aResponse['sCurrency']);
     $transaction->getExtendedData()->set('fFee', isset($aResponse['fFee']) ? $aResponse['fFee'] : '');
     $transaction->getExtendedData()->set('sType', $aResponse['sType']);
     $transaction->getExtendedData()->set('iTypeId', $aResponse['iTypeId']);
     $transaction->getExtendedData()->set('sEmail', isset($aResponse['sEmail']) ? $aResponse['sEmail'] : '');
     $transaction->getExtendedData()->set('sDetails', isset($aResponse['sDetails']) ? $aResponse['sDetails'] : '');
     $transaction->getExtendedData()->set('sStatus', $aResponse['sStatus']);
     $transaction->getExtendedData()->set('cf_1', isset($aResponse['cf_1']) ? $aResponse['cf_1'] : '');
     $transaction->getExtendedData()->set('cf_2', isset($aResponse['cf_2']) ? $aResponse['cf_2'] : '');
     $transaction->getExtendedData()->set('cf_3', isset($aResponse['cf_3']) ? $aResponse['cf_3'] : '');
     $transaction->getExtendedData()->set('cf_4', isset($aResponse['cf_4']) ? $aResponse['cf_4'] : '');
     $transaction->getExtendedData()->set('cf_5', isset($aResponse['cf_5']) ? $aResponse['cf_5'] : '');
     $transaction->getExtendedData()->set('cf_6', isset($aResponse['cf_6']) ? $aResponse['cf_6'] : '');
     $transaction->getExtendedData()->set('cf_7', isset($aResponse['cf_7']) ? $aResponse['cf_7'] : '');
     $transaction->getExtendedData()->set('cf_8', isset($aResponse['cf_8']) ? $aResponse['cf_8'] : '');
     $em->persist($transaction);
     $payment = $transaction->getPayment();
     $result = $this->get('payment.plugin_controller')->approveAndDeposit($payment->getId(), (double) $aResponse['fAmount']);
     if (is_object($ex = $result->getPluginException())) {
         throw $ex;
     }
     $em->flush();
     return new Response('OK');
 }
 /**
  * @param \Symfony\Component\HttpFoundation\Request         $request     The request
  * @param \JMS\Payment\CoreBundle\Entity\PaymentInstruction $instruction The payment instruction
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function urlcAction(Request $request, PaymentInstruction $instruction)
 {
     $this->get('event_dispatcher')->dispatch(DotpayEvents::PAYMENT_DOTPAY_CONFIRMATION_RECEIVED, new DotpayConfirmationReceivedEvent($instruction, $request->request));
     $client = $this->get('payment.dotpay.client.token');
     $logger = $this->get('logger');
     // Check the PIN
     $control = md5(sprintf("%s:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s", $client->getPin(), $client->getId(), $request->request->get('control'), $request->request->get('t_id'), $request->request->get('amount'), $request->request->get('email'), $request->request->get('service'), $request->request->get('code'), $request->request->get('username'), $request->request->get('password'), $request->request->get('t_status')));
     if ($control !== $request->request->get('md5')) {
         $logger->err('[Dotpay - URLC] pin verification failed');
         return new Response('FAIL', 500);
     }
     if (null === ($transaction = $instruction->getPendingTransaction())) {
         $logger->err('[Dotpay - URLC] no pending transaction found for the payment instruction');
         return new Response('FAIL', 500);
     }
     $amountParts = explode(' ', $request->get('orginal_amount'));
     // Yes, the right parameter is 'orginal_amount'
     $amount = (double) $amountParts[0];
     // there is a typo error in the DotPay API
     $transaction->getExtendedData()->set('t_status', $request->get('t_status'));
     $transaction->getExtendedData()->set('t_id', $request->get('t_id'));
     $transaction->getExtendedData()->set('amount', $amount);
     try {
         $this->get('payment.plugin_controller')->approveAndDeposit($transaction->getPayment()->getId(), $amount);
     } catch (\Exception $e) {
         $logger->err(sprintf('[Dotpay - URLC] %s', $e->getMessage()));
         return new Response('FAIL', 500);
     }
     $this->getDoctrine()->getManager()->flush();
     $logger->info(sprintf('[Dotpay - URLC] Payment instruction %s successfully updated', $instruction->getId()));
     return new Response('OK');
 }
 /**
  * Zatwierdzanie płatności
  * @param Request $request
  * @param PaymentInstruction $instruction
  * @return Response
  * @throws \EgoPayException
  */
 public function callbackAction(Request $request, PaymentInstruction $instruction)
 {
     $client = $this->get('payment.perfectmoney.client');
     $response = $client->getPaymentResponse($request);
     if (null === ($transaction = $instruction->getPendingTransaction())) {
         throw new \RuntimeException('No pending transaction found for the payment instruction');
     }
     $em = $this->getDoctrine()->getManager();
     $extendedData = $transaction->getExtendedData();
     $extendedData->set('Time', $response['Time']);
     $extendedData->set('Type', $response['Type']);
     $extendedData->set('Batch', $response['Batch']);
     $extendedData->set('Currency', $response['Currency']);
     $extendedData->set('Amount', $response['Amount']);
     $extendedData->set('Fee', $response['Fee']);
     $extendedData->set('Payer_Account', $response['Payer_Account']);
     $extendedData->set('Payee_Account', $response['Payee_Account']);
     $extendedData->set('Payment_ID', $response['Payment_ID']);
     $extendedData->set('Memo', $response['Memo']);
     $em->persist($transaction);
     $payment = $transaction->getPayment();
     $result = $this->get('payment.plugin_controller')->approveAndDeposit($payment->getId(), (double) $response['Amount']);
     if (is_object($ex = $result->getPluginException())) {
         throw $ex;
     }
     $em->flush();
     return new Response('OK');
 }
예제 #5
0
 public function __construct(PaymentInstructionInterface $paymentInstruction, $amount)
 {
     $this->attentionRequired = false;
     $this->creditedAmount = 0.0;
     $this->creditingAmount = 0.0;
     $this->paymentInstruction = $paymentInstruction;
     $this->transactions = new ArrayCollection();
     $this->reversingAmount = 0.0;
     $this->state = self::STATE_NEW;
     $this->targetAmount = $amount;
     $this->createdAt = new \DateTime();
     $this->paymentInstruction->addCredit($this);
 }
 /**
  * @param Request $request
  * @param PaymentInstruction $instruction
  * @return Response
  * @throws \Exception
  */
 public function callbackAction(Request $request, PaymentInstruction $instruction)
 {
     if (null === ($transaction = $instruction->getPendingTransaction())) {
         return new Response('No pending transaction found for the payment instruction', 500);
     }
     $doctrine = $this->getDoctrine();
     $client = $this->get('payment.okpay.client');
     $response = $client->getCallbackResponse($request);
     $post = $request->request;
     if ($response->getResult() != CallbackResponse::RESULT_VERIFIED) {
         throw new \Exception("Transaction is not verified. Result: " . $response->getResult(), 1);
     }
     if ($response->isValid()) {
         if ($post->get("ok_txn_status") != CallbackResponse::STATUS_COMPLETED) {
             throw new \Exception("Invalid transaction status. Status: " . $post->get("ok_txn_status"), 2);
         }
         if ($post->get("ok_receiver_wallet") != $client->getWalletId()) {
             throw new \Exception("Invalid wallet id.", 3);
         }
         $exist = $doctrine->getRepository('JMSPaymentCoreBundle:FinancialTransaction')->findOneByReferenceNumber(OkPayClient::REF_NUM_PREFIX . $post->get("ok_txn_id"));
         if (!is_null($exist)) {
             throw new \Exception("Transaction " . $post->get("ok_txn_id") . " has been previously processed", 4);
         }
         $em = $this->getDoctrine()->getManager();
         $transaction->getExtendedData()->set("ok_txn_status", $post->get("ok_txn_status"));
         $transaction->getExtendedData()->set("ok_txn_id", $post->get("ok_txn_id"));
         $transaction->getExtendedData()->set("ok_receiver", $post->get("ok_receiver"));
         $transaction->getExtendedData()->set("ok_receiver_email", $post->get("ok_receiver_email"));
         $transaction->getExtendedData()->set("ok_receiver_id", $post->get("ok_receiver_id"));
         $transaction->getExtendedData()->set("ok_receiver_wallet", $post->get("ok_receiver_wallet"));
         $transaction->getExtendedData()->set("ok_txn_gross", $post->get("ok_txn_gross"));
         $transaction->getExtendedData()->set("ok_txn_currency", $post->get("ok_txn_currency"));
         $em->persist($transaction);
     } else {
         $exceptions = $response->getValidationExceptions();
         throw new $exceptions[0]();
     }
     $payment = $transaction->getPayment();
     $result = $this->get('payment.plugin_controller')->approveAndDeposit($payment->getId(), (double) $post->get("ok_txn_gross"));
     if (is_object($ex = $result->getPluginException())) {
         throw $ex;
     }
     $em->flush();
     return new Response('OK');
 }
 /**
  * Zatwierdzanie płatności
  * @param Request $request
  * @param PaymentInstruction $instruction
  * @return Response
  * @throws \Exception
  */
 public function callbackAction(Request $request, PaymentInstruction $instruction)
 {
     if (null === ($transaction = $instruction->getPendingTransaction())) {
         throw new \RuntimeException('No pending transaction found for the payment instruction');
     }
     $client = $this->get('payment.blockchain.client');
     $response = new CallbackResponse($request);
     $extendedData = $transaction->getExtendedData();
     if ($client->getSecretParameter() !== $response->getSecretParameter()) {
         throw new \Exception("Invalid secret parameter", 1);
     }
     if ($client->getReceivingAddress() !== $response->getDestinationAddress()) {
         throw new \Exception("Invalid destination address", 2);
     }
     if ($extendedData->get("generated_input_address") !== $response->getInputAddress()) {
         throw new \Exception("Invalid input address", 3);
     }
     if ((int) $response->getConfirmations() >= 6) {
         $amount = (double) $response->getValue() / 100000000;
         // The value of the payment received in satoshi. Divide by 100000000 to get the value in BTC.
         $em = $this->getDoctrine()->getManager();
         $extendedData->set("value", $amount);
         $extendedData->set("input_address", $response->getInputAddress());
         $extendedData->set("confirmations", $response->getConfirmations());
         $extendedData->set("transaction_hash", $response->getTransactionHash());
         $extendedData->set("input_transaction_hash", $response->getInputTransactionHash());
         $extendedData->set("destination_address", $response->getDestinationAddress());
         $em->persist($transaction);
         $payment = $transaction->getPayment();
         $result = $this->get('payment.plugin_controller')->approveAndDeposit($payment->getId(), $amount);
         if (is_object($ex = $result->getPluginException())) {
             throw $ex;
         }
         $em->flush();
         return new Response('*ok*');
     } else {
         return new Response('not enough confirmations');
     }
 }
 /**
  * @expectedException \InvalidArgumentException
  * @dataProvider getTestAmountsForIndependentCredit
  */
 public function testCreditOnlyAcceptsValidAmountsForIndependentCredits($amount)
 {
     $controller = $this->getController();
     $instruction = new PaymentInstruction(150.0, 'EUR', 'foo', new ExtendedData());
     $instruction->setState(PaymentInstructionInterface::STATE_VALID);
     $credit = new Credit($instruction, 50);
     $instruction->setDepositedAmount(10.0);
     $instruction->setReversingDepositedAmount(0.01);
     $instruction->setCreditedAmount(0.01);
     $instruction->setCreditingAmount(0.01);
     $this->callCredit($controller, array($credit, $amount));
 }
 public function testChangesToExtendedDataCanBeMadeAfterCreation()
 {
     $instruction = new PaymentInstruction(123, 'EUR', 'foo', $data = new ExtendedData());
     $instruction->getExtendedData()->set('foo', 'bar');
     $instruction->onPreSave();
     $this->assertNotSame($data, $instruction->getExtendedData());
 }