mirror of
https://github.com/wp-graphql/wp-graphql-woocommerce.git
synced 2026-08-14 12:53:44 +02:00
* chore: bump min versions to actual and update deps
* chore: fix multiple empty lines at EOF
* chore: preincrement when standalone (phpcs)
* fix: use `printf` instead of `echo sprintf` [phpcs]
* chore: avoid lonely `if()` in `else{}` [phpcs]
* chore: avoid reserved keywords as param names [phpcs]
* chore: remove unused callback params [phpcs]
* chore: remove more unused callback params [phpcs]
* chore: apply lints to tests
* chore: update ruleset for PHPCS 3.0
* texts: restore $last_request_headers
92 lines
2.0 KiB
PHP
92 lines
2.0 KiB
PHP
<?php
|
|
/**
|
|
* Factory class for the WooCommerce's Cart data objects.
|
|
*
|
|
* @since v0.8.0
|
|
* @package Tests\WPGraphQL\WooCommerce\Factory
|
|
*/
|
|
|
|
namespace Tests\WPGraphQL\WooCommerce\Factory;
|
|
|
|
/**
|
|
* Cart factory class for testing.
|
|
*/
|
|
class PaymentTokenFactory {
|
|
/**
|
|
* Create a new credit card payment token
|
|
*
|
|
* @since 2.6
|
|
* @return \WC_Payment_Token_CC object
|
|
*/
|
|
public static function createCCToken( $user_id = '', $args = [] ) {
|
|
$token = new \WC_Payment_Token_CC();
|
|
$token->set_last4( 1234 );
|
|
$token->set_expiry_month( '08' );
|
|
$token->set_expiry_year( '2016' );
|
|
$token->set_card_type( 'visa' );
|
|
$token->set_token( time() );
|
|
if ( ! empty( $user_id ) ) {
|
|
$token->set_user_id( $user_id );
|
|
}
|
|
|
|
// Set props.
|
|
foreach ( $args as $key => $value ) {
|
|
if ( is_callable( [ $token, "set_{$key}" ] ) ) {
|
|
$token->{"set_{$key}"}( $value );
|
|
}
|
|
}
|
|
|
|
$token->save();
|
|
return $token;
|
|
}
|
|
|
|
/**
|
|
* Create a new eCheck payment token
|
|
*
|
|
* @since 2.6
|
|
* @return \WC_Payment_Token_ECheck object
|
|
*/
|
|
public static function createECheckToken( $user_id = '', $args = [] ) {
|
|
$token = new \WC_Payment_Token_ECheck();
|
|
$token->set_last4( 1234 );
|
|
$token->set_token( time() );
|
|
|
|
if ( ! empty( $user_id ) ) {
|
|
$token->set_user_id( $user_id );
|
|
}
|
|
|
|
// Set props.
|
|
foreach ( $args as $key => $value ) {
|
|
if ( is_callable( [ $token, "set_{$key}" ] ) ) {
|
|
$token->{"set_{$key}"}( $value );
|
|
}
|
|
}
|
|
|
|
$token->save();
|
|
return $token;
|
|
}
|
|
|
|
/**
|
|
* Create a new 'stub' payment token
|
|
*
|
|
* @since 2.6
|
|
* @param string $extra A string to insert and get to test the metadata functionality of a token
|
|
* @return \WC_Payment_Token_Stub object
|
|
*/
|
|
public static function createStubToken( $extra, $args = [] ) {
|
|
$token = new \WC_Payment_Token_Stub();
|
|
$token->set_extra( $extra );
|
|
$token->set_token( time() );
|
|
|
|
// Set props.
|
|
foreach ( $args as $key => $value ) {
|
|
if ( is_callable( [ $token, "set_{$key}" ] ) ) {
|
|
$token->{"set_{$key}"}( $value );
|
|
}
|
|
}
|
|
|
|
$token->save();
|
|
return $token;
|
|
}
|
|
}
|