Skip to content

Commit b2c883e

Browse files
committed
When AuthorizedNet CIM is enabled, and a user has stored a CreditCard
previously, but then due to having to switch to the ALWAYS_APPROVE processor, if the user happens to create a new CreditCard, and then the processor is switched back, then make certain to call "update" instead of "create". This can occur when the bank and authorize.net have disconnected their settings, and they are taking time to reconnect the money end of things.
1 parent 75d38a5 commit b2c883e

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

service/AuthorizeDotNet/CimServices.xml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,24 @@ along with this software (see the LICENSE.md file). If not, see
8989
<set field="expireDateFormatted" value="${expireYear}-${expireMonth}"/>
9090
<!-- correct masking if needed, use only 'X' -->
9191
<set field="cardNumber" from="creditCard.cardNumber?.replaceAll(/\D/, 'X')"/>
92-
<if condition="paymentMethod.gatewayCimId"><then>
92+
<!-- current paymentMethod has a gatewayCimId -->
93+
<set field="foundGatewayCimId" from="paymentMethod.gatewayCimId"/>
94+
</then><else>
95+
<log message="store#CustomerPaymentMethod -> looking up previous paymentMethods for party ${paymentMethod.ownerPartyId}"/>
96+
<!-- current paymentMethod was not stored with CIM, but perhaps a previous one was -->
97+
<entity-find entity-name="mantle.account.method.PaymentMethod" list="partyPaymentMethodsWithCim">
98+
<econdition field-name="ownerPartyId" from="paymentMethod.ownerPartyId"/>
99+
<econdition field-name="paymentGatewayConfigId" from="paymentGatewayConfigId"/>
100+
<econdition field-name="gatewayCimId" operator="is-not-null"/>
101+
<order-by field-name="-from-date"/>
102+
</entity-find>
103+
<if condition="!partyPaymentMethodsWithCim.isEmpty()">
104+
<!-- found previous paymentMethods for this gateway, use the most recent gatewayCimId -->
105+
<set field="foundGatewayCimId" from="partyPaymentMethodsWithCim[0].gatewayCimId"/>
106+
</if>
107+
</else></if>
108+
109+
<if condition="foundGatewayCimId"><then>
93110
<!-- have a payment profile, call updateCustomerPaymentProfileRequest -->
94111
<script><![CDATA[requestString = """<?xml version="1.0" encoding="utf-8"?>
95112
<updateCustomerPaymentProfileRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
@@ -107,7 +124,7 @@ along with this software (see the LICENSE.md file). If not, see
107124
</billTo>
108125
<payment><creditCard><cardNumber>${cardNumber}</cardNumber><expirationDate>${expireDateFormatted}</expirationDate>
109126
${validateSecurityCode || creditCard.cardSecurityCode ? ('<cardCode>' + (validateSecurityCode ?: creditCard.cardSecurityCode) + '</cardCode>') : ''}</creditCard></payment>
110-
<customerPaymentProfileId>${paymentMethod.gatewayCimId}</customerPaymentProfileId>
127+
<customerPaymentProfileId>${foundGatewayCimId}</customerPaymentProfileId>
111128
</paymentProfile>
112129
<validationMode>${pgan.validationMode}</validationMode>
113130
</updateCustomerPaymentProfileRequest>

0 commit comments

Comments
 (0)