Adds Adyen payment provider
This commit is contained in:
1 parent
4c9b876407
commit
20c8dc23a1
30 files changed
+1047
-16
No files matched your search
@@ -0,0 +1,10 @@
|
||||
import { Router } from "express"
|
||||
import store from "./routes/store"
|
||||
import hooks from "./routes/hooks"
|
||||
|
||||
export default (rootDirectory) => {
|
||||
const app = Router()
|
||||
store(app, rootDirectory)
|
||||
hooks(app, rootDirectory)
|
||||
return app
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export default (fn) => (...args) => fn(...args).catch(args[2])
|
||||
@@ -0,0 +1,5 @@
|
||||
import { default as wrap } from "./await-middleware"
|
||||
|
||||
export default {
|
||||
wrap,
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
export default async (req, res) => {
|
||||
const adyenService = req.scope.resolve("adyenService")
|
||||
|
||||
const notification = req.body
|
||||
const event = notification.notificationItems[0].NotificationRequestItem
|
||||
|
||||
const valid = adyenService.validateNotification(event)
|
||||
|
||||
if (!valid) {
|
||||
res.status(401).send(`Unauthorized webhook event`)
|
||||
return
|
||||
}
|
||||
|
||||
switch (event.success) {
|
||||
case "false":
|
||||
res.status(400).send(event.reason)
|
||||
return
|
||||
default:
|
||||
res.status(200).send("[accepted]")
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { Router } from "express"
|
||||
import cors from "cors"
|
||||
import bodyParser from "body-parser"
|
||||
import middlewares from "../../middlewares"
|
||||
import { getConfigFile } from "medusa-core-utils"
|
||||
|
||||
const route = Router()
|
||||
|
||||
export default (app, rootDirectory) => {
|
||||
const { configModule } = getConfigFile(rootDirectory, `medusa-config`)
|
||||
const config = (configModule && configModule.projectConfig) || {}
|
||||
|
||||
const storeCors = config.store_cors || ""
|
||||
route.use(
|
||||
cors({
|
||||
origin: storeCors.split(","),
|
||||
credentials: true,
|
||||
})
|
||||
)
|
||||
|
||||
app.use("/adyen-hooks", route)
|
||||
|
||||
route.post(
|
||||
"/capture",
|
||||
bodyParser.json(),
|
||||
middlewares.wrap(require("./capture-hook").default)
|
||||
)
|
||||
|
||||
return app
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { Validator, MedusaError } from "medusa-core-utils"
|
||||
|
||||
export default async (req, res) => {
|
||||
const schema = Validator.object().keys({
|
||||
cart_id: Validator.string().required(),
|
||||
payment_method: Validator.object().required(),
|
||||
provider_id: Validator.string().required(),
|
||||
})
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
if (error) {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
try {
|
||||
const cartService = req.scope.resolve("cartService")
|
||||
const paymentProvider = req.scope.resolve(`pp_${value.provider_id}`)
|
||||
|
||||
const cart = await cartService.retrieve(value.cart_id)
|
||||
|
||||
const { data } = await paymentProvider.authorizePayment(
|
||||
cart,
|
||||
value.payment_method
|
||||
)
|
||||
|
||||
const transactionReference = data.pspReference
|
||||
|
||||
let newPaymentSession = cart.payment_sessions.find(
|
||||
(ps) => ps.provider_id === value.provider_id
|
||||
)
|
||||
|
||||
newPaymentSession = {
|
||||
...newPaymentSession,
|
||||
data,
|
||||
}
|
||||
|
||||
await cartService.setMetadata(
|
||||
cart._id,
|
||||
"adyen_transaction_ref",
|
||||
transactionReference
|
||||
)
|
||||
|
||||
await cartService.updatePaymentSession(
|
||||
cart._id,
|
||||
value.provider_id,
|
||||
newPaymentSession
|
||||
)
|
||||
|
||||
res.status(200).json({ data })
|
||||
} catch (err) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { Validator, MedusaError } from "medusa-core-utils"
|
||||
|
||||
export default async (req, res) => {
|
||||
const schema = Validator.object().keys({
|
||||
payment_provider: Validator.string().required(),
|
||||
payload: Validator.object().required(),
|
||||
payment_data: Validator.object().required(),
|
||||
})
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
if (error) {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
try {
|
||||
const adyenService = req.scope.resolve("adyenService")
|
||||
const paymentProviderService = req.scope.resolve(
|
||||
`${value.payment_provider}AdyenProviderService`
|
||||
)
|
||||
|
||||
const adyenResultCode = await adyenService.checkPaymentResult(
|
||||
value.payment_data,
|
||||
value.payload
|
||||
)
|
||||
|
||||
const status = paymentProviderService.getStatus(adyenResultCode)
|
||||
|
||||
res.status(200).json({ status })
|
||||
} catch (err) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { Router } from "express"
|
||||
import cors from "cors"
|
||||
import bodyParser from "body-parser"
|
||||
import middlewares from "../../middlewares"
|
||||
import { getConfigFile } from "medusa-core-utils"
|
||||
|
||||
const route = Router()
|
||||
|
||||
export default (app, rootDirectory) => {
|
||||
const { configModule } = getConfigFile(rootDirectory, `medusa-config`)
|
||||
const config = (configModule && configModule.projectConfig) || {}
|
||||
|
||||
const storeCors = config.store_cors || ""
|
||||
route.use(
|
||||
cors({
|
||||
origin: storeCors.split(","),
|
||||
credentials: true,
|
||||
})
|
||||
)
|
||||
|
||||
app.use("/adyen", route)
|
||||
|
||||
route.post(
|
||||
"/payment-methods",
|
||||
bodyParser.json(),
|
||||
middlewares.wrap(require("./retrieve-payment-methods").default)
|
||||
)
|
||||
|
||||
route.post(
|
||||
"/authorize",
|
||||
bodyParser.json(),
|
||||
middlewares.wrap(require("./authorize-payment").default)
|
||||
)
|
||||
|
||||
route.post(
|
||||
"/payment-status",
|
||||
bodyParser.json(),
|
||||
middlewares.wrap(require("./check-payment-status").default)
|
||||
)
|
||||
|
||||
return app
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { Validator, MedusaError } from "medusa-core-utils"
|
||||
|
||||
export default async (req, res) => {
|
||||
const schema = Validator.object().keys({
|
||||
cart_id: Validator.string().required(),
|
||||
})
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
if (error) {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
try {
|
||||
const adyenService = req.scope.resolve("adyenService")
|
||||
const cartService = req.scope.resolve("cartService")
|
||||
const regionService = req.scope.resolve("regionService")
|
||||
const totalsService = req.scope.resolve("totalsService")
|
||||
|
||||
const cart = await cartService.retrieve(value.cart_id)
|
||||
const region = await regionService.retrieve(cart.region_id)
|
||||
const total = await totalsService.getTotal(cart)
|
||||
|
||||
const allowedMethods = cart.payment_sessions.map(
|
||||
(ps) => ps.provider_id.split("Adyen")[0]
|
||||
)
|
||||
|
||||
const { data } = await adyenService.retrievePaymentMethods(
|
||||
cart,
|
||||
allowedMethods,
|
||||
total,
|
||||
region.currency_code
|
||||
)
|
||||
|
||||
res.status(200).json({ paymentMethods: data })
|
||||
} catch (err) {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
import axios from "axios"
|
||||
import _ from "lodash"
|
||||
import { hmacValidator } from "@adyen/api-library"
|
||||
import { BaseService } from "medusa-interfaces"
|
||||
|
||||
class AdyenService extends BaseService {
|
||||
constructor({ regionService, cartService, totalsService }, options) {
|
||||
super()
|
||||
|
||||
this.regionService_ = regionService
|
||||
|
||||
this.cartService_ = cartService
|
||||
|
||||
this.totalsService_ = totalsService
|
||||
|
||||
this.options_ = options
|
||||
|
||||
this.adyenCheckoutApi = axios.create({
|
||||
baseURL: "https://checkout-test.adyen.com/v52",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"x-API-key": this.options_.api_key,
|
||||
},
|
||||
})
|
||||
|
||||
this.adyenPaymentApi = axios.create({
|
||||
baseURL: "https://pal-test.adyen.com/pal/servlet/Payment/v52",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"x-API-key": this.options_.api_key,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
getOptions() {
|
||||
return this.options_
|
||||
}
|
||||
|
||||
validateNotification(event) {
|
||||
const validator = new hmacValidator()
|
||||
const validated = validator.validateHMAC(
|
||||
event,
|
||||
this.options_.notification_hmac
|
||||
)
|
||||
return validated
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve payment methods from Ayden using country as filter.
|
||||
* @param {string} countryCode - country code of cart
|
||||
* @param {string} shopperLocale - locale used on website
|
||||
* @returns {string} the status of the payment
|
||||
*/
|
||||
async retrievePaymentMethods(cart, allowedMethods, total, currency) {
|
||||
let request = {
|
||||
allowedPaymentMethods: allowedMethods,
|
||||
amount: {
|
||||
value: total * 100,
|
||||
currency: currency,
|
||||
},
|
||||
merchantAccount: this.options_.merchant_account,
|
||||
channel: this.options_.channel,
|
||||
}
|
||||
|
||||
if (cart.customer_id) {
|
||||
request.shopperReference = cart.customer_id
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.adyenCheckoutApi.post("/paymentMethods", request)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Status for Adyen payment.
|
||||
* @param {Object} paymentData - payment method data from cart
|
||||
* @returns {string} the status of the payment
|
||||
*/
|
||||
async getStatus(_) {
|
||||
let status = "initial"
|
||||
return status
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Adyen payment object.
|
||||
* @param {any} _ - placeholder object
|
||||
* @returns {Object} empty payment data
|
||||
*/
|
||||
async createPayment(_) {
|
||||
return {}
|
||||
}
|
||||
|
||||
async retrievePayment(data) {
|
||||
return data
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and authorizes an Ayden payment
|
||||
* @returns {Object} payment data result
|
||||
*/
|
||||
async authorizePayment(cart, paymentMethod) {
|
||||
const region = await this.regionService_.retrieve(cart.region_id)
|
||||
const total = await this.totalsService_.getTotal(cart)
|
||||
|
||||
let request = {
|
||||
amount: {
|
||||
currency: region.currency_code,
|
||||
value: total * 100,
|
||||
},
|
||||
shopperReference: cart.customer_id,
|
||||
paymentMethod,
|
||||
reference: cart._id,
|
||||
merchantAccount: this.options_.merchant_account,
|
||||
returnUrl: this.options_.return_url,
|
||||
metadata: {
|
||||
cart_id: cart._id,
|
||||
},
|
||||
}
|
||||
|
||||
if (paymentMethod.storedPaymentMethodId) {
|
||||
request.shopperInteraction = "Ecommerce"
|
||||
request.recurringProcessingModel = "CardOnFile"
|
||||
}
|
||||
|
||||
return await this.adyenCheckoutApi.post("/payments", request)
|
||||
}
|
||||
|
||||
async checkPaymentResult(paymentData, payload) {
|
||||
const request = {
|
||||
paymentData,
|
||||
details: {
|
||||
payload,
|
||||
},
|
||||
}
|
||||
return this.adyenCheckoutApi.post("/payments/details", request)
|
||||
}
|
||||
|
||||
/**
|
||||
* Captures an Ayden payment
|
||||
* @param {Object} data - payment data to capture
|
||||
* @returns {Object} payment data result of capture
|
||||
*/
|
||||
async capturePayment(data) {
|
||||
const { pspReference, amount } = data
|
||||
|
||||
try {
|
||||
return this.adyenPaymentApi.post("/capture", {
|
||||
originalReference: pspReference,
|
||||
modificationAmount: amount,
|
||||
merchantAccount: this.options_.merchant_account,
|
||||
})
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refunds an Ayden payment
|
||||
* @param {Object} paymentData - payment data to refund
|
||||
* @param {number} amountToRefund - amount to refund
|
||||
* @returns {Object} payment data result of refund
|
||||
*/
|
||||
async refundPayment(data) {
|
||||
const { pspReference, amount } = data
|
||||
|
||||
try {
|
||||
return this.adyenPaymentApi.post("/capture", {
|
||||
originalReference: pspReference,
|
||||
merchantAccount: this.options_.merchant_account,
|
||||
modificationAmount: amount,
|
||||
})
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels an Ayden payment
|
||||
* @param {Object} paymentData - payment data to cancel
|
||||
* @returns {Object} payment data result of cancel
|
||||
*/
|
||||
async cancelPayment(paymentData) {
|
||||
const { pspReference } = paymentData
|
||||
|
||||
try {
|
||||
return this.adyenPaymentApi.post("/capture", {
|
||||
originalReference: pspReference,
|
||||
merchantAccount: this.options_.merchant_account,
|
||||
})
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default AdyenService
|
||||
@@ -0,0 +1,74 @@
|
||||
import _ from "lodash"
|
||||
import { PaymentService } from "medusa-interfaces"
|
||||
|
||||
class ApplePayAdyenService extends PaymentService {
|
||||
static identifier = "applepayAdyen"
|
||||
|
||||
constructor({ adyenService }) {
|
||||
super()
|
||||
|
||||
this.adyenService_ = adyenService
|
||||
}
|
||||
|
||||
/**
|
||||
* Status for Adyen payment.
|
||||
* @param {Object} paymentData - payment method data from cart
|
||||
* @returns {string} the status of the payment
|
||||
*/
|
||||
async getStatus(paymentData) {
|
||||
const { resultCode } = paymentData
|
||||
let status = "initial"
|
||||
|
||||
if (resultCode === "Authorised") {
|
||||
status = "authorized"
|
||||
}
|
||||
|
||||
return status
|
||||
}
|
||||
|
||||
async createPayment(_) {
|
||||
return {}
|
||||
}
|
||||
|
||||
async authorizePayment(cart, paymentMethod) {
|
||||
return this.adyenService_.authorizePayment(cart, paymentMethod)
|
||||
}
|
||||
|
||||
async retrievePayment(data) {
|
||||
return this.adyenService_.retrievePayment(data)
|
||||
}
|
||||
|
||||
async updatePayment(data, _) {
|
||||
return this.adyenService_.updatePayment(data)
|
||||
}
|
||||
|
||||
async deletePayment(data) {
|
||||
return this.adyenService_.deletePayment(data)
|
||||
}
|
||||
|
||||
async capturePayment(data) {
|
||||
try {
|
||||
return this.adyenService_.capturePayment(data)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async refundPayment(data) {
|
||||
try {
|
||||
return this.adyenService_.refundPayment(data)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async cancelPayment(data) {
|
||||
try {
|
||||
return this.adyenService_.cancelPayment(data)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default ApplePayAdyenService
|
||||
@@ -0,0 +1,74 @@
|
||||
import _ from "lodash"
|
||||
import { PaymentService } from "medusa-interfaces"
|
||||
|
||||
class CardAdyenService extends PaymentService {
|
||||
static identifier = "schemeAdyen"
|
||||
|
||||
constructor({ adyenService }) {
|
||||
super()
|
||||
|
||||
this.adyenService_ = adyenService
|
||||
}
|
||||
|
||||
/**
|
||||
* Status for Adyen payment.
|
||||
* @param {Object} paymentData - payment method data from cart
|
||||
* @returns {string} the status of the payment
|
||||
*/
|
||||
async getStatus(paymentData) {
|
||||
const { resultCode } = paymentData
|
||||
let status = "initial"
|
||||
|
||||
if (resultCode === "Authorised") {
|
||||
status = "authorized"
|
||||
}
|
||||
|
||||
return status
|
||||
}
|
||||
|
||||
async createPayment(_) {
|
||||
return {}
|
||||
}
|
||||
|
||||
async authorizePayment(cart, paymentMethod) {
|
||||
return this.adyenService_.authorizePayment(cart, paymentMethod)
|
||||
}
|
||||
|
||||
async retrievePayment(data) {
|
||||
return this.adyenService_.retrievePayment(data)
|
||||
}
|
||||
|
||||
async updatePayment(data, _) {
|
||||
return this.adyenService_.updatePayment(data)
|
||||
}
|
||||
|
||||
async deletePayment(data) {
|
||||
return this.adyenService_.deletePayment(data)
|
||||
}
|
||||
|
||||
async capturePayment(data) {
|
||||
try {
|
||||
return this.adyenService_.capturePayment(data)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async refundPayment(data) {
|
||||
try {
|
||||
return this.adyenService_.refundPayment(data)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async cancelPayment(data) {
|
||||
try {
|
||||
return this.adyenService_.cancelPayment(data)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default CardAdyenService
|
||||
@@ -0,0 +1,74 @@
|
||||
import _ from "lodash"
|
||||
import { PaymentService } from "medusa-interfaces"
|
||||
|
||||
class GooglePayAdyenService extends PaymentService {
|
||||
static identifier = "googlepayAdyen"
|
||||
|
||||
constructor({ adyenService }) {
|
||||
super()
|
||||
|
||||
this.adyenService_ = adyenService
|
||||
}
|
||||
|
||||
/**
|
||||
* Status for Adyen payment.
|
||||
* @param {Object} paymentData - payment method data from cart
|
||||
* @returns {string} the status of the payment
|
||||
*/
|
||||
async getStatus(paymentData) {
|
||||
const { resultCode } = paymentData
|
||||
let status = "initial"
|
||||
|
||||
if (resultCode === "Authorised") {
|
||||
status = "authorized"
|
||||
}
|
||||
|
||||
return status
|
||||
}
|
||||
|
||||
async createPayment(_) {
|
||||
return {}
|
||||
}
|
||||
|
||||
async authorizePayment(cart, paymentMethod) {
|
||||
return this.adyenService_.authorizePayment(cart, paymentMethod)
|
||||
}
|
||||
|
||||
async retrievePayment(data) {
|
||||
return this.adyenService_.retrievePayment(data)
|
||||
}
|
||||
|
||||
async updatePayment(data, _) {
|
||||
return this.adyenService_.updatePayment(data)
|
||||
}
|
||||
|
||||
async deletePayment(data) {
|
||||
return this.adyenService_.deletePayment(data)
|
||||
}
|
||||
|
||||
async capturePayment(data) {
|
||||
try {
|
||||
return this.adyenService_.capturePayment(data)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async refundPayment(data) {
|
||||
try {
|
||||
return this.adyenService_.refundPayment(data)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async cancelPayment(data) {
|
||||
try {
|
||||
return this.adyenService_.cancelPayment(data)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default GooglePayAdyenService
|
||||
@@ -0,0 +1,74 @@
|
||||
import _ from "lodash"
|
||||
import { PaymentService } from "medusa-interfaces"
|
||||
|
||||
class IdealAdyenService extends PaymentService {
|
||||
static identifier = "idealAdyen"
|
||||
|
||||
constructor({ adyenService }) {
|
||||
super()
|
||||
|
||||
this.adyenService_ = adyenService
|
||||
}
|
||||
|
||||
/**
|
||||
* Status for Adyen payment.
|
||||
* @param {Object} paymentData - payment method data from cart
|
||||
* @returns {string} the status of the payment
|
||||
*/
|
||||
async getStatus(paymentData) {
|
||||
const { resultCode } = paymentData
|
||||
let status = "initial"
|
||||
|
||||
if (resultCode === "Authorised") {
|
||||
status = "authorized"
|
||||
}
|
||||
|
||||
return status
|
||||
}
|
||||
|
||||
async createPayment(_) {
|
||||
return {}
|
||||
}
|
||||
|
||||
async authorizePayment(cart, paymentMethod) {
|
||||
return this.adyenService_.authorizePayment(cart, paymentMethod)
|
||||
}
|
||||
|
||||
async retrievePayment(data) {
|
||||
return this.adyenService_.retrievePayment(data)
|
||||
}
|
||||
|
||||
async updatePayment(data, _) {
|
||||
return this.adyenService_.updatePayment(data)
|
||||
}
|
||||
|
||||
async deletePayment(data) {
|
||||
return this.adyenService_.deletePayment(data)
|
||||
}
|
||||
|
||||
async capturePayment(data) {
|
||||
try {
|
||||
return this.adyenService_.capturePayment(data)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async refundPayment(data) {
|
||||
try {
|
||||
return this.adyenService_.refundPayment(data)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async cancelPayment(data) {
|
||||
try {
|
||||
return this.adyenService_.cancelPayment(data)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default IdealAdyenService
|
||||
@@ -0,0 +1,74 @@
|
||||
import _ from "lodash"
|
||||
import { PaymentService } from "medusa-interfaces"
|
||||
|
||||
class MobilePayAdyenService extends PaymentService {
|
||||
static identifier = "mobilepayAdyen"
|
||||
|
||||
constructor({ adyenService }) {
|
||||
super()
|
||||
|
||||
this.adyenService_ = adyenService
|
||||
}
|
||||
|
||||
/**
|
||||
* Status for Adyen payment.
|
||||
* @param {Object} paymentData - payment method data from cart
|
||||
* @returns {string} the status of the payment
|
||||
*/
|
||||
async getStatus(paymentData) {
|
||||
const { resultCode } = paymentData
|
||||
let status = "initial"
|
||||
|
||||
if (resultCode === "Authorised") {
|
||||
status = "authorized"
|
||||
}
|
||||
|
||||
return status
|
||||
}
|
||||
|
||||
async createPayment(_) {
|
||||
return {}
|
||||
}
|
||||
|
||||
async authorizePayment(cart, paymentMethod) {
|
||||
return this.adyenService_.authorizePayment(cart, paymentMethod)
|
||||
}
|
||||
|
||||
async retrievePayment(data) {
|
||||
return this.adyenService_.retrievePayment(data)
|
||||
}
|
||||
|
||||
async updatePayment(data, _) {
|
||||
return this.adyenService_.updatePayment(data)
|
||||
}
|
||||
|
||||
async deletePayment(data) {
|
||||
return this.adyenService_.deletePayment(data)
|
||||
}
|
||||
|
||||
async capturePayment(data) {
|
||||
try {
|
||||
return this.adyenService_.capturePayment(data)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async refundPayment(data) {
|
||||
try {
|
||||
return this.adyenService_.refundPayment(data)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async cancelPayment(data) {
|
||||
try {
|
||||
return this.adyenService_.cancelPayment(data)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default MobilePayAdyenService
|
||||
@@ -0,0 +1,74 @@
|
||||
import _ from "lodash"
|
||||
import { PaymentService } from "medusa-interfaces"
|
||||
|
||||
class PayPalAdyenService extends PaymentService {
|
||||
static identifier = "paypalAdyen"
|
||||
|
||||
constructor({ adyenService }) {
|
||||
super()
|
||||
|
||||
this.adyenService_ = adyenService
|
||||
}
|
||||
|
||||
/**
|
||||
* Status for Adyen payment.
|
||||
* @param {Object} paymentData - payment method data from cart
|
||||
* @returns {string} the status of the payment
|
||||
*/
|
||||
async getStatus(paymentData) {
|
||||
const { resultCode } = paymentData
|
||||
let status = "initial"
|
||||
|
||||
if (resultCode === "Authorised") {
|
||||
status = "authorized"
|
||||
}
|
||||
|
||||
return status
|
||||
}
|
||||
|
||||
async createPayment(_) {
|
||||
return {}
|
||||
}
|
||||
|
||||
async authorizePayment(cart, paymentMethod) {
|
||||
return this.adyenService_.authorizePayment(cart, paymentMethod)
|
||||
}
|
||||
|
||||
async retrievePayment(data) {
|
||||
return this.adyenService_.retrievePayment(data)
|
||||
}
|
||||
|
||||
async updatePayment(data, _) {
|
||||
return this.adyenService_.updatePayment(data)
|
||||
}
|
||||
|
||||
async deletePayment(data) {
|
||||
return this.adyenService_.deletePayment(data)
|
||||
}
|
||||
|
||||
async capturePayment(data) {
|
||||
try {
|
||||
return this.adyenService_.capturePayment(data)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async refundPayment(data) {
|
||||
try {
|
||||
return this.adyenService_.refundPayment(data)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
async cancelPayment(data) {
|
||||
try {
|
||||
return this.adyenService_.cancelPayment(data)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default PayPalAdyenService
|
||||
Reference in new issue
Block a user