• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wp-graphql / wp-graphql-woocommerce / 11714183904

07 Nov 2024 12:23AM UTC coverage: 83.665% (-0.8%) from 84.451%
11714183904

push

github

web-flow
devops: Name officially changed to "WPGraphQL for WooCommerce" (#900)

* devops: Name officially changed to "WPGraphQL for WooCommerce"

* devops: GA workflow environment updated

* devops: GA workflow environment updated

* devops: composer-git-hooks downgraded to "2.8.5"

* devops: Unstable session manager tests skipped

* chore: cleanup applied

* devops: Docker configurations updated

* devops: Docker configurations updated

* devops: Docker configurations updated

* devops: Docker configurations updated

* devops: Docker configurations updated

2 of 8 new or added lines in 5 files covered. (25.0%)

268 existing lines in 20 files now uncovered.

12431 of 14858 relevant lines covered (83.67%)

71.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.71
/includes/type/interface/class-payment-token.php
1
<?php
2
/**
3
 * WPInterface Type - Payment_Token
4
 *
5
 * @package WPGraphQL\WooCommerce\Type\WPInterface
6
 * @since   0.10.1
7
 */
8

9
namespace WPGraphQL\WooCommerce\Type\WPInterface;
10

11
use GraphQL\Error\UserError;
12
use GraphQLRelay\Relay;
13

14
/**
15
 * Class Payment_Token
16
 */
17
class Payment_Token {
18
        /**
19
         * Registers the "PaymentToken" interface.
20
         *
21
         * @return void
22
         */
23
        public static function register_interface() {
24
                register_graphql_interface_type(
141✔
25
                        'PaymentToken',
141✔
26
                        [
141✔
27
                                'description' => __( 'Payment token object', 'wp-graphql-woocommerce' ),
141✔
28
                                'interfaces'  => [ 'Node' ],
141✔
29
                                'fields'      => self::get_fields(),
141✔
30
                                'resolveType' => static function ( $value ) {
141✔
31
                                        $type_registry = \WPGraphQL::get_type_registry();
2✔
32
                                        $type          = $value->get_type();
2✔
33
                                        switch ( $type ) {
34
                                                case 'CC':
2✔
35
                                                        return $type_registry->get_type( 'PaymentTokenCC' );
2✔
36
                                                case 'eCheck':
2✔
37
                                                        return $type_registry->get_type( 'PaymentTokenECheck' );
2✔
38
                                                default:
39
                                                        throw new UserError(
×
40
                                                                sprintf(
×
41
                                                                        /* translators: %s: Payment token type */
NEW
42
                                                                        __( 'The "%s" token type is not supported by the core WPGraphQL for WooCommerce (WooGraphQL) schema.', 'wp-graphql-woocommerce' ),
×
43
                                                                        $type
×
44
                                                                )
×
45
                                                        );
×
46
                                        }
47
                                },
141✔
48
                        ]
141✔
49
                );
141✔
50
        }
51

52
        /**
53
         * Return field definitions.
54
         *
55
         * @param array $other_fields  Optional fields to be added.
56
         * @return array
57
         */
58
        public static function get_fields( $other_fields = [] ) {
59
                return array_merge(
141✔
60
                        [
141✔
61
                                'id'        => [
141✔
62
                                        'type'        => [ 'non_null' => 'ID' ],
141✔
63
                                        'description' => __( 'Token ID unique identifier', 'wp-graphql-woocommerce' ),
141✔
64
                                        'resolve'     => static function ( $source ) {
141✔
65
                                                return ! empty( $source->get_id() ) ? Relay::toGlobalId( 'token', $source->get_id() ) : null;
2✔
66
                                        },
141✔
67
                                ],
141✔
68
                                'tokenId'   => [
141✔
69
                                        'type'        => [ 'non_null' => 'Integer' ],
141✔
70
                                        'description' => __( 'Token database ID.', 'wp-graphql-woocommerce' ),
141✔
71
                                        'resolve'     => static function ( $source ) {
141✔
72
                                                return ! empty( $source->get_id() ) ? $source->get_id() : null;
1✔
73
                                        },
141✔
74
                                ],
141✔
75
                                'type'      => [
141✔
76
                                        'type'        => [ 'non_null' => 'String' ],
141✔
77
                                        'description' => __( 'Token type', 'wp-graphql-woocommerce' ),
141✔
78
                                        'resolve'     => static function ( $source ) {
141✔
79
                                                return ! empty( $source->get_type() ) ? $source->get_type() : null;
×
80
                                        },
141✔
81
                                ],
141✔
82
                                'gateway'   => [
141✔
83
                                        'type'        => 'PaymentGateway',
141✔
84
                                        'description' => __( 'Token payment gateway', 'wp-graphql-woocommerce' ),
141✔
85
                                        'resolve'     => static function ( $source ) {
141✔
86
                                                $gateway_id = $source->get_gateway_id();
×
87
                                                return null;
×
88
                                        },
141✔
89
                                ],
141✔
90
                                'isDefault' => [
141✔
91
                                        'type'        => 'Boolean',
141✔
92
                                        'description' => __( 'Is token connected to user\'s preferred payment method', 'wp-graphql-woocommerce' ),
141✔
93
                                        'resolve'     => static function ( $source ) {
141✔
94
                                                return ! is_null( $source->is_default() ) ? $source->is_default() : false;
1✔
95
                                        },
141✔
96
                                ],
141✔
97
                        ],
141✔
98
                        $other_fields
141✔
99
                );
141✔
100
        }
101
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc