Completed
Pull Request — master (#1383)
by
unknown
01:40
created

WC_Helper_Token   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 1
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A create_token() 0 13 1
1
<?php
2
/**
3
 * Token helpers.
4
 *
5
 * @package WooCommerce/Tests
6
 */
7
8
/**
9
 * Class WC_Helper_Token.
10
 *
11
 * This helper class should ONLY be used for unit tests!.
12
 */
13
class WC_Helper_Token {
14
15
	/**
16
	 * Create a token.
17
	 *
18
	 * @param string $payment_method Token payment method.
19
	 * @param int    $user_id        ID of the token's user, defaults to get_current_user_id().
20
	 * @param string $gateway        Token's Gateway ID, default to WC_Payment_Gateway_WCPay::GATEWAY_ID
21
	 */
22
	public static function create_token( $payment_method, $user_id = null, $gateway = WC_Payment_Gateway_WCPay::GATEWAY_ID ) {
23
		$token = new WC_Payment_Token_CC();
24
		$token->set_token( $payment_method );
25
		$token->set_gateway_id( $gateway );
26
		$token->set_user_id( $user_id ?? get_current_user_id() );
27
		$token->set_card_type( 'visa' );
28
		$token->set_last4( '4242' );
29
		$token->set_expiry_month( 6 );
30
		$token->set_expiry_year( intval( gmdate( 'Y' ) ) + 1 );
31
		$token->save();
32
33
		return WC_Payment_Tokens::get( $token->get_id() );
34
	}
35
}
36