Feat/manual payment (#318)
What A dummy payment provider for testing and potentially other relevant use cases like accepting cash payments. Also makes it possible to start server without notification/payment/fulfillment providers. Why When setting up a starter project it introduces unnecessary overhead to have to set up an account with a payment provider (e.g. Stripe). Adding a dummy provider will remove friction. How Extremely simple wrapper functionality.
This commit is contained in:
1 parent
dde3834124
commit
8783de17cd
9 files changed
+236
-3
No files matched your search
@@ -0,0 +1,95 @@
|
||||
import { PaymentService } from "medusa-interfaces"
|
||||
|
||||
class ManualPaymentService extends PaymentService {
|
||||
static identifier = "manual"
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently held status.
|
||||
* @param {object} paymentData - payment method data from cart
|
||||
* @returns {string} the status of the payment
|
||||
*/
|
||||
async getStatus(paymentData) {
|
||||
const { status } = paymentData
|
||||
return status
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a manual payment with status "pending"
|
||||
* @param {object} cart - cart to create a payment for
|
||||
* @returns {object} an object with staus
|
||||
*/
|
||||
async createPayment() {
|
||||
return { status: "pending" }
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves payment
|
||||
* @param {object} data - the data of the payment to retrieve
|
||||
* @returns {Promise<object>} returns data
|
||||
*/
|
||||
async retrievePayment(data) {
|
||||
return data
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the payment status to authorized
|
||||
* @returns {Promise<{ status: string, data: object }>} result with data and status
|
||||
*/
|
||||
async authorizePayment() {
|
||||
return { status: "authorized", data: { status: "authorized" } }
|
||||
}
|
||||
|
||||
/**
|
||||
* Noop, simply returns existing data.
|
||||
* @param {object} sessionData - payment session data.
|
||||
* @returns {object} same data
|
||||
*/
|
||||
async updatePayment(sessionData) {
|
||||
return sessionData.data
|
||||
}
|
||||
|
||||
async deletePayment() {
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the payment status to captured
|
||||
* @param {object} paymentData - payment method data from cart
|
||||
* @returns {object} object with updated status
|
||||
*/
|
||||
async capturePayment() {
|
||||
return { status: "captured" }
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data currently held in a status
|
||||
* @param {object} paymentData - payment method data from cart
|
||||
* @returns {object} the current data
|
||||
*/
|
||||
async getPaymentData(session) {
|
||||
return session.data
|
||||
}
|
||||
|
||||
/**
|
||||
* Noop, resolves to allow manual refunds.
|
||||
* @param {object} payment - payment method data from cart
|
||||
* @returns {string} same data
|
||||
*/
|
||||
async refundPayment(payment) {
|
||||
return payment.data
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the payment status to cancled
|
||||
* @returns {object} object with canceled status
|
||||
*/
|
||||
async cancelPayment() {
|
||||
return { status: "canceled" }
|
||||
}
|
||||
}
|
||||
|
||||
export default ManualPaymentService
|
||||
Reference in new issue
Block a user