PaymentService

PaymentService

Contains methods relating to Payment entities.

Signature

class PaymentService {
  constructor(connection: TransactionalConnection, paymentStateMachine: PaymentStateMachine, refundStateMachine: RefundStateMachine, paymentMethodService: PaymentMethodService, eventBus: EventBus)
  async create(ctx: RequestContext, input: DeepPartial<Payment>) => Promise<Payment>;
  async findOneOrThrow(ctx: RequestContext, id: ID, relations: string[] = ['order']) => Promise<Payment>;
  async transitionToState(ctx: RequestContext, paymentId: ID, state: PaymentState) => Promise<Payment | PaymentStateTransitionError>;
  getNextStates(payment: Payment) => ReadonlyArray<PaymentState>;
  async createPayment(ctx: RequestContext, order: Order, amount: number, method: string, metadata: any) => Promise<Payment | IneligiblePaymentMethodError>;
  async settlePayment(ctx: RequestContext, paymentId: ID) => Promise<PaymentStateTransitionError | Payment>;
  async createManualPayment(ctx: RequestContext, order: Order, amount: number, input: ManualPaymentInput) => ;
  async createRefund(ctx: RequestContext, input: RefundOrderInput, order: Order, items: OrderItem[], selectedPayment: Payment) => Promise<Refund | RefundStateTransitionError>;
}

Members

constructor

method
type:
(connection: TransactionalConnection, paymentStateMachine: PaymentStateMachine, refundStateMachine: RefundStateMachine, paymentMethodService: PaymentMethodService, eventBus: EventBus) => PaymentService

create

async method
type:
(ctx: RequestContext, input: DeepPartial<Payment>) => Promise<Payment>

findOneOrThrow

async method
type:
(ctx: RequestContext, id: ID, relations: string[] = ['order']) => Promise<Payment>

transitionToState

async method
type:
(ctx: RequestContext, paymentId: ID, state: PaymentState) => Promise<Payment | PaymentStateTransitionError>

Transitions a Payment to the given state.

When updating a Payment in the context of an Order, it is preferable to use the OrderService transitionPaymentToState() method, which will also handle updating the Order state too.

getNextStates

method
type:
(payment: Payment) => ReadonlyArray<PaymentState>

createPayment

async method
type:
(ctx: RequestContext, order: Order, amount: number, method: string, metadata: any) => Promise<Payment | IneligiblePaymentMethodError>

Creates a new Payment.

When creating a Payment in the context of an Order, it is preferable to use the OrderService addPaymentToOrder() method, which will also handle updating the Order state too.

settlePayment

async method
type:
(ctx: RequestContext, paymentId: ID) => Promise<PaymentStateTransitionError | Payment>

Settles a Payment.

When settling a Payment in the context of an Order, it is preferable to use the OrderService settlePayment() method, which will also handle updating the Order state too.

createManualPayment

async method
type:
(ctx: RequestContext, order: Order, amount: number, input: ManualPaymentInput) =>

Creates a Payment from the manual payment mutation in the Admin API

When creating a manual Payment in the context of an Order, it is preferable to use the OrderService addManualPaymentToOrder() method, which will also handle updating the Order state too.

createRefund

async method
type:
(ctx: RequestContext, input: RefundOrderInput, order: Order, items: OrderItem[], selectedPayment: Payment) => Promise<Refund | RefundStateTransitionError>

Creates a Refund against the specified Payment. If the amount to be refunded exceeds the value of the specified Payment (in the case of multiple payments on a single Order), then the remaining outstanding refund amount will be refunded against the next available Payment from the Order.

When creating a Refund in the context of an Order, it is preferable to use the OrderService refundOrder() method, which performs additional validation.