feat(medusa,medusa-payment-stripe): Migrate Stripe to Abstract payment service (#1790)
This commit is contained in:
@@ -12,8 +12,7 @@ export type Data = Record<string, unknown>
|
||||
export type PaymentData = Data
|
||||
export type PaymentSessionData = Data
|
||||
|
||||
export interface PaymentService<T extends TransactionBaseService>
|
||||
extends TransactionBaseService {
|
||||
export interface PaymentService extends TransactionBaseService {
|
||||
getIdentifier(): string
|
||||
|
||||
getPaymentData(paymentSession: PaymentSession): Promise<PaymentData>
|
||||
@@ -50,9 +49,9 @@ export interface PaymentService<T extends TransactionBaseService>
|
||||
getStatus(data: Data): Promise<PaymentSessionStatus>
|
||||
}
|
||||
|
||||
export abstract class AbstractPaymentService<T extends TransactionBaseService>
|
||||
export abstract class AbstractPaymentService
|
||||
extends TransactionBaseService
|
||||
implements PaymentService<T>
|
||||
implements PaymentService
|
||||
{
|
||||
protected constructor(container: unknown, config?: Record<string, unknown>) {
|
||||
super(container, config)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
BaseNotificationService,
|
||||
BaseFulfillmentService,
|
||||
BaseNotificationService,
|
||||
BasePaymentService,
|
||||
} from "medusa-interfaces"
|
||||
import { currencies } from "../utils/currencies"
|
||||
@@ -82,7 +82,8 @@ export default async ({
|
||||
const hasCountries = await countryRepo.findOne()
|
||||
if (!hasCountries) {
|
||||
for (const c of countries) {
|
||||
const query = `INSERT INTO "country" ("iso_2", "iso_3", "num_code", "name", "display_name") VALUES ($1, $2, $3, $4, $5)`
|
||||
const query = `INSERT INTO "country" ("iso_2", "iso_3", "num_code", "name", "display_name")
|
||||
VALUES ($1, $2, $3, $4, $5)`
|
||||
|
||||
const iso2 = c.alpha2.toLowerCase()
|
||||
const iso3 = c.alpha3.toLowerCase()
|
||||
@@ -106,7 +107,8 @@ export default async ({
|
||||
const hasCurrencies = await currencyRepo.findOne()
|
||||
if (!hasCurrencies) {
|
||||
for (const [, c] of Object.entries(currencies)) {
|
||||
const query = `INSERT INTO "currency" ("code", "symbol", "symbol_native", "name") VALUES ($1, $2, $3, $4)`
|
||||
const query = `INSERT INTO "currency" ("code", "symbol", "symbol_native", "name")
|
||||
VALUES ($1, $2, $3, $4)`
|
||||
|
||||
const code = c.code.toLowerCase()
|
||||
const sym = c.symbol
|
||||
@@ -122,9 +124,11 @@ export default async ({
|
||||
await storeService.withTransaction(manager).create()
|
||||
|
||||
const payProviders =
|
||||
silentResolution<
|
||||
(typeof BasePaymentService | AbstractPaymentService<never>)[]
|
||||
>(container, "paymentProviders", logger) || []
|
||||
silentResolution<(typeof BasePaymentService | AbstractPaymentService)[]>(
|
||||
container,
|
||||
"paymentProviders",
|
||||
logger
|
||||
) || []
|
||||
const payIds = payProviders.map((p) => p.getIdentifier())
|
||||
|
||||
const pProviderService = container.resolve<PaymentProviderService>(
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { isEmpty, isEqual } from "lodash"
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
import { DeepPartial, EntityManager, In } from "typeorm"
|
||||
import { TransactionBaseService } from "../interfaces"
|
||||
import { IPriceSelectionStrategy } from "../interfaces/price-selection-strategy"
|
||||
import SalesChannelFeatureFlag from "../loaders/feature-flags/sales-channels"
|
||||
import { IPriceSelectionStrategy, TransactionBaseService } from "../interfaces"
|
||||
import {
|
||||
Address,
|
||||
Cart,
|
||||
@@ -36,7 +34,6 @@ import CustomerService from "./customer"
|
||||
import DiscountService from "./discount"
|
||||
import EventBusService from "./event-bus"
|
||||
import GiftCardService from "./gift-card"
|
||||
import { SalesChannelService } from "./index"
|
||||
import InventoryService from "./inventory"
|
||||
import LineItemService from "./line-item"
|
||||
import LineItemAdjustmentService from "./line-item-adjustment"
|
||||
@@ -45,9 +42,11 @@ import ProductService from "./product"
|
||||
import ProductVariantService from "./product-variant"
|
||||
import RegionService from "./region"
|
||||
import ShippingOptionService from "./shipping-option"
|
||||
import StoreService from "./store"
|
||||
import TaxProviderService from "./tax-provider"
|
||||
import TotalsService from "./totals"
|
||||
import SalesChannelFeatureFlag from "../loaders/feature-flags/sales-channels"
|
||||
import StoreService from "./store"
|
||||
import { SalesChannelService } from "./index"
|
||||
|
||||
type InjectedDependencies = {
|
||||
manager: EntityManager
|
||||
|
||||
@@ -26,7 +26,7 @@ type InjectedDependencies = {
|
||||
refundRepository: typeof RefundRepository
|
||||
} & {
|
||||
[key in `${PaymentProviderKey}`]:
|
||||
| AbstractPaymentService<never>
|
||||
| AbstractPaymentService
|
||||
| typeof BasePaymentService
|
||||
}
|
||||
|
||||
@@ -275,11 +275,11 @@ export default class PaymentProviderService extends TransactionBaseService {
|
||||
* @return {PaymentService} the payment provider
|
||||
*/
|
||||
retrieveProvider<
|
||||
TProvider extends AbstractPaymentService<never> | typeof BasePaymentService
|
||||
TProvider extends AbstractPaymentService | typeof BasePaymentService
|
||||
>(
|
||||
providerId: string
|
||||
): TProvider extends AbstractPaymentService<never>
|
||||
? AbstractPaymentService<never>
|
||||
): TProvider extends AbstractPaymentService
|
||||
? AbstractPaymentService
|
||||
: typeof BasePaymentService {
|
||||
try {
|
||||
let provider
|
||||
|
||||
Reference in New Issue
Block a user