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

wp-graphql / wp-graphql-woocommerce / 23675172456

28 Mar 2026 02:10AM UTC coverage: 70.983% (-18.4%) from 89.424%
23675172456

Pull #1003

github

web-flow
Merge 05339093d into 6fb7b226f
Pull Request #1003: devops: WC email template tests, COT cursor HPOS fix, checkout account auth

71 of 81 new or added lines in 5 files covered. (87.65%)

3346 existing lines in 124 files now uncovered.

12576 of 17717 relevant lines covered (70.98%)

55.38 hits per line

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

68.57
/includes/mutation/class-payment-method-delete.php
1
<?php
2
/**
3
 * Mutation - deletePaymentMethod
4
 *
5
 * Registers mutation for deleting a stored payment method.
6
 *
7
 * @package WPGraphQL\WooCommerce\Mutation
8
 * @since 0.12.4
9
 */
10

11
namespace WPGraphQL\WooCommerce\Mutation;
12

13
use GraphQL\Error\UserError;
14
use WC_Payment_Tokens;
15

16
/**
17
 * Class Payment_Method_Delete
18
 */
19
class Payment_Method_Delete {
20
        /**
21
         * Registers mutation
22
         *
23
         * @return void
24
         */
25
        public static function register_mutation() {
26
                register_graphql_mutation(
110✔
27
                        'deletePaymentMethod',
110✔
28
                        [
110✔
29
                                'inputFields'         => self::get_input_fields(),
110✔
30
                                'outputFields'        => self::get_output_fields(),
110✔
31
                                'mutateAndGetPayload' => self::mutate_and_get_payload(),
110✔
32
                        ]
110✔
33
                );
110✔
34
        }
35

36
        /**
37
         * Defines the mutation input field configuration
38
         *
39
         * @return array
40
         */
41
        public static function get_input_fields() {
42
                return [
110✔
43
                        'tokenId' => [
110✔
44
                                'type'        => [ 'non_null' => 'Integer' ],
110✔
45
                                'description' => __( 'Token ID of the payment token being deleted.', 'wp-graphql-woocommerce' ),
110✔
46

47
                        ],
110✔
48
                ];
110✔
49
        }
50

51
        /**
52
         * Defines the mutation output field configuration
53
         *
54
         * @return array
55
         */
56
        public static function get_output_fields() {
57
                return [
110✔
58
                        'status' => [
110✔
59
                                'type'        => 'String',
110✔
60
                                'description' => __( 'Status of the request', 'wp-graphql-woocommerce' ),
110✔
61
                                'resolve'     => static function ( $payload ) {
110✔
UNCOV
62
                                        return ! empty( $payload['status'] ) ? $payload['status'] : 'FAILED';
×
63
                                },
110✔
64
                        ],
110✔
65
                ];
110✔
66
        }
67

68
        /**
69
         * Defines the mutation data modification closure.
70
         *
71
         * @return callable
72
         */
73
        public static function mutate_and_get_payload() {
74
                return static function ( $input ) {
110✔
UNCOV
75
                        global $wp;
×
UNCOV
76
                        if ( ! is_user_logged_in() ) {
×
UNCOV
77
                                throw new UserError( __( 'Must be authenticated to set a default payment method', 'wp-graphql-woocommerce' ) );
×
78
                        }
79

UNCOV
80
                        $token_id = $input['tokenId'];
×
UNCOV
81
                        $token    = WC_Payment_Tokens::get( $token_id );
×
82

UNCOV
83
                        if ( is_null( $token ) || get_current_user_id() !== $token->get_user_id() ) {
×
UNCOV
84
                                throw new UserError( __( 'Invalid payment method.', 'wp-graphql-woocommerce' ) );
×
85
                        }
86

UNCOV
87
                        WC_Payment_Tokens::delete( $token_id );
×
UNCOV
88
                        wc_add_notice( __( 'Payment method deleted.', 'wp-graphql-woocommerce' ) );
×
89

UNCOV
90
                        return [ 'status' => 'SUCCESS' ];
×
91
                };
110✔
92
        }
93
}
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

© 2026 Coveralls, Inc