File size: 1,348 Bytes
5f32fbd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | <?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
// use App\Models\Subscriptions;
use Stripe\Exception\ApiErrorException;
class CancelAwaitingPaymentSubscriptions implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
protected $subscription;
protected $stripe;
/**
* Create a new job instance.
*/
public function __construct($stripe, $subscription)
{
$this->subscription = $subscription;
$this->stripe = $stripe;
}
/**
* Execute the job.
*/
public function handle(): void
{
try {
$subscriptionObj = $this->stripe->subscriptions->retrieve($this->subscription->stripe_id);
if ($subscriptionObj !== null) {
$subscriptionObj->delete();
}
$this->subscription->update(['stripe_status' => 'cancelled']);
} catch (ApiErrorException $ex) {
$this->subscription->update(['stripe_status' => 'cancelled']);
Log::error("CancelAwaitingPaymentSubscriptions Job\n" . $ex->getMessage());
}
}
}
|