**What** One problem with local development can be the dependencies management. To mitigate that, transform checks from an instance of to value check as well as harmonize utils function to be part of the class as a static method instead of separate utilities. By using this approach we are not dependent of the origin of the class and therefore it should ease the user experience. **NOTE** As a next step to discuss, we should probably move the interfaces from the interfaces/medusa package to the utils package. Then we can deprecate the interfaces package and remove it at a later time
86 lines
2.4 KiB
JavaScript
86 lines
2.4 KiB
JavaScript
import BaseService from "./base-service"
|
|
|
|
/**
|
|
* The interface that all payment services must inherit from. The intercace
|
|
* provides the necessary methods for creating, authorizing and managing
|
|
* payments.
|
|
* @interface
|
|
* @deprecated use AbstractPaymentProcessor from @medusajs/medusa instead
|
|
*/
|
|
class BasePaymentService extends BaseService {
|
|
static _isPaymentService = true
|
|
|
|
static isPaymentService(obj) {
|
|
return obj?.constructor?._isPaymentService
|
|
}
|
|
|
|
constructor() {
|
|
super()
|
|
}
|
|
|
|
getIdentifier() {
|
|
return this.constructor.identifier
|
|
}
|
|
|
|
/**
|
|
* Used to create a payment to be processed with the service's payment gateway.
|
|
* @param cart {object} - the cart that the payment should cover.
|
|
* @return {Promise<{object}>} - returns a promise that resolves to an object
|
|
* containing the payment data. This data will be saved to the cart for later
|
|
* use.
|
|
*/
|
|
createPayment(cart) {
|
|
throw Error("createPayment must be overridden by the child class")
|
|
}
|
|
|
|
/**
|
|
* Used to retrieve a payment.
|
|
* @param cart {object} - the cart whose payment should be retrieved.
|
|
* @return {Promise<{object}>} - returns a promise that resolves to the
|
|
* payment object as stored with the provider.
|
|
*/
|
|
retrievePayment(cart) {
|
|
throw Error("getPayment must be overridden by the child class")
|
|
}
|
|
|
|
/**
|
|
* Used to update a payment. This method is called when the cart is updated.
|
|
* @param cart {object} - the cart whose payment should be updated.
|
|
* @return {Promise<{object}>} - returns a promise that resolves to the
|
|
* payment object as stored with the provider.
|
|
*/
|
|
updatePayment(cart) {
|
|
throw Error("updatePayment must be overridden by the child class")
|
|
}
|
|
|
|
getStatus() {
|
|
throw Error("getStatus must be overridden by the child class")
|
|
}
|
|
|
|
authorizePayment() {
|
|
throw Error("authorizePayment must be overridden by the child class")
|
|
}
|
|
|
|
capturePayment() {
|
|
throw Error("capturePayment must be overridden by the child class")
|
|
}
|
|
|
|
refundPayment() {
|
|
throw Error("refundPayment must be overridden by the child class")
|
|
}
|
|
|
|
deletePayment() {
|
|
throw Error("deletePayment must be overridden by the child class")
|
|
}
|
|
|
|
/**
|
|
* If the payment provider can save a payment method this function will
|
|
* retrieve them.
|
|
*/
|
|
retrieveSavedMethods(customer) {
|
|
return Promise.resolve([])
|
|
}
|
|
}
|
|
|
|
export default BasePaymentService
|