-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
👉 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
Showing
12 changed files
with
1,088 additions
and
75 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
app/graphql/mutations/customer_portal/wallet_transactions/create.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
24
app/graphql/types/customer_portal/wallet_transactions/object.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.