blob: 2eec7133b4e440268e38f6cd5b24f72df401dd09 [file] [log] [blame]
swissChilif0cbdc32023-01-05 17:21:38 -05001<?php
2
3if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly
5}
6
7// phpcs:disable WordPress.Files.FileName
8
9/**
10 * WooCommerce Stripe SEPA Direct Debit Payment Token.
11 *
12 * Representation of a payment token for SEPA.
13 *
14 * @class WC_Payment_Token_SEPA
15 * @version 4.0.0
16 * @since 4.0.0
17 */
18class WC_Payment_Token_SEPA extends WC_Payment_Token {
19
20 /**
21 * Stores payment type.
22 *
23 * @var string
24 */
25 protected $type = 'sepa';
26
27 /**
28 * Stores SEPA payment token data.
29 *
30 * @var array
31 */
32 protected $extra_data = [
33 'last4' => '',
34 'payment_method_type' => 'sepa_debit',
35 ];
36
37 /**
38 * Get type to display to user.
39 *
40 * @since 4.0.0
41 * @version 4.0.0
42 * @param string $deprecated Deprecated since WooCommerce 3.0
43 * @return string
44 */
45 public function get_display_name( $deprecated = '' ) {
46 $display = sprintf(
47 /* translators: last 4 digits of IBAN account */
48 __( 'SEPA IBAN ending in %s', 'woocommerce-gateway-stripe' ),
49 $this->get_last4()
50 );
51
52 return $display;
53 }
54
55 /**
56 * Hook prefix
57 *
58 * @since 4.0.0
59 * @version 4.0.0
60 */
61 protected function get_hook_prefix() {
62 return 'woocommerce_payment_token_sepa_get_';
63 }
64
65 /**
66 * Validate SEPA payment tokens.
67 *
68 * These fields are required by all SEPA payment tokens:
69 * last4 - string Last 4 digits of the iBAN
70 *
71 * @since 4.0.0
72 * @version 4.0.0
73 * @return boolean True if the passed data is valid
74 */
75 public function validate() {
76 if ( false === parent::validate() ) {
77 return false;
78 }
79
80 if ( ! $this->get_last4( 'edit' ) ) {
81 return false;
82 }
83
84 return true;
85 }
86
87 /**
88 * Returns the last four digits.
89 *
90 * @since 4.0.0
91 * @version 4.0.0
92 * @param string $context What the value is for. Valid values are view and edit.
93 * @return string Last 4 digits
94 */
95 public function get_last4( $context = 'view' ) {
96 return $this->get_prop( 'last4', $context );
97 }
98
99 /**
100 * Set the last four digits.
101 *
102 * @since 4.0.0
103 * @version 4.0.0
104 * @param string $last4
105 */
106 public function set_last4( $last4 ) {
107 $this->set_prop( 'last4', $last4 );
108 }
109
110 /**
111 * Set Stripe payment method type.
112 *
113 * @param string $type Payment method type.
114 */
115 public function set_payment_method_type( $type ) {
116 $this->set_prop( 'payment_method_type', $type );
117 }
118
119 /**
120 * Returns Stripe payment method type.
121 *
122 * @param string $context What the value is for. Valid values are view and edit.
123 * @return string $payment_method_type
124 */
125 public function get_payment_method_type( $context = 'view' ) {
126 return $this->get_prop( 'payment_method_type', $context );
127 }
128}