addCustomerCreditSourceToCheckout

Learn how to add a Customer Credit source to checkout.

Use this global method to create a customer credit payment source and attach it to checkout.

The payment session identifier and currency code will be derived from the cart if multicurrency is enabled in org. Otherwise, the currency code will be derived from the user’s default currency.

Before creating a payment source, use this method to verify that the amount specified by the shopper is less than or equal to the amountRemainingToBeContributed. If the amount passed into the method is greater than amountRemainingToBeContributed, it will throw an error.

This global method will set the amountContributed and amountRemainingToBeContributed values in the Cart object.

Sending a request

This method accepts parameters in JSON string format and can be called outside the managed package. You need to pass the cartId and the amount applied to this method.

Request body example
“{
                 "cartId":CartId, 
                 "paymentName": "GiftCard123",
                 "amount”: "50", 
}”

Receiving a response

You'll see the following parameters in the response.

Response body example
{
    "isSuccess":{{boolean_value}},
    "errorMessage": {{error_msg}}, //in case of error
    "sourceId":{{sourceId}}   //in case of success
}

Calling the global method from a custom component

Import the addCustomerChreditSourceToCheckout method into your custom component javascript file with digialriverv3 as the namespace as shown below.

Import example
import addCustomerCreditSourceToCheckout from 
"@salesforce/apex/digitalriverv3.DRB2B_CustomerCreditService.addCustomerCreditSourceToCheckout";

Call the global method from a custom JavaScript file by passing the cartId, amount, and (optionally) paymentName arguments as shown below.

handleAddCustomerCredit(event){
        addCustomerCreditSourceToCheckout({
            inputData : JSON.stringify({
                cartId : this.webcartId,//cart Id
                amount: amount 
            })
          }).then((result) => {
               // implement logic here in case of success
            })
            .catch((error) => {
               // implement logic here in case of error
            });
    }

Last updated