Processing multiple shipments with a single approval

You can process multiple shipments at a time with a single authorization approval by customizing the PaymentEventListenerImpl class. Without customization, the PaymentEventListenerImpl class uses the default payment rules and processes multiple transactions for multiple shipments.

Procedure

  1. Override the finalization amount and reservation amount in the PaymentEventListenerImpl class. Update the updateAtomicPaymentAfterHashActions() method to correct the final amount of the order.
    Use the example to override the updateAtomicPaymentAfterHashActions() method:
    
    protected void updateAtomicPaymentAfterHashActions(HashMap actionLists, int phase) 
      throws InvalidRequestException, InvalidDataException, ObjectCannotBeFoundException, EDPException {
        PaymentActionData actionData = null;
        List actions = null;
        int numberOfActions = 0;
        Iterator iter = actionLists.keySet().iterator();
        while (iter.hasNext()) {
          Long piId = (Long) iter.next();
          actions = (List) actionLists.get(piId);
          numberOfActions = actions.size();
          
          // Loop through the array of Action objects
          for (int j = 0; j < numberOfActions; j++) {
            actionData = (PaymentActionData) actions.get(j);
            
            if(actionData.getActionName().equals("DepositAction"))
            {
              Long apKeyId = actionData.getAtomicPaymentId();
              AtomicPaymentData payment = getOMF().getAtomicPayment(apKeyId);
              if(phase == Constants.PHASE_FINALIZATION)
              {
                BigDecimal amount = actionData.getAmount().add(payment.getFinalizationAmount());
                actionData.setAmount(amount);
              }
              if(phase == Constants.PHASE_RESERVATION)
              {
                BigDecimal amount = actionData.getAmount().add(payment.getReservationAmount());
                actionData.setAmount(amount);
              }
            }
          }
        }
        super.updateAtomicPaymentAfterHashActions(actionLists, phase);
      } 
  2. Update the wc-server.xml file to use the updated version of PaymentEventListenerImpl class.
    1. In the wc-server.xml, update the compClassName.
      For example:
      <component
      compClassName="com.ibm.commerce.payment.actions.commands.PaymentEventListenerImpl"
        enable="true" name="Payment Rule Listener">
        <property display="false">
          <start enabled="true"/>
          <event name="PaymentRule"/>
        </property>
      </component>
  3. Set the target in the CorePaymentActions.xml file.
    1. Go to WC_installdir/xml/config/payments/edp/groups/group_name/paymentConfiguration.
    2. Set the target for deposit in the CorePaymentActions.xml file:
    <TargetDeposited>
    ...
    <CurrentApproved>
      <AmountLessThanRequested>
        <Action name="Deposit" amount="existing" target="existing"/>
        <Action name="Approve" amount="delta" target="additional"/>
        <Action name="Deposit" amount="delta" target="existing"/>
      </AmountLessThanRequested>
      <AmountEqualsRequested>
        <Action name="Deposit" amount="existing" target="existing"/>
      </AmountEqualsRequested>
      <AmountGreaterThanRequested>
        <Action name="Deposit" amount="requested" target="existing"/>
      </AmountGreaterThanRequested>
    </CurrentApproved>
    ...
    </TargetDeposited>