where('order_id', $order->id)->first(); if ($existing !== null) { return $existing; } $start = now(); return Subscription::create(array_merge( Subscription::snapshotFrom($order->plan, $term), [ 'customer_id' => $order->customer_id, 'order_id' => $order->id, 'started_at' => $start, 'current_period_start' => $start, 'current_period_end' => $term === Subscription::TERM_YEARLY ? $start->copy()->addYear() : $start->copy()->addMonth(), 'status' => 'active', ], )); } }