public function actionAddcredentials()
 {
     $request = \Yii::$app->Request;
     $msg = '';
     if (!empty($request->post('private_key')) && !empty($request->post('public_key'))) {
         if (Stripe::findOne(1)) {
             $setting = Stripe::findOne(1);
             $setting->public_key = $request->post('public_key');
             $setting->private_key = $request->post('private_key');
             $setting->amount_monthly = $request->post('monthly_amount');
             $setting->amount_one_time = $request->post('one_time_amount');
         } else {
             $setting = new Stripe();
             $setting->public_key = $request->post('public_key');
             $setting->private_key = $request->post('private_key');
             $setting->amount_monthly = $request->post('monthly_amount');
             $setting->amount_one_time = $request->post('one_time_amount');
         }
         if ($setting->save()) {
             $msg = "Settings Saved Successfuly";
         } else {
             $msg = "Error Please Try Again";
         }
     } else {
         $msg = "Keys are empty";
     }
     return $this->render('addStripe', ['msg' => $msg]);
 }
示例#2
0
 public function init()
 {
     parent::init();
     try {
         $tableSchema = Yii::$app->db->schema->getTableSchema('insighter_stripe');
         if ($tableSchema != null) {
             $stripe_setting = Stripe::findOne(1);
             if ($stripe_setting) {
                 $api_key = $stripe_setting->private_key;
                 \Stripe\Stripe::setApiKey($api_key);
             }
         }
     } catch (Exception $e) {
     }
 }