| @@ -18,8 +18,42 @@ | ||
| 18 | 18 | * Shared helper for the POS payment-gateway contract. |
| 19 | 19 | */ |
| 20 | 20 | class Gateway_Contract { |
| 21 | 21 | /** |
| 22 | + * Human-readable gateway name for POS and settings display. | |
| 23 | + * | |
| 24 | + * Falls back from the public title to the admin method title to the id, | |
| 25 | + * because some gateways never assign a public title. | |
| 26 | + * | |
| 27 | + * @param WC_Payment_Gateway $gateway Gateway object. | |
| 28 | + */ | |
| 29 | + public function get_display_title( WC_Payment_Gateway $gateway ): string { | |
| 30 | + foreach ( array( $gateway->get_title(), $gateway->method_title ) as $title ) { | |
| 31 | + if ( is_string( $title ) && '' !== trim( $title ) ) { | |
| 32 | + return $title; | |
| 33 | + } | |
| 34 | + } | |
| 35 | + | |
| 36 | + return (string) $gateway->id; | |
| 37 | + } | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * Gateway description for POS and settings display, falling back to the | |
| 41 | + * admin method description. | |
| 42 | + * | |
| 43 | + * @param WC_Payment_Gateway $gateway Gateway object. | |
| 44 | + */ | |
| 45 | + public function get_display_description( WC_Payment_Gateway $gateway ): string { | |
| 46 | + foreach ( array( $gateway->get_description(), $gateway->method_description ) as $description ) { | |
| 47 | + if ( is_string( $description ) && '' !== trim( $description ) ) { | |
| 48 | + return $description; | |
| 49 | + } | |
| 50 | + } | |
| 51 | + | |
| 52 | + return ''; | |
| 53 | + } | |
| 54 | + | |
| 55 | + /** | |
| 22 | 56 | * Infer POS type for a gateway. |
| 23 | 57 | * |
| 24 | 58 | * @param WC_Payment_Gateway $gateway Gateway object. |
| 25 | 59 | * @param WP_REST_Request $request Request object. |