/**
  * Tests log with false usage.
  */
 public function testDoNotLog()
 {
     $logger = $this->getMockBuilder('Psr\\Log\\LoggerInterface')->disableOriginalConstructor()->getMock();
     $logger->expects($this->never())->method('log');
     $paymentLogger = new PaymentLogger($logger, false);
     $paymentLogger->log('error', 'message', 'bundle');
 }
 /**
  * Process Paypal IPN notification.
  *
  * This controller handles the IPN notification.
  * The notification is sent using POST method. However,
  * we expect our internal order_id to be passed as a
  * query parameter 'order_id'. The resulting URL for
  * IPN callback notification will have the following form:
  *
  * http://my-domain.com/payment/paypal_web_checkout/process?order_id=1001
  *
  * No matter what happens here, this controller will
  * always return a 200 status HTTP response, otherwise
  * Paypal notification engine will keep on sending the
  * message.
  *
  * @param Request $request Request element
  *
  * @return Response
  */
 public function processAction(Request $request)
 {
     $orderId = $request->query->get('order_id');
     try {
         $this->paypalWebCheckoutManager->processPaypalIPNMessage($orderId, $request->request->all());
         $this->paymentLogger->log('info', 'Paypal payment success. Order number #' . $orderId, 'paypal-web-checkout');
     } catch (ParameterNotReceivedException $exception) {
         $this->paymentLogger->log('error', 'Parameter ' . $exception->getMessage() . ' not received. Order number #' . $orderId, 'paypal-web-checkout');
     } catch (PaymentException $exception) {
         $this->paymentLogger->log('error', 'Paypal payment error "' . $exception->getMessage() . '". Order number #' . $orderId, 'paypal-web-checkout');
     }
     return new Response('OK', 200);
 }
Exemplo n.º 3
0
 /**
  * Post url update the order status
  *
  * @param SafetypayMethod $paymentMethod
  * @param Array           $postData
  */
 public function confirmPayment(SafetypayMethod $paymentMethod, $postData)
 {
     $this->paymentLogger->setPaymentBundle($paymentMethod->getPaymentName());
     $jsonData = json_encode($postData);
     $this->paymentLogger->log('Response: ' . $jsonData);
     $paymentMethod->setReference($postData['MerchantReferenceNo']);
     $paymentMethod->setRequestDateTime($postData['RequestDateTime']);
     $paymentMethod->setSignature($postData['Signature']);
     $paymentBridge = $this->paymentBridge;
     $signature = $this->getSignature($postData, 'RequestDateTime, MerchantReferenceNo', true);
     if ($postData['ApiKey'] !== '' || $postData['Signature'] !== '') {
         if ($this->key == $postData['ApiKey']) {
             if ($postData['Signature'] == $signature) {
                 $this->eventDispatcher->notifyPaymentOrderLoad($paymentBridge, $paymentMethod);
                 $this->eventDispatcher->notifyPaymentOrderSuccess($paymentBridge, $paymentMethod);
             }
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Builds form given success and fail urls
  *
  * @param  String                                                     $successRoute
  * @param  String                                                     $failRoute
  * @param  Integer                                                    $safetyPayTransaction
  * @param  SafetypayMethod                                            $paymentMethod
  * @throws \PaymentSuite\PaymentCoreBundle\Exception\PaymentException
  * @return FormBuilder
  */
 public function buildForm($successRoute, $failRoute, $safetyPayTransaction, SafetypayMethod $paymentMethod)
 {
     $formBuilder = $this->formFactory->createNamedBuilder(null);
     $elements = array('Apikey' => $this->key, 'RequestDateTime' => $this->safetyPayManager->getRequestDateTime(), 'CurrencyCode' => $this->paymentBridge->getCurrency(), 'Amount' => number_format($this->paymentBridge->getAmount() / 100, 2, '.', ''), 'MerchantReferenceNo' => $safetyPayTransaction, 'Language' => 'ES', 'TrackingCode' => '', 'ExpirationTime' => $this->expiration, 'FilterBy' => '', 'TransactionOkURL' => $successRoute, 'TransactionErrorURL' => $failRoute, 'ResponseFormat' => $this->safetyPayManager->getresponseFormat());
     $this->paymentLogger->setPaymentBundle($paymentMethod->getPaymentName());
     $jsonData = json_encode($elements);
     $this->paymentLogger->log('Request: ' . $jsonData);
     $elements['signature'] = $this->safetyPayManager->getSignature($elements, 'CurrencyCode, Amount, MerchantReferenceNo, Language,
         TrackingCode, ExpirationTime, TransactionOkURL,
         TransactionErrorURL');
     $paymentMethod->setRequestDateTime($elements['RequestDateTime']);
     $paymentMethod->setSignature($elements['signature']);
     $urlToken = $this->safetyPayManager->getUrlToken($elements, false);
     //Token no valid
     if (strpos($urlToken, 'Error') > 0) {
         throw new PaymentException();
     }
     $urlTokenExploded = explode('?', $urlToken);
     $urlTokenHost = $urlTokenExploded[0];
     $urlTokenParam = $urlTokenExploded[1];
     $urlTokenParamExploded = explode('=', $urlTokenParam);
     $formBuilder->setAction($urlTokenHost)->setMethod('POST')->add('TokenID', 'hidden', array('data' => $urlTokenParamExploded[1]));
     return $formBuilder;
 }
Exemplo n.º 5
0
 /**
  * Tests log with false usage
  */
 public function testDoNotLog()
 {
     $this->logger->expects($this->never())->method('log')->will($this->returnValue(null));
     $this->paymentLogger->setActive(false);
     $this->paymentLogger->log('This should not be logged');
 }
Exemplo n.º 6
0
 /**
  * Process Payu Request
  *
  * @param PayuRequest $request       Payu Request
  * @param string      $host          Payu host
  * @param string      $responseClass Payu Response Class
  *
  * @return string Raw Payu Response
  */
 protected function processRequest(PayuRequest $request, $host, $responseClass)
 {
     $jsonData = $this->serializer->serialize($request, 'json');
     $this->paymentLogger->log('Request: ' . $jsonData);
     $ch = curl_init($host);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_TIMEOUT, 30);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json; charset=utf-8", "Accept: application/json", "Content-Length: " . strlen($jsonData)));
     curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
     $jsonResponse = curl_exec($ch);
     $this->paymentLogger->log('Response: ' . $jsonResponse);
     $response = $this->serializer->deserialize($jsonResponse, $responseClass, 'json');
     return $response;
 }