chore(docs): added eslint to lint documentation code blocks (#2920)

* docs: added rule for code length

* chore: fixes based on vale errors

* changed to use eslint

* fixes using eslint

* added github action for documentation eslint

* changed allowed max-length

* fixed incorrect heading level

* removed comment
This commit is contained in:
Shahed Nasser
2022-12-30 18:44:46 +02:00
committed by GitHub
parent 99add15fc3
commit d1b4b11ff6
67 changed files with 2611 additions and 1735 deletions
@@ -50,51 +50,60 @@ The first step to create a payment provider is to create a JavaScript or TypeScr
For example, create the file `src/services/my-payment.ts` with the following content:
<!-- eslint-disable max-len -->
```ts title=src/services/my-payment.ts
import { AbstractPaymentService, Cart, Data, Payment, PaymentSession, PaymentSessionStatus, TransactionBaseService } from "@medusajs/medusa"
import { EntityManager } from "typeorm";
import {
AbstractPaymentService,
Cart, Data, Payment, PaymentSession,
PaymentSessionStatus, TransactionBaseService,
} from "@medusajs/medusa"
import { EntityManager } from "typeorm"
class MyPaymentService extends AbstractPaymentService<TransactionBaseService> {
protected manager_: EntityManager;
protected transactionManager_: EntityManager;
protected manager_: EntityManager
protected transactionManager_: EntityManager
getPaymentData(paymentSession: PaymentSession): Promise<Data> {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
updatePaymentData(paymentSessionData: Data, data: Data): Promise<Data> {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
createPayment(cart: Cart): Promise<Data> {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
retrievePayment(paymentData: Data): Promise<Data> {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
updatePayment(paymentSessionData: Data, cart: Cart): Promise<Data> {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
authorizePayment(paymentSession: PaymentSession, context: Data): Promise<{ data: Data; status: PaymentSessionStatus; }> {
throw new Error("Method not implemented.");
authorizePayment(
paymentSession: PaymentSession,
context: Data
): Promise<{ data: Data; status: PaymentSessionStatus; }> {
throw new Error("Method not implemented.")
}
capturePayment(payment: Payment): Promise<Data> {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
refundPayment(payment: Payment, refundAmount: number): Promise<Data> {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
cancelPayment(payment: Payment): Promise<Data> {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
deletePayment(paymentSession: PaymentSession): Promise<void> {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
getStatus(data: Data): Promise<PaymentSessionStatus> {
throw new Error("Method not implemented.");
throw new Error("Method not implemented.")
}
}
export default MyPaymentService;
export default MyPaymentService
```
Where `MyPaymentService` is the name of your Payment Provider service. For example, Stripes Payment Provider Service is called `StripeProviderService`.
@@ -123,10 +132,16 @@ You can also use the constructor to initialize your integration with the third-p
Additionally, if youre creating your Payment Provider as an external plugin to be installed on any Medusa server and you want to access the options added for the plugin, you can access it in the constructor. The options are passed as a second parameter:
<!-- eslint-disable max-len -->
```ts
constructor({ productService }, options) {
super();
//you can access options here
class MyPaymentService extends AbstractPaymentService<TransactionBaseService> {
// ...
constructor({ productService }, options) {
super()
// you can access options here
}
// ...
}
```
@@ -140,15 +155,20 @@ This method must return an object that is going to be stored in the `data` field
An example of a minimal implementation of `createPayment` that does not interact with any third-party providers:
<!-- eslint-disable max-len -->
```ts
import { Cart, Data } from "@medusajs/medusa"
//...
// ...
async createPayment(cart: Cart): Promise<Data> {
return {
id: 'test-payment',
status: 'pending'
};
class MyPaymentService extends AbstractPaymentService<TransactionBaseService> {
// ...
async createPayment(cart: Cart): Promise<Data> {
return {
id: "test-payment",
status: "pending",
}
}
}
```
@@ -162,12 +182,17 @@ This method must return an object containing the data from the third-party provi
An example of a minimal implementation of `retrievePayment` where you dont need to interact with the third-party provider:
<!-- eslint-disable max-len -->
```ts
import { Data } from "@medusajs/medusa"
//...
// ...
async retrievePayment(paymentData: Data): Promise<Data> {
return {};
class MyPaymentService extends AbstractPaymentService<TransactionBaseService> {
// ...
async retrievePayment(paymentData: Data): Promise<Data> {
return {}
}
}
```
@@ -189,12 +214,17 @@ This method returns a string that represents the status. The status must be one
An example of a minimal implementation of `getStatus` where you dont need to interact with the third-party provider:
<!-- eslint-disable max-len -->
```ts
import { Data, PaymentSessionStatus } from "@medusajs/medusa"
//...
// ...
async getStatus(data: Data): Promise<PaymentSessionStatus> {
return PaymentSessionStatus.AUTHORIZED;
class MyPaymentService extends AbstractPaymentService<TransactionBaseService> {
// ...
async getStatus(data: Data): Promise<PaymentSessionStatus> {
return PaymentSessionStatus.AUTHORIZED
}
}
```
@@ -222,12 +252,17 @@ This method must return an object that will be stored in the `data` field of the
An example of a minimal implementation of `updatePayment` that does not need to make any updates on the third-party provider or the `data` field of the Payment Session:
```ts
import { Cart, Data } from "@medusajs/medusa";
//...
<!-- eslint-disable max-len -->
async updatePayment(paymentSessionData: Data, cart: Cart): Promise<Data> {
return paymentSessionData;
```ts
import { Cart, Data } from "@medusajs/medusa"
// ...
class MyPaymentService extends AbstractPaymentService<TransactionBaseService> {
// ...
async updatePayment(paymentSessionData: Data, cart: Cart): Promise<Data> {
return paymentSessionData
}
}
```
@@ -243,12 +278,20 @@ This method must return an object that will be stored in the `data` field of the
An example of a minimal implementation of `updatePaymentData` that returns the `updatedData` passed in the body of the request as-is to update the `data` field of the Payment Session.
```ts
import { Data } from "@medusajs/medusa";
//...
<!-- eslint-disable max-len -->
async updatePaymentData(paymentSessionData: Data, updatedData: Data): Promise<Data> {
return updatedData;
```ts
import { Data } from "@medusajs/medusa"
// ...
class MyPaymentService extends AbstractPaymentService<TransactionBaseService> {
// ...
async updatePaymentData(
paymentSessionData: Data,
updatedData: Data
): Promise<Data> {
return updatedData
}
}
```
@@ -267,12 +310,17 @@ You can use this method to interact with the third-party provider to delete data
An example of a minimal implementation of `deletePayment` where no interaction with a third-party provider is required:
```ts
import { PaymentSession } from "@medusajs/medusa";
//...
<!-- eslint-disable max-len -->
async deletePayment(paymentSession: PaymentSession): Promise<void> {
return;
```ts
import { PaymentSession } from "@medusajs/medusa"
// ...
class MyPaymentService extends AbstractPaymentService<TransactionBaseService> {
// ...
async deletePayment(paymentSession: PaymentSession): Promise<void> {
return
}
}
```
@@ -305,17 +353,29 @@ You can utilize this method to interact with the third-party provider and perfor
An example of a minimal implementation of `authorizePayment` that doesnt need to interact with any third-party provider:
```ts
import { Data, PaymentSession, PaymentSessionStatus } from "@medusajs/medusa";
//...
<!-- eslint-disable max-len -->
async authorizePayment(paymentSession: PaymentSession, context: Data): Promise<{ data: Data; status: PaymentSessionStatus; }> {
return {
status: PaymentSessionStatus.AUTHORIZED,
data: {
id: 'test'
```ts
import {
Data,
PaymentSession,
PaymentSessionStatus,
} from "@medusajs/medusa"
// ...
class MyPaymentService extends AbstractPaymentService<TransactionBaseService> {
// ...
async authorizePayment(
paymentSession: PaymentSession,
context: Data
): Promise<{ data: Data; status: PaymentSessionStatus; }> {
return {
status: PaymentSessionStatus.AUTHORIZED,
data: {
id: "test",
},
}
};
}
}
```
@@ -329,12 +389,17 @@ This method must return an object to be stored in the `data` field of the Paymen
An example of a minimal implementation of `getPaymentData`:
```ts
import { Data, PaymentSession } from "@medusajs/medusa";
//...
<!-- eslint-disable max-len -->
async getPaymentData(paymentSession: PaymentSession): Promise<Data> {
return paymentSession.data;
```ts
import { Data, PaymentSession } from "@medusajs/medusa"
// ...
class MyPaymentService extends AbstractPaymentService<TransactionBaseService> {
// ...
async getPaymentData(paymentSession: PaymentSession): Promise<Data> {
return paymentSession.data
}
}
```
@@ -352,14 +417,19 @@ This method must return an object that will be stored in the `data` field of the
An example of a minimal implementation of `capturePayment` that doesnt need to interact with a third-party provider:
```ts
import { Data, Payment } from "@medusajs/medusa";
//...
<!-- eslint-disable max-len -->
async capturePayment(payment: Payment): Promise<Data> {
return {
status: 'captured'
};
```ts
import { Data, Payment } from "@medusajs/medusa"
// ...
class MyPaymentService extends AbstractPaymentService<TransactionBaseService> {
// ...
async capturePayment(payment: Payment): Promise<Data> {
return {
status: "captured",
}
}
}
```
@@ -377,13 +447,21 @@ This method must return an object that is stored in the `data` field of the Paym
An example of a minimal implementation of `refundPayment` that doesnt need to interact with a third-party provider:
```ts
import { Data, Payment } from "@medusajs/medusa";
//...
<!-- eslint-disable max-len -->
async refundPayment(payment: Payment, refundAmount: number): Promise<Data> {
return {
id: 'test'
```ts
import { Data, Payment } from "@medusajs/medusa"
// ...
class MyPaymentService extends AbstractPaymentService<TransactionBaseService> {
// ...
async refundPayment(
payment: Payment,
refundAmount: number
): Promise<Data> {
return {
id: "test",
}
}
}
```
@@ -405,13 +483,18 @@ This method must return an object that is stored in the `data` field of the Paym
An example of a minimal implementation of `cancelPayment` that doesnt need to interact with a third-party provider:
```ts
import { Data, Payment } from "@medusajs/medusa";
//...
<!-- eslint-disable max-len -->
async cancelPayment(payment: Payment): Promise<Data> {
return {
id: 'test'
```ts
import { Data, Payment } from "@medusajs/medusa"
// ...
class MyPaymentService extends AbstractPaymentService<TransactionBaseService> {
// ...
async cancelPayment(payment: Payment): Promise<Data> {
return {
id: "test",
}
}
}
```
@@ -438,26 +521,31 @@ If youre using Medusas [Next.js](../../../starters/nextjs-medusa-starter.m
An example of the implementation of `retrieveSavedMethods` taken from Stripes Payment Provider:
<!-- eslint-disable max-len -->
```ts
import { Customer, Data } from "@medusajs/medusa"
//...
// ...
/**
* Fetches a customers saved payment methods if registered in Stripe.
* @param {object} customer - customer to fetch saved cards for
* @returns {Promise<Array<object>>} saved payments methods
*/
async retrieveSavedMethods(customer: Customer): Promise<Data[]> {
if (customer.metadata && customer.metadata.stripe_id) {
const methods = await this.stripe_.paymentMethods.list({
customer: customer.metadata.stripe_id,
type: "card",
})
class MyPaymentService extends AbstractPaymentService<TransactionBaseService> {
// ...
/**
* Fetches a customers saved payment methods if registered in Stripe.
* @param {object} customer - customer to fetch saved cards for
* @return {Promise<Array<object>>} saved payments methods
*/
async retrieveSavedMethods(customer: Customer): Promise<Data[]> {
if (customer.metadata && customer.metadata.stripe_id) {
const methods = await this.stripe_.paymentMethods.list({
customer: customer.metadata.stripe_id,
type: "card",
})
return methods.data
return methods.data
}
return Promise.resolve([])
}
return Promise.resolve([])
}
```