Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix updating of the remote CIM after a processor change. #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions service/AuthorizeDotNet/CimServices.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@ along with this software (see the LICENSE.md file). If not, see
<!-- correct masking if needed, use only 'X' -->
<set field="cardNumber" from="creditCard.cardNumber?.replaceAll(/\D/, 'X')"/>
<if condition="paymentMethod.gatewayCimId"><then>
<!-- current paymentMethod has a gatewayCimId -->
<set field="foundGatewayCimId" from="paymentMethod.gatewayCimId"/>
</then><else>
<log message="store#CustomerPaymentMethod -> looking up previous paymentMethods for party ${paymentMethod.ownerPartyId}"/>
<!-- current paymentMethod was not stored with CIM, but perhaps a previous one was -->
<entity-find entity-name="mantle.account.method.PaymentMethod" list="partyPaymentMethodsWithCim">
<econdition field-name="ownerPartyId" from="paymentMethod.ownerPartyId"/>
<econdition field-name="paymentGatewayConfigId" from="paymentGatewayConfigId"/>
<econdition field-name="gatewayCimId" operator="is-not-null"/>
<order-by field-name="-from-date"/>
</entity-find>
<if condition="!partyPaymentMethodsWithCim.isEmpty()">
<!-- found previous paymentMethods for this gateway, use the most recent gatewayCimId -->
<set field="foundGatewayCimId" from="partyPaymentMethodsWithCim[0].gatewayCimId"/>
</if>
</else></if>

<if condition="foundGatewayCimId"><then>
<!-- have a payment profile, call updateCustomerPaymentProfileRequest -->
<script><![CDATA[requestString = """<?xml version="1.0" encoding="utf-8"?>
<updateCustomerPaymentProfileRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
Expand All @@ -107,7 +125,7 @@ along with this software (see the LICENSE.md file). If not, see
</billTo>
<payment><creditCard><cardNumber>${cardNumber}</cardNumber><expirationDate>${expireDateFormatted}</expirationDate>
${validateSecurityCode || creditCard.cardSecurityCode ? ('<cardCode>' + (validateSecurityCode ?: creditCard.cardSecurityCode) + '</cardCode>') : ''}</creditCard></payment>
<customerPaymentProfileId>${paymentMethod.gatewayCimId}</customerPaymentProfileId>
<customerPaymentProfileId>${foundGatewayCimId}</customerPaymentProfileId>
</paymentProfile>
<validationMode>${pgan.validationMode}</validationMode>
</updateCustomerPaymentProfileRequest>
Expand Down Expand Up @@ -203,8 +221,13 @@ along with this software (see the LICENSE.md file). If not, see

<!-- set the gatewayCimId values for Party and PaymentMethod as needed -->
<if condition="paymentMethod.gatewayCimId"><then>
<!-- have a payment profile, called updateCustomerPaymentProfileRequest, no need to do anything -->
</then><else-if condition="party.gatewayCimId">
<!-- current paymentMethod has a profile, no need to do anything -->
</then><else-if condition="foundGatewayCimId">
<!-- Updating a previous profile, attach to the current paymentMethod -->
<set field="paymentMethod.gatewayCimId" from="foundGatewayCimId"/>
<set field="paymentMethod.paymentGatewayConfigId" from="paymentGatewayConfigId"/>
<entity-update value-field="paymentMethod"/>
</else-if><else-if condition="party.gatewayCimId">
<!-- no payment profile but we have a customer profile, called createCustomerPaymentProfileRequest -->
<set field="paymentMethod.gatewayCimId" from="responseNode.customerPaymentProfileId.text()"/>
<set field="paymentMethod.paymentGatewayConfigId" from="paymentGatewayConfigId"/>
Expand Down