Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
silenaker committed Aug 30, 2024
1 parent 710ff38 commit 393d233
Show file tree
Hide file tree
Showing 17 changed files with 1,097 additions and 924 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ interface StepInput {
currency_code: string
provider_token?: string
context?: PaymentProviderContext
data?: Record<string, unknown>
}

export const createPaymentSessionStepId = "create-payment-session"
Expand All @@ -31,8 +30,7 @@ export const createPaymentSessionStep = createStep(
provider_token: input.provider_token,
currency_code: input.currency_code,
amount: input.amount,
data: input.data ?? {},
context: input.context,
context: input.context ?? {},
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ export const deletePaymentSessionsStep = createStep(
provider_id: paymentSession.provider_id,
currency_code: paymentSession.currency_code,
amount: paymentSession.amount,
data: paymentSession.data ?? {},
context: paymentSession.context,
context: paymentSession.context ?? {},
}

// Creating a payment session also requires an external call. If we fail to recreate the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export const capturePaymentStep = createStep(
ModuleRegistrationName.PAYMENT
)

const payment = await paymentModule.capturePayment(input)
const payment = await paymentModule.capturePayment(input.payment_id, {
amount: input.amount,
captured_by: input.captured_by,
})

return new StepResponse(payment)
}
Expand Down
7 changes: 5 additions & 2 deletions packages/core/core-flows/src/payment/steps/refund-payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { StepResponse, createStep } from "@medusajs/workflows-sdk"

type StepInput = {
payment_id: string
created_by?: string
refunded_by?: string
amount?: BigNumberInput
}

Expand All @@ -16,7 +16,10 @@ export const refundPaymentStep = createStep(
ModuleRegistrationName.PAYMENT
)

const payment = await paymentModule.refundPayment(input)
const payment = await paymentModule.refundPayment(input.payment_id, {
amount: input.amount,
refunded_by: input.refunded_by,
})

return new StepResponse(payment)
}
Expand Down
13 changes: 9 additions & 4 deletions packages/core/types/src/payment/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@ import { BigNumberValue } from "../totals"
/* ********** PAYMENT COLLECTION ********** */

export type PaymentCollectionStatus =
| "not_paid"
| "awaiting"
| "pending"
| "paid"
| "partially_paid"
| "authorized"
| "partially_authorized"
| "canceled"
| "refunded"
| "partially_refunded"

export type PaymentSessionStatus =
| "authorized"
| "captured"
| "partially_captured"
| "refunded"
| "partially_refunded"
| "pending"
| "requires_more"
| "error"
| "canceled"
| "processing"

/**
* The payment collection details.
Expand Down
41 changes: 13 additions & 28 deletions packages/core/types/src/payment/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,6 @@ export interface CreateCaptureDTO {
*/
amount?: BigNumberInput

/**
* The associated payment's ID.
*/
payment_id: string

/**
* Who captured the payment. For example,
* a user's ID.
Expand All @@ -207,16 +202,11 @@ export interface CreateRefundDTO {
*/
amount?: BigNumberInput

/**
* The associated payment's ID.
*/
payment_id: string

/**
* Who refunded the payment. For example,
* a user's ID.
*/
created_by?: string
refunded_by?: string
}

/**
Expand All @@ -243,15 +233,10 @@ export interface CreatePaymentSessionDTO {
*/
amount: BigNumberInput

/**
* Necessary data for the associated payment provider to process the payment.
*/
data: Record<string, unknown>

/**
* Necessary context data for the associated payment provider.
*/
context?: PaymentProviderContext
context: PaymentProviderContext
}

/**
Expand All @@ -264,24 +249,24 @@ export interface UpdatePaymentSessionDTO {
id: string

/**
* Necessary data for the associated payment provider to process the payment.
*/
data: Record<string, unknown>

/**
* The ISO 3 character currency code.
* The provider's payment method token
*/
currency_code: string
provider_token?: string

/**
* The amount to be authorized.
* Necessary context data for the associated payment provider.
*/
amount: BigNumberInput
context: PaymentProviderContext
}

/**
* The attributes to authorize in a payment session.
*/
export interface AuthorizePaymentSessionDTO {
/**
* Necessary context data for the associated payment provider.
* The provider token to authorize payment session
*/
context?: PaymentProviderContext
provider_token?: string
}

/**
Expand Down
Loading

0 comments on commit 393d233

Please sign in to comment.