stripePayment = new StripePaymentService(); $this->paypalPayment = new PaypalPaymentService(); } public function create($plan, $request) { $data = $request->except('_token'); if(in_array("paypal", $data['payment_method'])){ $paypalResponse = $this->paypalPayment->createProductPrice($plan,$data); $data['paypal_price_id'] = $paypalResponse->id; } if(in_array("stripe", $data['payment_method'])){ $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) { if(in_array("paypal", $data['payment_method'])){ $paypalResponse = $this->paypalPayment->updateProductPrice($price,$data); $data['paypal_price_id'] = $paypalResponse->id; } if(in_array("stripe", $data['payment_method'])){ $stripeResponse = $this->stripePayment->updateProductPrice($price,$data); $data['stripe_price_id'] = $stripeResponse['id']; } $data['subscription_plan_id'] = $price->subscription_plan_id; if(in_array("prepaid", $data['payment_method'])){ $price->update($data); } else { $price->delete(); $planPrice = new SubscriptionPlanPrice(); $planPrice->fill($data); $planPrice->save(); } return true; } return false; } public function delete($id) { $price = SubscriptionPlanPrice::find($id); if ($price) { if($price->paypal_price_id != null){ $this->stripePayment->archivePrice($price->stripe_price_id); } $price->delete(); return true; } return false; } }