mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-07-15 11:07:53 -04:00
100 lines
2.7 KiB
PHP
100 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace Modules\Subscription\Repositories;
|
|
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Modules\Subscription\Entities\SubscriptionPlan;
|
|
use Modules\Subscription\Entities\SubscriptionPlanPrice;
|
|
use Modules\Subscription\Services\StripePaymentService;
|
|
use Modules\Subscription\Services\PaypalPaymentService;
|
|
|
|
class SubscriptionPlanPricesRepository
|
|
{
|
|
private $stripePayment;
|
|
private $paypalPayment;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->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;
|
|
}
|
|
}
|