Skip to content

Commit

Permalink
Set payment key to merchant reference
Browse files Browse the repository at this point in the history
CS-5553
  • Loading branch information
Tamara committed Jul 4, 2024
1 parent 2768ac6 commit 9169de8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 11 deletions.
1 change: 0 additions & 1 deletion extension/src/paymentHandler/make-payment.handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ async function execute(paymentObject) {
const updatePaymentAction = getPaymentKeyUpdateAction(
paymentObject.key,
request,
response,
)
if (updatePaymentAction) actions.push(updatePaymentAction)

Expand Down
12 changes: 3 additions & 9 deletions extension/src/paymentHandler/payment-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import c from '../config/constants.js'
import config from '../config/config.js'

const { getAdyenPaymentMethodsToNames } = config
const unsuccessfulResponseCodes = [400, 401, 403, 422, 500]

function getAuthorizationTransactionSuccess(paymentObject) {
return getTransactionWithTypesAndStates(
Expand Down Expand Up @@ -198,19 +197,14 @@ function getIdempotencyKey(transaction) {
return idempotencyKey
}

function getPaymentKeyUpdateAction(paymentKey, request, response) {
function getPaymentKeyUpdateAction(paymentKey, request) {
const requestBodyJson = JSON.parse(request.body)
const reference = requestBodyJson.reference?.toString()
let newReference = reference
if (!unsuccessfulResponseCodes.includes(response.status)) {
const pspReference = response.pspReference?.toString()
newReference = pspReference || reference
}
let newReference = requestBodyJson.reference?.toString()

let paymentKeyUpdateAction
// ensure the key and new reference is different, otherwise the error with
// "code": "InvalidOperation", "message": "'key' has no changes." will return by commercetools API.
if (newReference !== paymentKey) {
if (newReference && newReference !== paymentKey) {
paymentKeyUpdateAction = {
action: 'setKey',
key: newReference,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ async function execute(paymentObject) {
const updatePaymentAction = getPaymentKeyUpdateAction(
paymentObject.key,
request,
response,
)
if (updatePaymentAction) actions.push(updatePaymentAction)
}
Expand Down

0 comments on commit 9169de8

Please sign in to comment.