Home / Admin / Payment Method Smart Tag
Duplicate Snippet

Embed Snippet on Your Site

Payment Method Smart Tag

This code only has handling for klarna, us_bank_account and card (default). The other available types are listed here: https://docs.stripe.com/api/payment_methods/object#payment_method_object-type

Code Preview
php
<?php
add_filter(
	'simpay_payment_details_template_tags',
	function( $tags ) {
		$tags[] = 'payment-method';
		
		return $tags;
	}
);
	
add_filter(
	'simpay_payment_confirmation_template_tag_payment-method',
	function( $value, $payment_confirmation_data ) {
		$charges = \SimplePay\Core\API\Charges\all(
			array(
				'customer' => $payment_confirmation_data['customer']->id,
				'limit' => 1,
			),
			$payment_confirmation_data['form']->get_api_request_args()
		);
		$charge = end( $charges->data );
		$payment_method_details = $charge->payment_method_details;
		return match ($payment_method_details->type) {
			'us_bank_account' => 'Bank Account',
			'klarna' => 'Klarna',
			default => 'Credit Card',
		};
	},
	99,
	2
);

Comments

Add a Comment