/**
  * Creates a new Transaction model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Transaction();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
    /**
     * Creates a new Transaction model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate()
    {
        $model = new Transaction();
        if ($model->load(Yii::$app->request->post())) {
            $_app = \Yii::$app->params['_app'];
            $user = \common\models\User::findOne(Yii::$app->user->id);
            $_user = ArrayHelper::toArray($user, ['\\common\\models\\User' => ['id', 'username']]);
            $model->username = $_user['username'];
            $model->id_user = Yii::$app->user->id;
            $model->status = 0;
            $url_oneclickmoney = \Yii::$app->params['url_oneclickmoney'];
            $curl = curl_init($url_oneclickmoney);
            $xml = <<<XML
<?xml version='1.0'?>
<xml>
    <action>send</action>
    <app>{$_app}</app>
    <transaction id="{$model->id}" ttl="{$model->ttl}" status="{$model->status}" description="{$model->description}" />
    <user>
        <id>{$model->id_user}</id>
        <name>{$model->username}</name>
    </user>
</xml>
XML;
            curl_setopt($curl, CURLOPT_POST, true);
            curl_setopt($curl, CURLOPT_HTTPHEADER, ["Content-Type: text/xml"]);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
            $result = curl_exec($curl);
            curl_close($curl);
            $xml = simplexml_load_string($result, "SimpleXMLElement", LIBXML_NOCDATA);
            $model->code = $xml->response['code'];
            $model->save();
            return $this->redirect(['index', 'alert' => 'trans_ok']);
        } else {
            if (!$model->load(Yii::$app->request->post())) {
                return $this->render('create', ['model' => $model]);
            }
        }
    }