Payment methods example scripts

This guide provides a series of example scripts that implement the payment methods API.

Filter payment methods based on configuration

This script filters payment methods when both of the following conditions are met:

  • The payment method name matches the paymentMethodName field from the configuration, or Unknown if the field wasn't set in the configuration.
  • The total price of the checkout (purchase proposal) is greater than the threshold field from the configuration in CAD, or $100.00 CAD if the field wasn't set in the configuration.

Rename first payment method

This script renames the first payment method to Renamed Payment Method! if there are one or more payment methods.

Rename payment method based on configuration

This script renames any payment method with a name equal to the nameToMatch field from the configuration to the name specified in the renameTo field from the configuration.

Sort payment methods

This script sorts payment methods by name.

  • If no configuration is provided, then payment methods are sorted in ascending order.
  • If the sortDirection field of the configuration is set to ascending, then payment methods are sorted in ascending order.
  • If the sortDirection field of the configuration is set to descending, then payment methods are sorted in descending order.
  • If the sortDirection field of the configuration is set to anything else, then the script raises an error.

Next steps