Adds a payment provider service that can easily retrieve payment providers

This commit is contained in:
Sebastian Rindom
2020-02-18 14:58:11 +01:00
parent d114b806d6
commit f8fcd5a3dd
7 changed files with 313 additions and 4 deletions
@@ -0,0 +1,33 @@
import { MedusaError } from "medusa-core-utils"
/**
* Helps retrive payment providers
*/
class PaymentProviderService {
constructor(container) {
/** @private {logger} */
this.container_ = container
}
/**
* Handles incoming jobs.
* @param job {{ eventName: (string), data: (any) }}
* eventName - the name of the event to process
* data - data to send to the subscriber
*
* @returns {PaymentService} the payment provider
*/
retrieveProvider(provider_id) {
try {
const provider = this.container_.resolve(`pp_${provider_id}`)
return provider
} catch (err) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Could not find a payment provider with id: ${provider_id}`
)
}
}
}
export default PaymentProviderService