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.

ParameterRequired/OptionalDetermine

cartId

Required

The Salesforce ID for the cart object.

amount

Required

The amount specified by the shopper to use for the customer credit source.

paymentName

Optional

You can pass the paymentName if you want to provide a different label (for example, GiftCard123) for the payment on the payment detail component. The paymentName appears in the Display Name field for a DR_Transaction_Payment__c object.

If this parameter is not provided, the label "CustomerCredit" will be used by default.

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

Receiving a response

You'll see the following parameters in the response.

ParameterDescription

isSuccess

This global method returns a Boolean value where:

  • true–indicates the source was successfully created and applied to checkout.

  • false–indicates an error occurred while creating or attaching the source to checkout. The system returns an error message when an error occurs, and the Boolean value is false.

errorMessage

If the system returns an error and the value for isSuccess is false, this parameter displays one of the following error messages:

  • Missing or invalid input parameters specified: One of the input parameters are missing or invalid.

  • Invalid amount specified: The value specified for the amount is invalid.

  • DR API error: An error message that comes from the Digital River API.

sourceId

The unique identifier of the customer credit source.

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