UNPKG

medusa-payment-tosspayments

Version:
140 lines (139 loc) 8.25 kB
import { AbstractPaymentProcessor, PaymentProcessorContext, PaymentProcessorError, PaymentProcessorSessionResponse, PaymentSessionStatus } from "@medusajs/medusa"; interface TosspaymentsProcessorOptions { key: string; version: string; debug?: boolean; } declare class TossPaymentsProcessor extends AbstractPaymentProcessor { static identifier: string; protected container_: Record<string, unknown>; protected readonly options_: TosspaymentsProcessorOptions | Record<string, unknown> | undefined; private tosspayments_; constructor(container: Record<string, unknown>, options: Record<string, unknown> | undefined); /** * FRONTSTORE * - initiatePayment * - updatePayment * - updatePaymentData * - authorizePayment */ /** * This method is called either if a region has only one payment provider enabled or when a Payment Session is selected, * which occurs when the customer selects their preferred payment method during checkout. * It is used to allow you to make any necessary calls to the third-party provider to initialize the payment. * For example, in Stripe this method is used to create a Payment Intent for the customer. * * @param context */ initiatePayment(context: PaymentProcessorContext): Promise<PaymentProcessorError | PaymentProcessorSessionResponse>; /** * This method is used to update the payment session when the payment amount changes. * It's called whenever the cart or any of its related data is updated. * For example, when a line item is added to the cart or when a shipping method is selected. * * @param context * @returns */ updatePayment(context: PaymentProcessorContext): Promise<PaymentProcessorError | PaymentProcessorSessionResponse | void>; /** * This method is used to update the data field of a payment session. * It's called when a request is sent to the Update Payment Session API Route, or when the CartService's updatePaymentSession is used. * This method can also be used to update the data in the third-party payment provider, if necessary. * * @param sessionId * @param data * @returns */ updatePaymentData(sessionId: string, data: Record<string, unknown>): Promise<PaymentProcessorError | PaymentProcessorSessionResponse["session_data"]>; /** * This method is used to get the status of a Payment or a Payment Session. * Its main usage is within the place order and create swap flows. * If the status returned is not authorized within these flows, then the payment is considered failed and an error will be thrown, stopping the flow from completion. * * @param paymentSessionData * @returns */ getPaymentStatus(paymentSessionData: Record<string, unknown>): Promise<PaymentSessionStatus>; /** * This method is used to authorize payment using the Payment Session of an order. This is called when the cart is completed and before the order is created. * This method is also used for authorizing payments of a swap of an order and when authorizing sessions in a payment collection. * You can interact with a third-party provider and perform any actions necessary to authorize the payment. * The payment authorization might require additional action from the customer before it is declared authorized. * Once that additional action is performed, the authorizePayment method will be called again to validate that the payment is now fully authorized. * So, make sure to implement it for this case as well, if necessary. * Once the payment is authorized successfully and the Payment Session status is set to authorized, the associated order or swap can then be placed or created. * If the payment authorization fails, then an error will be thrown and the order will not be created. * * @param paymentSessionData * @param context * @returns */ authorizePayment(paymentSessionData: Record<string, unknown>, context: Record<string, unknown>): Promise<PaymentProcessorError | { status: PaymentSessionStatus; data: PaymentProcessorSessionResponse["session_data"]; }>; /** * This method is used to provide a uniform way of retrieving the payment information from the third-party provider. * For example, in Stripe’s Payment Processor this method is used to retrieve the payment intent details from Stripe. * * @param paymentSessionData * @returns */ retrievePayment(paymentSessionData: Record<string, unknown> & { paymentKey: string; }): Promise<PaymentProcessorError | PaymentProcessorSessionResponse["session_data"]>; /** * ADMIN PANEL * - refundPayment * - cancelPayment * - capturePayment * - deletePayment */ /** * This method is used to refund an order’s payment. This is typically triggered manually by the store operator from the admin. * The refund amount might be the total order amount or part of it. * This method is also used for refunding payments of a swap or a claim of an order, or when a request is sent to the Refund Payment API Route. * You can utilize this method to interact with the third-party provider and perform any actions necessary to refund the payment. * * @param paymentSessionData * @param refundAmount * @returns */ refundPayment(paymentSessionData: Record<string, unknown>, refundAmount: number): Promise<PaymentProcessorError | PaymentProcessorSessionResponse["session_data"]>; /** * This method is used to cancel an order’s payment. This method is typically triggered by one of the following situations: * 1. Before an order is placed and after the payment is authorized, * an inventory check is done on products to ensure that products are still available for purchase. * If the inventory check fails for any of the products, the payment is canceled. * 2. If the store operator cancels the order from the admin. * 3. When the payment of an order's swap is canceled. * You can utilize this method to interact with the third-party provider and perform any actions necessary to cancel the payment. * * @param paymentSessionData * @returns */ cancelPayment(paymentSessionData: Record<string, unknown>): Promise<PaymentProcessorError | PaymentProcessorSessionResponse["session_data"]>; /** * This method is used to capture the payment amount of an order. This is typically triggered manually by the store operator from the admin. * This method is also used for capturing payments of a swap of an order, or when a request is sent to the Capture Payment API Route. * You can utilize this method to interact with the third-party provider and perform any actions necessary to capture the payment. * * 토스페이먼츠에서는 결제 승인과 동시에 매입이 일어나므로 사용하지 않는다. * * @param paymentSessionData */ capturePayment(paymentSessionData: Record<string, unknown>): Promise<PaymentProcessorError | PaymentProcessorSessionResponse["session_data"]>; /** * This method is used to perform any actions necessary before a Payment Session is deleted. The Payment Session is deleted in one of the following cases: * 1. When a request is sent to delete the Payment Session. * 2. When the Payment Session is refreshed. The Payment Session is deleted so that a newer one is initialized instead. * 3. When the Payment Processor is no longer available. This generally happens when the store operator removes it from the available Payment Processor in the admin. * 4. When the region of the store is changed based on the cart information and the Payment Processor is not available in the new region. * * @param paymentSessionData * @returns */ deletePayment(paymentSessionData: Record<string, unknown>): Promise<PaymentProcessorError | PaymentProcessorSessionResponse["session_data"]>; protected buildError(message: string, e: PaymentProcessorError | Error): PaymentProcessorError; } export default TossPaymentsProcessor;