Skip to content

Commit

Permalink
feat(manual-payments): WIP - Add GQL enums, inputs and types
Browse files Browse the repository at this point in the history
  • Loading branch information
ivannovosad committed Jan 24, 2025
1 parent 8e9e11d commit 65f0c61
Show file tree
Hide file tree
Showing 16 changed files with 714 additions and 0 deletions.
25 changes: 25 additions & 0 deletions app/graphql/mutations/payments/create.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module Mutations
module Payments
class Create < BaseMutation
include AuthenticableApiUser
include RequiredOrganization

REQUIRED_PERMISSION = "payments:create"

graphql_name "CreatePayment"
description "Creates a manual payment"

input_object_class Types::Payments::CreateInput
type Types::Payments::Object

def resolve(**args)
invoice = current_organization.invoices.find_by(id: args[:invoice_id])

result = ::ManualPayments::CreateService.call(invoice:, params: args)
result.success? ? result.payment : result_error(result)
end
end
end
end
33 changes: 33 additions & 0 deletions app/graphql/resolvers/payments_resolver.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

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

REQUIRED_PERMISSION = "payments:view"

description "Query payments of an organization"

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

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

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

result.payments
end
end
end
2 changes: 2 additions & 0 deletions app/graphql/types/mutation_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class MutationType < Types::BaseObject
field :revoke_membership, mutation: Mutations::Memberships::Revoke
field :update_membership, mutation: Mutations::Memberships::Update

field :create_payment, mutation: Mutations::Payments::Create

field :create_payment_request, mutation: Mutations::PaymentRequests::Create

field :create_password_reset, mutation: Mutations::PasswordResets::Create
Expand Down
20 changes: 20 additions & 0 deletions app/graphql/types/payables/object.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Types
module Payables
class Object < Types::BaseUnion
graphql_name 'Payable'

possible_types Types::Payments::Object, Types::PaymentRequests::Object

def self.resolve_type(object, _context)
case object.class.to_s
when 'Payment'
Types::Payments::Object
when 'PaymentRequest'
Types::PaymentRequests::Object
else
raise "Unexpected payable type: #{object.inspect}"
end
end
end
end
end
14 changes: 14 additions & 0 deletions app/graphql/types/payments/create_input.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Types
module Payments
class CreateInput < Types::BaseInputObject
graphql_name "CreatePaymentInput"

argument :invoice_id, ID, required: true
argument :created_at, GraphQL::Types::ISO8601DateTime, required: true
argument :reference, String, required: true
argument :amount_cents, GraphQL::Types::BigInt, required: true
end
end
end
24 changes: 24 additions & 0 deletions app/graphql/types/payments/object.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

module Types
module Payments
class Object < Types::BaseObject
graphql_name "Payment"

field :id, ID, null: false

field :amount_cents, GraphQL::Types::BigInt, null: false
field :amount_currency, Types::CurrencyEnum, null: false

field :invoice, Types::Invoices::Object, null: false
field :payable, Types::Payables::Object, null: false
field :payable_payment_status, Types::Payments::PayablePaymentStatusEnum, null: true
field :payment_provider, Types::PaymentProviders::ProviderTypeEnum, null: true
field :payment_type, Types::Payments::PaymentTypeEnum, null: false
field :provider_payment_id, GraphQL::Types::String, null: true
field :reference, GraphQL::Types::String, null: true

field :created_at, GraphQL::Types::ISO8601DateTime, null: false
end
end
end
11 changes: 11 additions & 0 deletions app/graphql/types/payments/payable_payment_status_enum.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module Types
module Payments
class PayablePaymentStatusEnum < Types::BaseEnum
Payment::PAYABLE_PAYMENT_STATUS.each do |type|
value type
end
end
end
end
13 changes: 13 additions & 0 deletions app/graphql/types/payments/payment_type_enum.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Types
module Payments
class PaymentTypeEnum < Types::BaseEnum
%w[provider manual].each do |type|
# TODO:
# Payment::PAYMENT_TYPES.keys.each do |type|
value type
end
end
end
end
Loading

0 comments on commit 65f0c61

Please sign in to comment.