diff --git a/app/Http/Controllers/BillingSubscriptionController.php b/app/Http/Controllers/BillingSubscriptionController.php index 421e2e2768f4..0dff2f31c962 100644 --- a/app/Http/Controllers/BillingSubscriptionController.php +++ b/app/Http/Controllers/BillingSubscriptionController.php @@ -40,6 +40,43 @@ class BillingSubscriptionController extends BaseController $this->billing_subscription_repo = $billing_subscription_repo; } + /** + * Show the list of BillingSubscriptions. + * * + * @return Response + * + * @OA\Get( + * path="/api/v1/billing_subscriptions", + * operationId="getBillingSubscriptions", + * tags={"billing_subscriptions"}, + * summary="Gets a list of billing_subscriptions", + * description="Lists billing_subscriptions.", + * + * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), + * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), + * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), + * @OA\Parameter(ref="#/components/parameters/include"), + * @OA\Response( + * response=200, + * description="A list of billing_subscriptions", + * @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"), + * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), + * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), + * @OA\JsonContent(ref="#/components/schemas/BillingSubscription"), + * ), + * @OA\Response( + * response=422, + * description="Validation error", + * @OA\JsonContent(ref="#/components/schemas/ValidationError"), + * ), + * @OA\Response( + * response="default", + * description="Unexpected Error", + * @OA\JsonContent(ref="#/components/schemas/Error"), + * ), + * ) + */ + public function index(): \Illuminate\Http\Response { $billing_subscriptions = BillingSubscription::query()->company(); diff --git a/app/Http/Controllers/OpenAPI/BillingSubscription.php b/app/Http/Controllers/OpenAPI/BillingSubscription.php new file mode 100644 index 000000000000..bde43b87c618 --- /dev/null +++ b/app/Http/Controllers/OpenAPI/BillingSubscription.php @@ -0,0 +1,31 @@ + 'boolean', + 'plan_map' => 'object', + 'webhook_configuration' => 'object', + 'updated_at' => 'timestamp', + 'created_at' => 'timestamp', + 'deleted_at' => 'timestamp', + ]; + public function company(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(Company::class); diff --git a/app/Transformers/BillingSubscriptionTransformer.php b/app/Transformers/BillingSubscriptionTransformer.php index 4969f4dfa018..8b2f376f9762 100644 --- a/app/Transformers/BillingSubscriptionTransformer.php +++ b/app/Transformers/BillingSubscriptionTransformer.php @@ -29,7 +29,7 @@ class BillingSubscriptionTransformer extends EntityTransformer * @var array */ protected $availableIncludes = [ - 'products', + 'product', ]; public function transform(BillingSubscription $billing_subscription): array @@ -44,24 +44,27 @@ class BillingSubscriptionTransformer extends EntityTransformer 'frequency_id' => (string)$billing_subscription->frequency_id, 'auto_bill' => (string)$billing_subscription->auto_bill, 'promo_code' => (string)$billing_subscription->promo_code, - 'promo_discount' => (string)$billing_subscription->promo_discount, + 'promo_discount' => (float)$billing_subscription->promo_discount, 'is_amount_discount' => (bool)$billing_subscription->is_amount_discount, 'allow_cancellation' => (bool)$billing_subscription->allow_cancellation, - 'per_set_enabled' => (bool)$billing_subscription->per_set_enabled, + 'per_seat_enabled' => (bool)$billing_subscription->per_set_enabled, 'min_seats_limit' => (int)$billing_subscription->min_seats_limit, 'max_seats_limit' => (int)$billing_subscription->max_seats_limit, 'trial_enabled' => (bool)$billing_subscription->trial_enabled, - 'trial_duration' => (string)$billing_subscription->trial_duration, + 'trial_duration' => (int)$billing_subscription->trial_duration, 'allow_query_overrides' => (bool)$billing_subscription->allow_query_overrides, 'allow_plan_changes' => (bool)$billing_subscription->allow_plan_changes, 'plan_map' => (string)$billing_subscription->plan_map, - 'refund_period' => (string)$billing_subscription->refund_period, + 'refund_period' => (int)$billing_subscription->refund_period, 'webhook_configuration' => (string)$billing_subscription->webhook_configuration, 'is_deleted' => (bool)$billing_subscription->is_deleted, + 'created_at' => (int) $credit->created_at, + 'updated_at' => (int) $credit->updated_at, + 'archived_at' => (int) $credit->deleted_at, ]; } - public function includeProducts(BillingSubscription $billing_subscription): \League\Fractal\Resource\Item + public function includeProduct(BillingSubscription $billing_subscription): \League\Fractal\Resource\Item { $transformer = new ProductTransformer($this->serializer); diff --git a/database/migrations/2021_03_08_123729_create_billing_subscriptions_table.php b/database/migrations/2021_03_08_123729_create_billing_subscriptions_table.php index 640a21becc0c..27400a8fa679 100644 --- a/database/migrations/2021_03_08_123729_create_billing_subscriptions_table.php +++ b/database/migrations/2021_03_08_123729_create_billing_subscriptions_table.php @@ -26,7 +26,7 @@ class CreateBillingSubscriptionsTable extends Migration $table->float('promo_discount')->default(0); $table->boolean('is_amount_discount')->default(false); $table->boolean('allow_cancellation')->default(true); - $table->boolean('per_set_enabled')->default(false); + $table->boolean('per_seat_enabled')->default(false); $table->unsignedInteger('min_seats_limit'); $table->unsignedInteger('max_seats_limit'); $table->boolean('trial_enabled')->default(false); diff --git a/routes/api.php b/routes/api.php index a2122998f186..1af077d5fbeb 100644 --- a/routes/api.php +++ b/routes/api.php @@ -173,7 +173,7 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a // Route::post('hooks', 'SubscriptionController@subscribe')->name('hooks.subscribe'); // Route::delete('hooks/{subscription_id}', 'SubscriptionController@unsubscribe')->name('hooks.unsubscribe'); - Route::resource('billing/subscriptions', 'BillingSubscriptionController'); + Route::resource('billing_subscriptions', 'BillingSubscriptionController'); }); Route::match(['get', 'post'], 'payment_webhook/{company_key}/{company_gateway_id}', 'PaymentWebhookController')