feat(core-flows,payment,medusa,types): Refund reasons management API (#8436)

* feat(core-flows,payment,medusa,types): add ability to set and manage refund reasons

* fix(payment): validate total amount when refunding payment (#8437)

Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>

* feature: introduce additional_data to the product endpoints (#8405)

* chore(docs): Generated References (#8440)

Generated the following references:
- `product`

* chore: align payment database schema

* Update packages/core/core-flows/src/payment-collection/steps/create-refund-reasons.ts

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>

* chore: address review

---------

Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
Co-authored-by: Harminder Virk <virk.officials@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Riqwan Thamir
2024-08-06 11:47:42 +02:00
committed by GitHub
parent 8fb079786d
commit 0ff5b975e7
36 changed files with 2412 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
import { BigNumberRawValue } from "@medusajs/types"
import { BigNumberRawValue, DAL } from "@medusajs/types"
import {
BigNumber,
MikroOrmBigNumberProperty,
@@ -9,14 +9,24 @@ import {
Entity,
ManyToOne,
OnInit,
OptionalProps,
PrimaryKey,
Property,
Rel,
} from "@mikro-orm/core"
import Payment from "./payment"
import RefundReason from "./refund-reason"
type OptionalProps =
| "note"
| "refund_reason_id"
| "refund_reason"
| DAL.ModelDateColumns
@Entity({ tableName: "refund" })
export default class Refund {
[OptionalProps]?: OptionalProps
@PrimaryKey({ columnType: "text" })
id: string
@@ -36,6 +46,20 @@ export default class Refund {
@Property({ columnType: "text", nullable: true })
payment_id: string
@ManyToOne(() => RefundReason, {
columnType: "text",
mapToPk: true,
fieldName: "refund_reason_id",
nullable: true,
})
refund_reason_id: string | null = null
@ManyToOne(() => RefundReason, { persist: false, nullable: true })
refund_reason: Rel<RefundReason> | null = null
@Property({ columnType: "text", nullable: true })
note: string | null = null
@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
@@ -66,10 +90,12 @@ export default class Refund {
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "ref")
this.refund_reason_id ??= this.refund_reason?.id || null
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "ref")
this.refund_reason_id ??= this.refund_reason?.id || null
}
}