/** * Make a Payment to Subscribe * @param integer $id Tempuser ID */ public function actionPayment($id) { // $model = Tempuser::findOne($id); if (Yii::$app->request->post()) { //cus_7iDI8bUtU39kbL, sub_7iDICaGE4xV7Tp \Stripe\Stripe::setApiKey(Yii::$app->find->setting('stripe_api_key')); try { $customer = \Stripe\Customer::create(array('email' => $_POST['stripeEmail'], 'source' => $_POST['stripeToken'], 'plan' => Yii::$app->find->setting('stripe_plan'))); $customer = $customer->jsonSerialize(); $user_id = $model->user_id == null ? $this->createParent($model) : $model->user_id; $payment = new \app\models\Payment(); $payment->user_id = $user_id; $payment->subcription_id = $customer['subscriptions']['data'][0]['id']; $payment->customer_id = $customer['id']; $payment->ip_address = Yii::$app->request->userIP; $payment->amount = $customer['subscriptions']['data'][0]['plan']['amount']; $payment->status = 1; $payment->date = date('Y-m-d H:i', $customer['created']); $payment->save(); Yii::$app->session->setFlash('success', 'Thank You! Your subscription is succeeded. Please sign in to continue.'); return $this->redirect(['user/login']); } catch (Exception $e) { var_dump($e); Yii::$app->session->setFlash('danger', 'Your payment was not received! Please try again. '); } } //\Stripe\Stripe::setApiKey(Yii::$app->params['stripeApiKey']); //$customer = \Stripe\Customer::retrieve("cus_7iDI8bUtU39kbL"); //$customer = $customer->jsonSerialize(); //VarDumper::dump($customer, 1000, true); //$subscription = $customer->subscriptions->retrieve("sub_7iDICaGE4xV7Tp"); //VarDumper::dump($subscription->jsonSerialize(), 1000, true);//$customer->subscriptions->all() return $this->render('payment', ['model' => $model]); }
public function emailExist($attribute, $params) { if (User::find()->where(['identity' => $this->email])->count() > 0 || Tempuser::find()->where(['email' => $this->email])->count() > 0) { $this->addError($attribute, 'Email Exist'); } }