1 | <?php |
||
19 | abstract class WC_Payment_Token extends WC_Data { |
||
20 | |||
21 | /** |
||
|
|||
22 | * Token Data (stored in the payment_tokens table). |
||
23 | * @var array |
||
24 | */ |
||
25 | protected $_data = array( |
||
26 | 'id' => 0, |
||
27 | 'gateway_id' => '', |
||
28 | 'token' => '', |
||
29 | 'is_default' => 0, |
||
30 | 'user_id' => 0, |
||
31 | ); |
||
32 | |||
33 | /** |
||
34 | * Meta type. Payment tokens are a new object type. |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $_meta_type = 'payment_token'; |
||
38 | |||
39 | /** |
||
40 | * Initialize a payment token. |
||
41 | * |
||
42 | * These fields are accepted by all payment tokens: |
||
43 | * is_default - boolean Optional - Indicates this is the default payment token for a user |
||
44 | * token - string Required - The actual token to store |
||
45 | * gateway_id - string Required - Identifier for the gateway this token is associated with |
||
46 | * user_id - int Optional - ID for the user this token is associated with. 0 if this token is not associated with a user |
||
47 | * |
||
48 | * @since 2.6.0 |
||
49 | * @param mixed $token |
||
50 | */ |
||
51 | public function __construct( $token = '' ) { |
||
65 | |||
66 | /** |
||
67 | * Returns the payment token ID. |
||
68 | * @since 2.6.0 |
||
69 | * @return integer Token ID |
||
70 | */ |
||
71 | public function get_id() { |
||
74 | |||
75 | /** |
||
76 | * Returns the raw payment token. |
||
77 | * @since 2.6.0 |
||
78 | * @return string Raw token |
||
79 | */ |
||
80 | public function get_token() { |
||
83 | |||
84 | /** |
||
85 | * Set the raw payment token. |
||
86 | * @since 2.6.0 |
||
87 | * @param string $token |
||
88 | */ |
||
89 | public function set_token( $token ) { |
||
92 | |||
93 | /** |
||
94 | * Returns the type of this payment token (CC, eCheck, or something else). |
||
95 | * @since 2.6.0 |
||
96 | * @return string Payment Token Type (CC, eCheck) |
||
97 | */ |
||
98 | public function get_type() { |
||
101 | |||
102 | /** |
||
103 | * Get type to display to user. |
||
104 | * @return string |
||
105 | */ |
||
106 | public function get_display_name() { |
||
109 | |||
110 | /** |
||
111 | * Returns the user ID associated with the token or false if this token is not associated. |
||
112 | * @since 2.6.0 |
||
113 | * @return int User ID if this token is associated with a user or 0 if no user is associated |
||
114 | */ |
||
115 | public function get_user_id() { |
||
118 | |||
119 | /** |
||
120 | * Set the user ID for the user associated with this order. |
||
121 | * @since 2.6.0 |
||
122 | * @param int $user_id |
||
123 | */ |
||
124 | public function set_user_id( $user_id ) { |
||
127 | |||
128 | /** |
||
129 | * Returns the ID of the gateway associated with this payment token. |
||
130 | * @since 2.6.0 |
||
131 | * @return string Gateway ID |
||
132 | */ |
||
133 | public function get_gateway_id() { |
||
136 | |||
137 | /** |
||
138 | * Set the gateway ID. |
||
139 | * @since 2.6.0 |
||
140 | * @param string $gateway_id |
||
141 | */ |
||
142 | public function set_gateway_id( $gateway_id ) { |
||
145 | |||
146 | /** |
||
147 | * Returns if the token is marked as default. |
||
148 | * @since 2.6.0 |
||
149 | * @return boolean True if the token is default |
||
150 | */ |
||
151 | public function is_default() { |
||
154 | |||
155 | /** |
||
156 | * Marks the payment as default or non-default. |
||
157 | * @since 2.6.0 |
||
158 | * @param boolean $is_default True or false |
||
159 | */ |
||
160 | public function set_default( $is_default ) { |
||
163 | |||
164 | /** |
||
165 | * Validate basic token info (token and type are required). |
||
166 | * @since 2.6.0 |
||
167 | * @return boolean True if the passed data is valid |
||
168 | */ |
||
169 | public function validate() { |
||
180 | |||
181 | /** |
||
182 | * Get a token from the database. |
||
183 | * @since 2.6.0 |
||
184 | * @param int $token_id Token ID |
||
185 | */ |
||
186 | public function read( $token_id ) { |
||
197 | |||
198 | /** |
||
199 | * Update a payment token. |
||
200 | * @since 2.6.0 |
||
201 | * @return boolean on success, false if validation failed and a payment token could not be updated |
||
202 | */ |
||
203 | public function update() { |
||
233 | |||
234 | /** |
||
235 | * Create a new payment token in the database. |
||
236 | * @since 2.6.0 |
||
237 | * @return boolean on success, false if validation failed and a payment token could not be created |
||
238 | */ |
||
239 | public function create() { |
||
272 | |||
273 | /** |
||
274 | * Saves a payment token to the database - does not require you to know if this is a new token or an update token. |
||
275 | * @since 2.6.0 |
||
276 | * @return boolean on success, false if validation failed and a payment token could not be saved |
||
277 | */ |
||
278 | public function save() { |
||
285 | |||
286 | /** |
||
287 | * Remove a payment token from the database. |
||
288 | * @since 2.6.0 |
||
289 | */ |
||
290 | public function delete() { |
||
297 | |||
298 | } |
||
299 |