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:
Sebastian Rindom authored and GitHub committed 2021-07-16 17:03:35 +02:00
1 parent dde3834124
commit 8783de17cd
9 files changed
+236 -3

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
{
"plugins": [
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-instanceof",
"@babel/plugin-transform-classes"
],
"presets": ["@babel/preset-env"],
"env": {
"test": {
"plugins": ["@babel/plugin-transform-runtime"]
}
}
}
+9
View File
@@ -0,0 +1,9 @@
{
"plugins": ["prettier"],
"extends": ["prettier"],
"rules": {
"prettier/prettier": "error",
"semi": "error",
"no-unused-expressions": "true"
}
}
+15
View File
@@ -0,0 +1,15 @@
/lib
node_modules
.DS_store
.env*
/*.js
!index.js
yarn.lock
/dist
/api
/services
/models
/subscribers
/__mocks__
+13
View File
@@ -0,0 +1,13 @@
/lib
node_modules
.DS_store
.env*
/*.js
!index.js
yarn.lock
src
.gitignore
.eslintrc
.babelrc
.prettierrc
@@ -0,0 +1,7 @@
{
"endOfLine": "lf",
"semi": false,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5"
}
+1
View File
@@ -0,0 +1 @@
// noop
@@ -0,0 +1,40 @@
{
"name": "medusa-payment-manual",
"version": "1.0.0",
"description": "A dummy payment provider to be used for testing or manual payments",
"main": "index.js",
"repository": {
"type": "git",
"url": "https://github.com/medusajs/medusa",
"directory": "packages/medusa-payment-manual"
},
"author": "Sebastian Rindom",
"license": "MIT",
"devDependencies": {
"@babel/cli": "^7.7.5",
"@babel/core": "^7.7.5",
"@babel/node": "^7.7.4",
"@babel/plugin-proposal-class-properties": "^7.7.4",
"@babel/plugin-proposal-optional-chaining": "^7.12.7",
"@babel/plugin-transform-classes": "^7.9.5",
"@babel/plugin-transform-instanceof": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.7.6",
"@babel/preset-env": "^7.7.5",
"@babel/register": "^7.7.4",
"@babel/runtime": "^7.9.6",
"cross-env": "^5.2.1",
"eslint": "^6.8.0",
"jest": "^25.5.2",
"medusa-test-utils": "^1.1.21"
},
"scripts": {
"build": "babel src -d . --ignore **/__tests__",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir . --ignore **/__tests__",
"test": "jest"
},
"peerDependencies": {
"medusa-interfaces": "1.x"
},
"gitHead": "db9d6c0cf55ff60a90415b16bc7582cc4795768f"
}
@@ -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