External payment method (EPM)

External payment method (EPM)

As Klarna Checkout transitions to Kustom Checkout, please note that parts of this documentation are still being updated. You may come across references to Klarna, outdated screenshots, or broken links.

We’re working continuously to revise all content, and we appreciate your patience during this process.

External payment methods can be configured for use with the Woo KCO plugin. External payment methods and checkouts allow merchants to offer payment methods not available today as an inline experience with Kustom Checkout.

Note: the use of EPM’s is also dependent upon the merchant’s Kustom contract.

Important:

External Payment Methods needs to be activated by Kustom in the merchants account before trying the example code.

This code may be used in a production store, but this code is not supported by Kustom or Krokedil.


Example code BACS


/**
 * Extend the Kustom Checkout plugin settings.
 */
add_filter( 'kco_wc_gateway_settings', 'kcoepm_form_fields' );
function kcoepm_form_fields( $settings ) {
	$settings['epm_bacs_settings_title'] = array(
		'title' => __( 'External Payment Method - Direct Bank Transfer', 'kco-epm-wc' ),
		'type'  => 'title',
	);
	$settings['epm_bacs_name']           = array(
		'title'       => __( 'Payment method name*', 'kco-epm-wc' ),
		'type'        => 'text',
		// https://docs.klarna.com/kustom-checkout/in-depth-knowledge/external-payment-methods/#external-payment-methods-in-kustom-checkout-supported-external-payment-methods-in-kco
		'description' => __( 'The name of the payment method exactly as it appears in the Klarna documentation. <b>This field is mandatory</b>.', 'kco-epm-wc' ),
		'default'     => __( 'Bank Transfer', 'kco-epm-wc' ),
	);
	$settings['epm_bacs_id']             = array(
		'title'       => __( 'Payment method ID*', 'kco-epm-wc' ),
		'type'        => 'text',
		'description' => __( 'The ID of the relevant WooCommerce payment method. For example, for "Direct bank transfer", the ID is "bacs". <b>This field is mandatory</b>.', 'kco-epm-wc' ),
		'default'     => __( 'bacs', 'kco-epm-wc' ),
	);
	$settings['epm_bacs_description']    = array(
		'title'       => __( 'Description', 'kco-epm-wc' ),
		'type'        => 'textarea',
		'description' => __( 'Add a description under the payment method. If omitted, Klarna will use a default description.', 'kco-epm-wc' ),
		'default'     => '',
	);
	$settings['epm_bacs_img_url']        = array(
		'title'       => __( 'Image URL', 'kco-epm-wc' ),
		'type'        => 'text',
		'description' => __( 'A URL to the payment icon (optional).', 'kco-epm-wc' ),
		'default'     => '',
	);
	$settings['epm_bacs_disable_button'] = array(
		'title'       => __( 'Disable other gateway button', 'kco-epm-wc' ),
		'type'        => 'checkbox',
		'description' => __( 'Whether the "Select another Payment method" button on the Kustom Checkout should be disabled.', 'kco-epm-wc' ),
		'default'     => 'no',
	);

	return $settings;
}

/**
 * Add Direct Transfer as payment method to the KCO iframe.
 */
add_filter( 'kco_wc_api_request_args', 'kcoepm_create_order_bacs' );
function kcoepm_create_order_bacs( $request_args ) {
	$kco_settings = get_option( 'woocommerce_kco_settings' );
	$name         = $kco_settings['epm_bacs_name'] ?? '';
	$id           = $kco_settings['epm_bacs_id'] ?? '';
	$image_url    = $kco_settings['epm_bacs_img_url'] ?? '';
	$description  = $kco_settings['epm_bacs_description'] ?? '';

	$klarna_external_payment = array(
		// The name is MANDATORY and must match exactly one of the payment method names as they appear in the Klarna documentation:
		// https://docs.klarna.com/kustom-checkout/in-depth-knowledge/external-payment-methods/#external-payment-methods-in-kustom-checkout-supported-external-payment-methods-in-kco.
		'name'         => $name,
		'image_url'    => $image_url,
		'description'  => $description,
		'redirect_url' => add_query_arg(
			array(
				'kco-external-payment' => $id,
				'order_id'             => isset( $request_args['merchant_reference2'] ) ? $request_args['merchant_reference2'] : '{checkout.order.id}',
			),
			wc_get_checkout_url()
		),
	);

	$klarna_external_payment                  = array( $klarna_external_payment );
	$request_args['external_payment_methods'] = $klarna_external_payment;

	return $request_args;
}


add_action( 'init', 'kcoepm_remove_other_gateway_button' );
function kcoepm_remove_other_gateway_button() {
	$kco_settings   = get_option( 'woocommerce_kco_settings' );
	$disable_button = isset( $kco_settings['epm_bacs_disable_button'] ) ? $kco_settings['epm_bacs_disable_button'] : 'no';
	if ( 'yes' === $disable_button ) {
		remove_action( 'kco_wc_after_order_review', 'kco_wc_show_another_gateway_button', 20 );
	}
}

FAQ


Is it possible to add multiple External Payment Methods to Kustom?

Yes, it is possible to add multiple External Payment Methods to Kustom (provided that you have an agreement with Klarna for this).

Each defined external payment method sent in the request to Kustom should be added as an array as described in the documentation here: https://docs.klarna.com/api/checkout/#operation/createOrderMerchant!path=external_payment_methods&t=request.