Ejemplo n.º 1
0
 public function actionVpossend()
 {
     if (isset($_POST["Subtotal"]) && isset($_POST["billing"]) && isset($_POST["delivery"])) {
         $plugin = new PlugInClientSend();
         /*Datos Establecimiento*/
         // $filePubKC = Yii::getAlias('@app')."/PUBLICA_CIFRADO_ESTABLECIMIENTO.pem";
         // $filePriKC = Yii::getAlias('@app')."/PRIVADA_CIFRADO_ESTABLECIMIENTO.pem";
         // $filePubKF = Yii::getAlias('@app')."/PUBLICA_FIRMA_ESTABLECIMIENTO.pem";
         $id = Yii::$app->user->identity->id;
         CarShop::deleteAll("user_id = {$id}");
         foreach (Yii::$app->cart->positions as $position) {
             $carshop = new CarShop();
             $carshop->user_id = Yii::$app->user->identity->id;
             $carshop->product_id = $position->product_id;
             $carshop->quantity = $position->quantity;
             $carshop->sap_id = $position->id;
             try {
                 $carshop->save();
             } catch (Exception $e) {
             }
         }
         $filePriKF = Yii::getAlias('@app') . "/PRIVADA_FIRMA_ESTABLECIMIENTO.pem";
         $filePubCI = Yii::getAlias('@app') . "/PUBLICA_CIFRADO_INTERDIN.pem";
         $vector = "JbEFFDiOkRc=";
         $AdquirerID = "1790241483001";
         $MerchantID = "1790241483001";
         $LocalID = "GN01";
         $moneda = "840";
         $URL_Tecnico = Url::to("@web/shop/vpossend", true);
         $ambiente = "pruebas";
         $number = rand(1111111111, 9999999999);
         $random_key = Yii::$app->user->identity->id . $number;
         $sell = new Sell();
         $sell->user_id = Yii::$app->user->identity->id;
         $sell->status = "INCOMPLETE";
         $sell->creation_date = date("Y-m-d H:i:s");
         $sell->transactionid = $random_key;
         $sell->delivery_id = $_POST["delivery"];
         $sell->billing_id = $_POST["billing"];
         $sell->save();
         $e = $plugin->setLocalID($LocalID);
         if ($e != "") {
             echo "Error: {$e}";
         }
         $e = $plugin->setTransacctionID($random_key);
         if ($e != "") {
             echo "Error: {$e}";
         }
         $e = $plugin->setTransacctionValue($_POST["Subtotal"] * 100);
         if ($e != "") {
             echo "Error: {$e}";
         }
         $e = $plugin->setTaxValue1($_POST["impuesto1"] * 100);
         if ($e != "") {
             echo "Error: {$e}";
         }
         $e = $plugin->setTaxValue2($_POST["impuesto2"] * 100);
         if ($e != "") {
             echo "Error: {$e}";
         }
         $e = $plugin->setTipValue($_POST["propina"] * 100);
         if ($e != "") {
             echo "Error: {$e}";
         }
         $e = $plugin->setCurrencyID($moneda);
         if ($e != "") {
             echo "Error: {$e}";
         }
         $e = $plugin->setReferencia1($sell->primaryKey);
         if ($e != "") {
             echo "Error: {$e}";
         }
         $e = $plugin->setReferencia2($sell->primaryKey);
         if ($e != "") {
             echo "Error: {$e}";
         }
         $e = $plugin->setReferencia3($_POST["txtReferencia3"]);
         if ($e != "") {
             echo "Error: {$e}";
         }
         $e = $plugin->setReferencia4($_POST["txtReferencia4"]);
         if ($e != "") {
             echo "Error: {$e}";
         }
         $e = $plugin->setReferencia5($_POST["txtReferencia5"]);
         if ($e != "") {
             echo "Error: {$e}";
         }
         $e = $plugin->setIV($vector);
         if ($e != "") {
             echo "Error: {$e}";
         }
         try {
             $plugin->setSignPrivateKey("file://" . $filePriKF);
             $plugin->setCipherPublicKey("file://" . $filePubCI);
             $xmlGenerateKeyI = $plugin->CreateXMLGENERATEKEY();
             $plugin->XMLProcess($URL_Tecnico);
             $xmlRequest = $plugin->getXMLREQUEST();
             $xmlDigitalSign = $plugin->getXMLDIGITALSIGN();
             return $this->render('confirm', ['xmlRequest' => $xmlRequest, 'xmlDigitalSign' => $xmlDigitalSign, 'xmlGenerateKeyI' => $xmlGenerateKeyI, 'transactionid' => $plugin->TransacctionID]);
         } catch (Exception $e) {
             echo "Error: {$e}";
         }
     } else {
         return $this->redirect(['viewcart']);
     }
 }
Ejemplo n.º 2
0
 /**
  * Creates a new Sell model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Sell();
     $brand_array = $this->getAllBrand();
     $model_array = $this->getAllModel($model->getAttribute('brand'));
     if ($model->load(Yii::$app->request->post())) {
         if ($model->beforeSave(true) && $model->save()) {
             $model->addCustomer();
             $model->setStatus();
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'brand_array' => $brand_array, 'model_array' => $model_array]);
     }
 }