Skip to content

Commit

Permalink
feat(payments-plugin): wip
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnvdbrug committed Feb 21, 2024
1 parent 138d9ff commit fb4cace
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/payments-plugin/src/mollie/mollie.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ export interface MolliePluginOptions {
providers: [MollieService, { provide: PLUGIN_INIT_OPTIONS, useFactory: () => MolliePlugin.options }],
configuration: (config: RuntimeVendureConfig) => {
config.paymentOptions.paymentMethodHandlers.push(molliePaymentHandler);
// config.customFields.Order.push({
// name: 'activeMollieOrderId',
// type: 'string',
// })
return config;
},
shopApiExtensions: {
Expand Down
15 changes: 12 additions & 3 deletions packages/payments-plugin/src/mollie/mollie.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Inject, Injectable } from '@nestjs/common';
import { ModuleRef } from '@nestjs/core';
import {
ActiveOrderService,
assertFound,
EntityHydrator,
ErrorResult,
Injector,
Expand All @@ -24,7 +25,7 @@ import {
ProductVariantService,
RequestContext,
} from '@vendure/core';
import { OrderStateMachine } from '@vendure/core/dist/service/helpers/order-state-machine/order-state-machine';
import { OrderStateMachine } from '@vendure/core/';
import { totalCoveredByPayments } from '@vendure/core/dist/service/helpers/utils/order-utils';

import { loggerCtx, PLUGIN_INIT_OPTIONS } from './constants';
Expand Down Expand Up @@ -145,9 +146,10 @@ export class MollieService {
}
redirectUrl = paymentMethodRedirectUrl;
}
// FIXME: Do we still need to manually do all the above checks like has-customer etc?
if (order.state !== 'ArrangingPayment' && order.state !== 'ArrangingAdditionalPayment') {
// TODO get order state machine and check if transitionable to ArrangingPayment
// const orderStateMachine = this.injector.get(OrderStateMachine);
// Check if order is transitionable to ArrangingPayment, because that will happen after Mollie payment
await this.canTransitionTo(ctx, order, 'ArrangingPayment');
}
const variantsWithInsufficientSaleableStock = await this.getVariantsWithInsufficientStock(ctx, order);
if (variantsWithInsufficientSaleableStock.length) {
Expand Down Expand Up @@ -405,6 +407,13 @@ export class MollieService {
return variantsWithInsufficientSaleableStock;
}

private async canTransitionTo(ctx: RequestContext, order: Order, state: OrderState) {
// Fetch new order object, because `transition()` mutates the order object
const orderCopy = await assertFound(this.orderService.findOne(ctx, order.id));
const orderStateMachine = this.injector.get(OrderStateMachine);
await orderStateMachine.transition(ctx, orderCopy, state);
}

private async getPaymentMethod(
ctx: RequestContext,
paymentMethodCode: string,
Expand Down

0 comments on commit fb4cace

Please sign in to comment.