View Source Glific.Partners.Billing (Glific v5.1.6)
We will use this as the main context interface for all billing subscriptions and the stripe interface.
Link to this section Summary
Functions
Standard changeset pattern we use for all data types
Create a billing record in glific, a billing customer in Stripe, given an organization
Create a billing record
Create a monthly subscription. Once the organization has entered a new payment card we create a subscription for it. We'll do updating the card in a separate function
create subscription on the basis of billing period
Create a quarterly subscription.
create subscription on the basis of billing period
Adding credit to customer in Stripe
fetches customer portal url of organization with billing status as active
Delete the billing record
Retrieve a billing record by clauses
Validate entered coupon code and return with coupon details
List of available billing period
A common function for making Stripe API calls with params that are not supported withing Stripity Stripe
Fetch the stripe id's
This is called on a regular schedule to update usage.
Fetch the stripe id's
Record the usage for a specific organization from start_date to end_date both dates inclusive
Stripe subscription created callback via webhooks. We are using this to update the prorate data with monthly billing.
Fetch the stripe tax rates
Update the billing record
Update organization and stripe customer with the current payment method as returned by stripe
Update the stripe customer details record
Update organization subscription plan
Update subscription details. We will also use this method while updating the details form webhook.
Update the usage record for all active subscriptions on a daily and weekly basis
Link to this section Types
@type t() :: %Glific.Partners.Billing{ __meta__: Ecto.Schema.Metadata.t(), billing_period: String.t() | nil, currency: String.t() | nil, deduct_tds: boolean() | false, email: String.t() | nil, id: non_neg_integer() | nil, inserted_at: :utc_datetime | nil, is_active: boolean() | true, is_delinquent: boolean(), name: String.t() | nil, organization: term(), organization_id: term(), stripe_current_period_end: DateTime.t() | nil, stripe_current_period_start: DateTime.t() | nil, stripe_customer_id: String.t() | nil, stripe_last_usage_recorded: DateTime.t() | nil, stripe_payment_method_id: String.t() | nil, stripe_subscription_id: String.t() | nil, stripe_subscription_items: map(), stripe_subscription_status: String.t() | nil, tds_amount: float() | nil, updated_at: :utc_datetime | nil }
Link to this section Functions
@spec changeset(t(), map()) :: Ecto.Changeset.t()
Standard changeset pattern we use for all data types
@spec create(Glific.Partners.Organization.t(), map()) :: {:ok, t()} | {:error, Ecto.Changeset.t() | String.t()}
Create a billing record in glific, a billing customer in Stripe, given an organization
@spec create_billing(map()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}
Create a billing record
@spec create_monthly_subscription(Glific.Partners.Organization.t(), map(), map()) :: {:ok, Stripe.Subscription.t()} | {:pending, map()} | {:error, String.t()}
Create a monthly subscription. Once the organization has entered a new payment card we create a subscription for it. We'll do updating the card in a separate function
@spec create_period_based_subscription(Glific.Partners.Organization.t(), map(), map()) :: {:ok, Stripe.Subscription.t()} | {:pending, map()} | {:error, String.t()}
create subscription on the basis of billing period
@spec create_quarterly_subscription(Glific.Partners.Organization.t(), map()) :: {:ok, Stripe.Subscription.t()} | {:pending, map()} | {:error, String.t()}
Create a quarterly subscription.
@spec create_subscription(Glific.Partners.Organization.t(), map()) :: {:ok, Stripe.Subscription.t()} | {:pending, map()} | {:error, String.t()}
create subscription on the basis of billing period
@spec credit_customer(map()) :: any() | non_neg_integer()
Adding credit to customer in Stripe
fetches customer portal url of organization with billing status as active
@spec delete_billing(t()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}
Delete the billing record
Retrieve a billing record by clauses
Validate entered coupon code and return with coupon details
@spec list_billing_period() :: [String.t()]
List of available billing period
A common function for making Stripe API calls with params that are not supported withing Stripity Stripe
@spec monthly_stripe_ids() :: map()
Fetch the stripe id's
@spec period_usage(DateTime.t()) :: :ok
This is called on a regular schedule to update usage.
@spec quarterly_stripe_ids() :: map()
Fetch the stripe id's
@spec record_usage(non_neg_integer(), DateTime.t(), DateTime.t()) :: :ok
Record the usage for a specific organization from start_date to end_date both dates inclusive
@spec subscription_created_callback(Stripe.Subscription.t(), non_neg_integer()) :: :ok | {:error, Stripe.Error.t()}
Stripe subscription created callback via webhooks. We are using this to update the prorate data with monthly billing.
@spec tax_rates() :: list()
Fetch the stripe tax rates
@spec update_billing(t(), map()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}
Update the billing record
@spec update_payment_method(Glific.Partners.Organization.t(), String.t()) :: {:ok, t()} | {:error, map()}
Update organization and stripe customer with the current payment method as returned by stripe
@spec update_stripe_customer(t(), map()) :: {:ok, t()} | {:error, Stripe.Error.t()}
Update the stripe customer details record
@spec update_subscription(t(), Glific.Partners.Organization.t()) :: Glific.Partners.Organization.t()
Update organization subscription plan
update_subscription_details(subscription, organization_id, billing)
View Source@spec update_subscription_details( Stripe.Subscription.t(), non_neg_integer(), t() | nil ) :: {:ok, Stripe.Subscription.t()} | {:error, String.t()}
Update subscription details. We will also use this method while updating the details form webhook.
@spec update_usage(non_neg_integer(), map()) :: :ok
Update the usage record for all active subscriptions on a daily and weekly basis