stripePayment = new StripePaymentService(); $this->paypalPayment = new PaypalPaymentService(); } public function create($plan, $request) { $data = $request->except('_token'); $paypalResponse = $this->paypalPayment->createProductPrice($plan,$data); $data['paypal_price_id'] = $paypalResponse->id; $stripeResponse = $this->stripePayment->createProductPrice($plan->stripe_product_id,$data); $data['stripe_price_id'] = $stripeResponse['id']; $planPrice = new SubscriptionPlanPrice(); $planPrice->fill($data); $planPrice->save(); return true; } public function update($request) { $data = $request->except('_token','subscription_plan_id','created_at','updated_at'); $price = SubscriptionPlanPrice::find($data['id']); if ($price) { $paypalResponse = $this->paypalPayment->updateProductPrice($price,$data); $data['paypal_price_id'] = $paypalResponse->id; $stripeResponse = $this->stripePayment->updateProductPrice($price,$data); $data['stripe_price_id'] = $stripeResponse['id']; $data['subscription_plan_id'] = $price->subscription_plan_id; //soft delete $price->delete(); $planPrice = new SubscriptionPlanPrice(); $planPrice->fill($data); $planPrice->save(); return true; } return false; } public function delete($id) { $price = SubscriptionPlanPrice::find($id); if ($price) { $this->stripePayment->archivePrice($price->stripe_price_id); $price->delete(); return true; } return false; } }