/** * Confirm webpay payment * * @param WebpayMethod $paymentMethod Payment Method * @param array $postData Post parameters * * @throws \PaymentSuite\PaymentCoreBundle\Exception\PaymentException * @throws \PaymentSuite\WebpayBundle\Exception\WebpayMacCheckException * @throws \PaymentSuite\PaymentCoreBundle\Exception\PaymentOrderNotFoundException * @throws \PaymentSuite\PaymentCoreBundle\Exception\PaymentAmountsNotMatchException * @throws \PaymentSuite\PaymentCoreBundle\Exception\PaymentDuplicatedException * * @return WebpayManager Self object */ public function confirmPayment(WebpayMethod $paymentMethod, array $postData) { $paymentBridge = $this->paymentBridge; /** @var Normal $trans */ $trans = $paymentMethod->getTransaction(); $tbkRespuesta = $trans->getRespuesta(); $tbkOrdenCompra = $trans->getOrdenCompra(); $tbkMonto = $trans->getMonto(); $paymentMethod->setSessionId($trans->getIdSesion()); // Check TBK_ORDEN_COMPRA $this->eventDispatcher->notifyPaymentOrderLoad($paymentBridge, $paymentMethod); if (!$paymentBridge->getOrder() || $paymentBridge->getOrderId() != $tbkOrdenCompra) { throw new PaymentOrderNotFoundException(); } // Check TBK_RESPUESTA if ($tbkRespuesta !== '0') { $this->eventDispatcher->notifyPaymentOrderFail($paymentBridge, $paymentMethod); throw new PaymentException(); } // Check MAC $fileMacName = $this->kccPath . '/log/MAC01Normal' . $trans->getIdSesion() . '.txt'; $fileMac = fopen($fileMacName, 'w'); foreach ($postData as $key => $val) { fwrite($fileMac, "{$key}={$val}&"); } fclose($fileMac); $cmd = $this->kccPath . '/tbk_check_mac.cgi ' . $fileMacName . ' 2>&1'; exec($cmd, $result, $retint); if ($retint != 0 || $result[0] != 'CORRECTO') { $this->eventDispatcher->notifyPaymentOrderFail($paymentBridge, $paymentMethod); throw new WebpayMacCheckException(); } // Check MONTO $fileMontoName = $this->kccPath . '/log/datos' . $trans->getIdSesion() . '.log'; if (!($fileMonto = fopen($fileMontoName, 'r'))) { $this->eventDispatcher->notifyPaymentOrderFail($paymentBridge, $paymentMethod); throw new PaymentAmountsNotMatchException(); } $line = trim(fgets($fileMonto)); fclose($fileMonto); $details = explode(";", $line); if (count($details) != 2) { $this->eventDispatcher->notifyPaymentOrderFail($paymentBridge, $paymentMethod); throw new PaymentAmountsNotMatchException(); } if ($tbkMonto != $details[0] || $tbkOrdenCompra != $details[1]) { $this->eventDispatcher->notifyPaymentOrderFail($paymentBridge, $paymentMethod); throw new PaymentAmountsNotMatchException(); } // Check DUPLICIDAD if ($paymentBridge->isOrderPaid()) { throw new PaymentDuplicatedException(); } $this->eventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $paymentMethod); return $this; }
/** * Payment confirmation * * @param Request $request Request element * * @return Response * * @Method("POST") */ public function confirmationAction(Request $request) { $status = WebpayController::WEBPAY_ACCEPTED; $paymentMethod = new WebpayMethod(); $transaction = new Normal(); $transaction->setAccion($request->request->get('TBK_ACCION'))->setCodigoAutorizacion($request->request->get('TBK_CODIGO_AUTORIZACION'))->setCodigoComercio($request->request->get('TBK_CODIGO_COMERCIO'))->setCodigoComercioEnc($request->request->get('TBK_CODIGO_COMERCIO_ENC'))->setFechaContable($request->request->get('TBK_FECHA_CONTABLE'))->setFechaExpiracion($request->request->get('TBK_FECHA_EXPIRACION'))->setFechaTransaccion($request->request->get('TBK_FECHA_TRANSACCION'))->setFinalNumeroTarjeta($request->request->get('TBK_FINAL_NUMERO_TARJETA'))->setHoraTransaccion($request->request->get('TBK_HORA_TRANSACCION'))->setIdSesion($request->request->get('TBK_ID_SESION'))->setIdTransaccion($request->request->get('TBK_ID_TRANSACCION'))->setMac($request->request->get('TBK_MAC'))->setMonto($request->request->get('TBK_MONTO'))->setNumeroCuotas($request->request->get('TBK_NUMERO_CUOTAS'))->setOrdenCompra($request->request->get('TBK_ORDEN_COMPRA'))->setRespuesta($request->request->get('TBK_RESPUESTA'))->setTipoPago($request->request->get('TBK_TIPO_PAGO'))->setVci($request->request->get('TBK_VCI'))->setTipoTransaccion($request->request->get('TBK_TIPO_TRANSACCION')); $paymentMethod->setTransaction($transaction); try { $this->get('webpay.manager')->confirmPayment($paymentMethod, $request->request->all()); } catch (PaymentOrderNotFoundException $e) { $status = WebpayController::WEBPAY_REJECTED; } catch (WebpayMacCheckException $e) { $status = WebpayController::WEBPAY_REJECTED; } catch (PaymentAmountsNotMatchException $e) { $status = WebpayController::WEBPAY_REJECTED; } catch (PaymentException $e) { } return new Response($status); }