-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(manual-payments): WIP - Add GQL enums, inputs and types
- Loading branch information
1 parent
8e9e11d
commit 65f0c61
Showing
16 changed files
with
714 additions
and
0 deletions.
There are no files selected for viewing
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,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 |
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,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 |
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
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 |
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,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 |
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 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 |
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,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 |
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,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 |
Oops, something went wrong.