Skip to content

Commit

Permalink
## Roadmap Task
Browse files Browse the repository at this point in the history
👉 https://getlago.canny.io/feature-requests/p/add-features-to-the-customer-portal

 ## Context

The current customer portal does not provide any customer wallets information.

 ## Description

This change improves the customer access to their active wallets
information and provides the means to top-up paid credits to their wallets.
  • Loading branch information
ancorcruz committed Sep 26, 2024
1 parent 037290f commit b9bd82c
Show file tree
Hide file tree
Showing 12 changed files with 1,088 additions and 75 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

module Mutations
module CustomerPortal
module WalletTransactions
class Create < BaseMutation
include AuthenticableCustomerPortalUser

graphql_name "CreateCustomerPortalWalletTransaction"
description "Creates a new Customer Wallet Transaction from Customer Portal"

argument :paid_credits, String, required: false
argument :wallet_id, ID, required: true

type Types::CustomerPortal::WalletTransactions::Object.collection_type

def resolve(**args)
organization = context[:customer_portal_user].organization
result = ::WalletTransactions::CreateService.call(organization:, params: args)

result.success? ? result.wallet_transactions : result_error(result)
end
end
end
end
end
27 changes: 27 additions & 0 deletions app/graphql/resolvers/customer_portal/wallets_resolver.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module Resolvers
module CustomerPortal
class WalletsResolver < Resolvers::BaseResolver
include AuthenticableCustomerPortalUser

description 'Query wallets'

argument :limit, Integer, required: false
argument :page, Integer, required: false

type Types::CustomerPortal::Wallets::Object.collection_type, null: false

def resolve(page: nil, limit: nil)
context[:customer_portal_user]
.wallets
.active
.page(page)
.per(limit)
.order(created_at: :desc)
rescue ActiveRecord::RecordNotFound
not_found_error(resource: 'customer')
end
end
end
end
24 changes: 24 additions & 0 deletions app/graphql/types/customer_portal/wallet_transactions/object.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

module Types
module CustomerPortal
module WalletTransactions
class Object < Types::BaseObject
graphql_name "CustomerPortalWalletTransaction"

field :id, ID, null: false
field :wallet, Types::CustomerPortal::Wallets::Object

field :amount, String, null: false
field :credit_amount, String, null: false
field :status, Types::WalletTransactions::StatusEnum, null: false
field :transaction_status, Types::WalletTransactions::TransactionStatusEnum, null: false
field :transaction_type, Types::WalletTransactions::TransactionTypeEnum, null: false

field :created_at, GraphQL::Types::ISO8601DateTime, null: false
field :settled_at, GraphQL::Types::ISO8601DateTime, null: true
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false
end
end
end
end
28 changes: 28 additions & 0 deletions app/graphql/types/customer_portal/wallets/object.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

module Types
module CustomerPortal
module Wallets
class Object < Types::BaseObject
graphql_name "CustomerPortalWallet"
description "CustomerPortalWallet"

field :id, ID, null: false

field :currency, Types::CurrencyEnum, null: false
field :expiration_at, GraphQL::Types::ISO8601DateTime, null: true
field :name, String, null: true
field :status, Types::Wallets::StatusEnum, null: false

field :balance_cents, GraphQL::Types::BigInt, null: false
field :consumed_amount_cents, GraphQL::Types::BigInt, null: false
field :consumed_credits, GraphQL::Types::Float, null: false
field :credits_balance, GraphQL::Types::Float, null: false
field :credits_ongoing_balance, GraphQL::Types::Float, null: false
field :ongoing_balance_cents, GraphQL::Types::BigInt, null: false
field :ongoing_usage_balance_cents, GraphQL::Types::BigInt, null: false
field :rate_amount, GraphQL::Types::Float, null: false
end
end
end
end
1 change: 1 addition & 0 deletions app/graphql/types/mutation_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class MutationType < Types::BaseObject
field :update_customer, mutation: Mutations::Customers::Update
field :update_customer_invoice_grace_period, mutation: Mutations::Customers::UpdateInvoiceGracePeriod

field :create_customer_portal_wallet_transaction, mutation: Mutations::CustomerPortal::WalletTransactions::Create
field :download_customer_portal_invoice, mutation: Mutations::CustomerPortal::DownloadInvoice
field :generate_customer_portal_url, mutation: Mutations::CustomerPortal::GenerateUrl

Expand Down
1 change: 1 addition & 0 deletions app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class QueryType < Types::BaseObject
field :customer_portal_organization, resolver: Resolvers::CustomerPortal::OrganizationResolver
field :customer_portal_overdue_balances, resolver: Resolvers::CustomerPortal::Analytics::OverdueBalancesResolver
field :customer_portal_user, resolver: Resolvers::CustomerPortal::CustomerResolver
field :customer_portal_wallets, resolver: Resolvers::CustomerPortal::WalletsResolver
field :customer_usage, resolver: Resolvers::Customers::UsageResolver
field :customers, resolver: Resolvers::CustomersResolver
field :events, resolver: Resolvers::EventsResolver
Expand Down
89 changes: 89 additions & 0 deletions schema.graphql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b9bd82c

Please sign in to comment.