public function actionSubscription() { $request = \Yii::$app->request; $Stripe = \Yii::$app->getModule('stripe'); if (\Yii::$app->hasModule('stripe')) { $msg = "Error In Coennecting to stripe! Please try again later"; if (!empty($request->post('stripeToken'))) { $token = $request->post('stripeToken'); try { $charge = \Stripe\Charge::create(array("amount" => 1000, "currency" => "usd", "source" => $token, "description" => "Example charge")); } catch (\Stripe\Error\Card $e) { } if (!empty($charge)) { if ($charge->paid == true) { $Subscription = new Subscription(); $Subscription->appointment_id = \Yii::$app->session['apid']; $Subscription->amount_paid = $charge->amount; $Subscription->currency = $charge->currency; $Subscription->user_id = \Yii::$app->user->id; $Subscription->transaction_id = $charge->id; $Subscription->save(); unset(\Yii::$app->session['apid']); $msg = "<h1>You Subscribed Succesfuly Thank You</h1>"; } else { $msg = "<h1>Error Please try again</h1>"; } } else { $msg = "<h1>Please Fill Appoinment Form</h1>"; } } } else { $msg = "<h1>Stripe is not configured correctly,Please contact administrator</h1>"; } return $this->render("result", array('msg' => $msg)); }
public function actionMybilling() { $user_id = \Yii::$app->user->getId(); $subscription = Subscription::find()->where(['=', 'user_id', $user_id])->all(); return $this->render("userStripeAccount", ['subscription' => $subscription]); }
public function actionSubscription() { $request = \Yii::$app->request; $Stripe = \Yii::$app->getModule('stripe'); if (\Yii::$app->hasModule('stripe')) { if (\Stripe\Plan::retrieve("gold")) { } else { \Stripe\Plan::create(array("amount" => $subscription_amount, "interval" => "month", "name" => "Gold Plan", "currency" => "usd", "id" => "gold")); } $msg = "Error In Coennecting to stripe! Please try again later"; if (!empty($request->post('stripeToken'))) { $token = $request->post('stripeToken'); $membership = $request->post('membership'); if (!empty($membership) && $membership == 'on') { try { $customer = \Stripe\Customer::create(array("description" => "Customer for test@example.com", "source" => $token)); $customer = \Stripe\Customer::retrieve($customer->id); $customer_res = $customer->subscriptions->create(array("plan" => "gold")); } catch (\Stripe\Error\Card $e) { } } else { try { $charge = \Stripe\Charge::create(array("amount" => $subscription_amount, "currency" => "usd", "source" => $token, "description" => "Example charge")); } catch (\Stripe\Error\Card $e) { } } if (!empty($charge)) { if ($charge->paid == true) { $Subscription = new Subscription(); $Subscription->appointment_id = \Yii::$app->session['apid']; $Subscription->amount_paid = $charge->amount; $Subscription->currency = $charge->currency; $Subscription->user_id = \Yii::$app->user->id; $Subscription->membership = 0; $Subscription->transaction_id = $charge->id; $Subscription->payment_type = $charge->source->brand; $Subscription->save(); unset(\Yii::$app->session['apid']); $msg = "<h1>You Subscribed Successfully Thank You</h1>"; } else { $msg = "<h1>Error Please try again</h1>"; } } else { if (!empty($customer)) { if ($customer_res->status == "active" && (!empty($membership) && $membership == 'on')) { $Subscription = new Subscription(); $Subscription->appointment_id = \Yii::$app->session['apid']; $Subscription->amount_paid = $customer_res->amount; $Subscription->currency = $customer_res->currency; $Subscription->user_id = \Yii::$app->user->id; $Subscription->membership = 1; $Subscription->transaction_id = $customer_res->id; $Subscription->payment_type = $customer->sources->data[0]->brand; $Subscription->save(); unset(\Yii::$app->session['apid']); $msg = "<h1>You Subscribed Successfully Thank You</h1>"; } else { } } else { $msg = "<h1>Please Fill Appoinment Form</h1>"; } } } } else { $msg = "<h1>Stripe is not configured correctly,Please contact administrator</h1>"; } return $this->render("subscription", array('msg' => $msg)); }
public function getSubscription() { return $this->hasOne(Subscription::className(), ['appointment_id' => 'id']); }