fix: make packages/medusa/src/services/payment-provider.js pass eslint (#549)

* fix: make packages/medusa/src/services/payment-provider.js pass eslint

* Linted files line-item, payment-provider and shipping-option.

* Update README.md (#692)

* fix: make packages/medusa/src/services/payment-provider.js pass eslint

* Linted files line-item, payment-provider and shipping-option.

Co-authored-by: Sebastian Rindom <skrindom@gmail.com>
This commit is contained in:
Ajordat
2021-11-10 17:37:23 +01:00
committed by GitHub
parent 3ea6aea5be
commit caf4357c4d
2 changed files with 21 additions and 21 deletions

View File

@@ -2,7 +2,6 @@
/packages/medusa/src/services/fulfillment-provider.js /packages/medusa/src/services/fulfillment-provider.js
/packages/medusa/src/services/middleware.js /packages/medusa/src/services/middleware.js
/packages/medusa/src/services/payment-provider.js
/packages/medusa/src/subscribers/notification.js /packages/medusa/src/subscribers/notification.js
/packages/medusa/src/subscribers/order.js /packages/medusa/src/subscribers/order.js
/packages/medusa/src/subscribers/product.js /packages/medusa/src/subscribers/product.js

View File

@@ -60,7 +60,7 @@ class PaymentProviderService extends BaseService {
} }
if (relations.length) { if (relations.length) {
query.relations = options.relations query.relations = relations
} }
const payment = await paymentRepo.findOne(query) const payment = await paymentRepo.findOne(query)
@@ -95,7 +95,7 @@ class PaymentProviderService extends BaseService {
} }
if (relations.length) { if (relations.length) {
query.relations = options.relations query.relations = relations
} }
const session = await sessionRepo.findOne(query) const session = await sessionRepo.findOne(query)
@@ -117,7 +117,7 @@ class PaymentProviderService extends BaseService {
* @return {Promise} the payment session * @return {Promise} the payment session
*/ */
async createSession(providerId, cart) { async createSession(providerId, cart) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const provider = this.retrieveProvider(providerId) const provider = this.retrieveProvider(providerId)
const sessionData = await provider.createPayment(cart) const sessionData = await provider.createPayment(cart)
@@ -142,12 +142,13 @@ class PaymentProviderService extends BaseService {
/** /**
* Refreshes a payment session with the given provider. * Refreshes a payment session with the given provider.
* This means, that we delete the current one and create a new. * This means, that we delete the current one and create a new.
* @param {string} providerId - the id of the provider to refresh payment for * @param {PaymentSession} paymentSession - the payment session object to
* update
* @param {Cart} cart - a cart object used to calculate the amount, etc. from * @param {Cart} cart - a cart object used to calculate the amount, etc. from
* @return {Promise} the payment session * @return {Promise} the payment session
*/ */
async refreshSession(paymentSession, cart) { async refreshSession(paymentSession, cart) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const session = await this.retrieveSession(paymentSession.id) const session = await this.retrieveSession(paymentSession.id)
const provider = this.retrieveProvider(paymentSession.provider_id) const provider = this.retrieveProvider(paymentSession.provider_id)
@@ -183,7 +184,7 @@ class PaymentProviderService extends BaseService {
* @return {Promise} the updated payment session * @return {Promise} the updated payment session
*/ */
updateSession(paymentSession, cart) { updateSession(paymentSession, cart) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const session = await this.retrieveSession(paymentSession.id) const session = await this.retrieveSession(paymentSession.id)
const provider = this.retrieveProvider(paymentSession.provider_id) const provider = this.retrieveProvider(paymentSession.provider_id)
@@ -197,9 +198,9 @@ class PaymentProviderService extends BaseService {
} }
deleteSession(paymentSession) { deleteSession(paymentSession) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const session = await this.retrieveSession(paymentSession.id).catch( const session = await this.retrieveSession(paymentSession.id).catch(
_ => undefined (_) => undefined
) )
if (!session) { if (!session) {
@@ -220,7 +221,7 @@ class PaymentProviderService extends BaseService {
/** /**
* Finds a provider given an id * Finds a provider given an id
* @param {string} providerId - the id of the provider to get * @param {string} providerId - the id of the provider to get
* @returns {PaymentService} the payment provider * @return {PaymentService} the payment provider
*/ */
retrieveProvider(providerId) { retrieveProvider(providerId) {
try { try {
@@ -241,7 +242,7 @@ class PaymentProviderService extends BaseService {
} }
async createPayment(cart) { async createPayment(cart) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const { payment_session: paymentSession, region, total } = cart const { payment_session: paymentSession, region, total } = cart
const provider = this.retrieveProvider(paymentSession.provider_id) const provider = this.retrieveProvider(paymentSession.provider_id)
const paymentData = await provider.getPaymentData(paymentSession) const paymentData = await provider.getPaymentData(paymentSession)
@@ -261,7 +262,7 @@ class PaymentProviderService extends BaseService {
} }
async updatePayment(paymentId, update) { async updatePayment(paymentId, update) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const payment = await this.retrievePayment(paymentId) const payment = await this.retrievePayment(paymentId)
if ("order_id" in update) { if ("order_id" in update) {
@@ -278,9 +279,9 @@ class PaymentProviderService extends BaseService {
} }
async authorizePayment(paymentSession, context) { async authorizePayment(paymentSession, context) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const session = await this.retrieveSession(paymentSession.id).catch( const session = await this.retrieveSession(paymentSession.id).catch(
_ => undefined (_) => undefined
) )
if (!session) { if (!session) {
@@ -303,7 +304,7 @@ class PaymentProviderService extends BaseService {
} }
async updateSessionData(paySession, update) { async updateSessionData(paySession, update) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const session = await this.retrieveSession(paySession.id) const session = await this.retrieveSession(paySession.id)
const provider = this.retrieveProvider(paySession.provider_id) const provider = this.retrieveProvider(paySession.provider_id)
@@ -319,7 +320,7 @@ class PaymentProviderService extends BaseService {
} }
async cancelPayment(paymentObj) { async cancelPayment(paymentObj) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const payment = await this.retrievePayment(paymentObj.id) const payment = await this.retrievePayment(paymentObj.id)
const provider = this.retrieveProvider(payment.provider_id) const provider = this.retrieveProvider(payment.provider_id)
payment.data = await provider.cancelPayment(payment) payment.data = await provider.cancelPayment(payment)
@@ -338,7 +339,7 @@ class PaymentProviderService extends BaseService {
} }
async capturePayment(paymentObj) { async capturePayment(paymentObj) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const payment = await this.retrievePayment(paymentObj.id) const payment = await this.retrievePayment(paymentObj.id)
const provider = this.retrieveProvider(payment.provider_id) const provider = this.retrieveProvider(payment.provider_id)
@@ -353,8 +354,8 @@ class PaymentProviderService extends BaseService {
} }
async refundPayment(payObjs, amount, reason, note) { async refundPayment(payObjs, amount, reason, note) {
return this.atomicPhase_(async manager => { return this.atomicPhase_(async (manager) => {
const payments = await this.listPayments({ id: payObjs.map(p => p.id) }) const payments = await this.listPayments({ id: payObjs.map((p) => p.id) })
let order_id let order_id
const refundable = payments.reduce((acc, next) => { const refundable = payments.reduce((acc, next) => {
@@ -378,7 +379,7 @@ class PaymentProviderService extends BaseService {
const used = [] const used = []
const paymentRepo = manager.getCustomRepository(this.paymentRepository_) const paymentRepo = manager.getCustomRepository(this.paymentRepository_)
let toRefund = payments.find(p => p.amount - p.amount_refunded > 0) let toRefund = payments.find((p) => p.amount - p.amount_refunded > 0)
while (toRefund) { while (toRefund) {
const currentRefundable = toRefund.amount - toRefund.amount_refunded const currentRefundable = toRefund.amount - toRefund.amount_refunded
@@ -395,7 +396,7 @@ class PaymentProviderService extends BaseService {
if (balance > 0) { if (balance > 0) {
toRefund = payments.find( toRefund = payments.find(
p => p.amount - p.amount_refunded > 0 && !used.includes(p.id) (p) => p.amount - p.amount_refunded > 0 && !used.includes(p.id)
) )
} else { } else {
toRefund = null toRefund = null