Payment Service Provider

For the Payment Service Provider (PSP) integration to work properly in Customer Service Center, Shop API interactions require code to connect Customer Service Center with the B2C Commerce PSP cartridge. To add or update a payment method after each event in Customer Service Center, “dw.order.hooks.PaymentHooks” is called within an encapsulated transaction.

To register a payment hook, complete the following registration.

{
    "hooks": [    
        {"name": "dw.order.payment.authorize", "script": "./authorize.js"}, 
        {"name": "dw.order.payment.authorizeCreditCard", "script": "./authorize.js"}
    ]
}    

Example

To initiate the authorize logic in the PSP cartridge, include the code in authorize.js.
importPackage( dw.system );
importPackage( dw.order );
importPackage( dw.value );
importPackage(dw.util);


function authorize(order : Order, paymentDetails : OrderPaymentInstrument)
{
    //link your payment cartridge here...
    Logger.info("auth for order {0}", order.orderNo);
    var gcCode : String = paymentDetails.getGiftCertificateCode();
    Logger.info("GC Code {0}", paymentDetails.getGiftCertificateCode());
    
    if(gcCode == 'bad'){
        return new Status( Status.ERROR, "ERR_BAD", "The Gift Certificate {0} could not authorized successfully.", gcCode);  
    }
    
    return new Status( Status.OK );  
}

function authorizeCreditCard(order : Order, paymentDetails : OrderPaymentInstrument, cvn : String)
{
    //link your payment cartridge here...
    var ccno : String = paymentDetails.getCreditCardNumber();
    Logger.info("CC payment auth for order {0} - {1}", order.orderNo, "************" + ccno.substr(12));
    
    if(ccno == '4111111111112222'){
        
        Logger.info("=====================================ERROR===========================================");
        return new Status( Status.ERROR, "ERR_2222", "Creditcard ending with {0} could not be authorized. Error code: {1}.", ccno.substr(12), "ERR_2222" );  
    }
    
    return new Status( Status.OK );  
}

module.exports = {
    authorize : authorize,
       authorizeCreditCard : authorizeCreditCard
};

Related Links

Customer Service Center

Customer Service Center Customization

Customer Service Center Hooks