Skip to content

Commit

Permalink
feat(dunning): Add resolver for payment requests
Browse files Browse the repository at this point in the history
  • Loading branch information
rsempe committed Aug 16, 2024
1 parent 9e5b02e commit d2a7250
Show file tree
Hide file tree
Showing 12 changed files with 453 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/config/permissions/definition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,5 @@ organization:
create:
update:
delete:
payment_requests:
view: true
2 changes: 2 additions & 0 deletions app/config/permissions/role-finance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ organization:
create: false
update: false
delete: false
payment_requests:
view: true
2 changes: 2 additions & 0 deletions app/config/permissions/role-manager.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ organization:
create: false
update: false
delete: false
payment_requests:
view: true
33 changes: 33 additions & 0 deletions app/graphql/resolvers/payment_requests_resolver.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

module Resolvers
class PaymentRequestsResolver < Resolvers::BaseResolver
include AuthenticableApiUser
include RequiredOrganization

REQUIRED_PERMISSION = "payment_requests:view"

description "Query payment requests of an organization"

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

type Types::PaymentRequests::Object.collection_type, null: false

def resolve(page: nil, limit: nil, external_customer_id: nil)
result = PaymentRequestsQuery.call(
organization: current_organization,
filters: {
external_customer_id:
},
pagination: {
page:,
limit:
}
)

result.payment_requests
end
end
end
20 changes: 20 additions & 0 deletions app/graphql/types/payment_requests/object.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Types
module PaymentRequests
class Object < Types::BaseObject
graphql_name "PaymentRequest"

field :id, ID, null: false

field :amount_cents, GraphQL::Types::BigInt, null: false
field :amount_currency, Types::CurrencyEnum, null: false
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
field :email, String, null: false
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false

field :customer, Types::Customers::Object, null: false
field :invoices, [Types::Invoices::Object], null: false
end
end
end
1 change: 1 addition & 0 deletions app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class QueryType < Types::BaseObject
field :password_reset, resolver: Resolvers::PasswordResetResolver
field :payment_provider, resolver: Resolvers::PaymentProviderResolver
field :payment_providers, resolver: Resolvers::PaymentProvidersResolver
field :payment_requests, resolver: Resolvers::PaymentRequestsResolver
field :plan, resolver: Resolvers::PlanResolver
field :plans, resolver: Resolvers::PlansResolver
field :subscription, resolver: Resolvers::SubscriptionResolver
Expand Down
4 changes: 4 additions & 0 deletions app/models/payment_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ class PaymentRequest < ApplicationRecord
validates :email, presence: true
validates :amount_cents, presence: true
validates :amount_currency, presence: true

def invoices
payment_requestable.is_a?(Invoice) ? [payment_requestable] : payment_requestable.invoices
end
end
4 changes: 1 addition & 3 deletions app/serializers/v1/payment_request_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ def customer
end

def invoices
invoices = model.payment_requestable.is_a?(Invoice) ? [model.payment_requestable] : model.payment_requestable.invoices

::CollectionSerializer.new(
invoices,
model.invoices,
::V1::InvoiceSerializer,
collection_name: "invoices"
).serialize
Expand Down
22 changes: 22 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 d2a7250

Please sign in to comment.