1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 23:22:52 +01:00
invoiceninja/app/Transformers/SubscriptionTransformer.php
David Bomba 114b58cdc4
Beganovich 1513 powerboard (#103)
* make container nicer

* assets rebuild

* authorize powerband card (3ds)

* add reference to build file

* update authorize (3ds) view

* assets rebuild

* unify 3ds and non-3ds auth/pay

* assets rebuild

* authorize

* pay

* update vite refs

* pay

* hide authorize button

* intercepting form on authorize

* assets build

* wip

* init powerboard in data ref

* fixes for blank placeholders

* reset the form on failed 3ds

* handling unsuccessful errors

* send email on payment failed

* fixes for 3ds fail on auth

* assets rebuild

* make card_name required

* make card_name required (on auth)

* fixes for blocked pay-now button

* fixes for reload

* fixes for reload

* build

* Fixes for broken powerboard

* make client name required

* skip fields checking if no required fields

* on request, return json response

* check for plain not_authenticated response

* flash message when no action is present

* fixes for exec order on token

* assets build

* check for plain not_authenticated response (pay)

* assets build

* adjustments for minimum payments

* Add text decoration to terms button

* Improvements for subscriptions and new payment flow

---------

Co-authored-by: Benjamin Beganović <k1pstabug@gmail.com>
2024-09-17 10:16:10 +10:00

80 lines
3.5 KiB
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Transformers;
use App\Models\Subscription;
use App\Utils\Traits\MakesHash;
class SubscriptionTransformer extends EntityTransformer
{
use MakesHash;
/**
* @var array
*/
protected array $defaultIncludes = [
];
/**
* @var array
*/
protected array $availableIncludes = [
];
public function transform(Subscription $subscription): array
{
$company = $subscription->company;
return [
'id' => $this->encodePrimaryKey($subscription->id),
'user_id' => $this->encodePrimaryKey($subscription->user_id),
'group_id' => $this->encodePrimaryKey($subscription->group_id),
'product_ids' => (string) $subscription->product_ids,
'name' => (string) $subscription->name,
'recurring_product_ids' => (string) $subscription->recurring_product_ids,
'assigned_user_id' => $this->encodePrimaryKey($subscription->assigned_user_id),
'company_id' => $this->encodePrimaryKey($subscription->company_id),
'price' => (float) $subscription->price,
'promo_price' => (float) $subscription->promo_price,
'frequency_id' => (string) $subscription->frequency_id,
'auto_bill' => (string) $subscription->auto_bill,
'promo_code' => (string) $subscription->promo_code,
'promo_discount' => (float) $subscription->promo_discount,
'is_amount_discount' => (bool) $subscription->is_amount_discount,
'allow_cancellation' => (bool) $subscription->allow_cancellation,
'per_seat_enabled' => (bool) $subscription->per_seat_enabled,
'max_seats_limit' => (int) $subscription->max_seats_limit,
'trial_enabled' => (bool) $subscription->trial_enabled,
'trial_duration' => (int) $subscription->trial_duration,
'allow_query_overrides' => (bool) $subscription->allow_query_overrides,
'allow_plan_changes' => (bool) $subscription->allow_plan_changes,
'refund_period' => (int) $subscription->refund_period,
'webhook_configuration' => $subscription->webhook_configuration ?: [],
'purchase_page' => (string) $company->domain()."/client/subscriptions/{$subscription->hashed_id}/purchase",
//'purchase_page' => (string)route('client.subscription.purchase', $subscription->hashed_id),
'currency_id' => (string) $subscription->currency_id,
'is_deleted' => (bool) $subscription->is_deleted,
'created_at' => (int) $subscription->created_at,
'updated_at' => (int) $subscription->updated_at,
'archived_at' => (int) $subscription->deleted_at,
'plan_map' => '', //@deprecated 03/04/2021
'use_inventory_management' => (bool) $subscription->use_inventory_management,
'optional_recurring_product_ids' => (string)$subscription->optional_recurring_product_ids,
'optional_product_ids' => (string) $subscription->optional_product_ids,
'registration_required' => (bool) $subscription->registration_required,
'steps' => $subscription->steps,
'remaining_cycles' => (int) $subscription->remaining_cycles,
];
}
}