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

wp-graphql / wp-graphql-woocommerce / 27386231983

12 Jun 2026 12:25AM UTC coverage: 91.791%. Remained the same
27386231983

Pull #1019

github

web-flow
Merge 46a421a18 into 01876f534
Pull Request #1019: fix: address WordPress.org plugin review (rename + prefixing + headers)

1327 of 1584 new or added lines in 200 files covered. (83.78%)

1 existing line in 1 file now uncovered.

18505 of 20160 relevant lines covered (91.79%)

151.6 hits per line

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

96.55
/includes/mutation/class-refund-delete.php
1
<?php
2
/**
3
 * Mutation - deleteRefund
4
 *
5
 * Registers mutation for deleting a refund on an order.
6
 *
7
 * @package WPGraphQL\WooCommerce\Mutation
8
 * @since 1.0.0
9
 */
10

11
namespace WPGraphQL\WooCommerce\Mutation;
12

13
use GraphQL\Error\UserError;
14
use GraphQL\Type\Definition\ResolveInfo;
15
use WPGraphQL\AppContext;
16
use WPGraphQL\WooCommerce\Model\Order;
17

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

38
        /**
39
         * Defines the mutation input field configuration.
40
         *
41
         * @return array
42
         */
43
        public static function get_input_fields() {
44
                return [
296✔
45
                        'id'    => [
296✔
46
                                'type'        => [ 'non_null' => 'ID' ],
296✔
47
                                'description' => static function () {
296✔
48
                                        return __( 'The ID of the refund to delete.', 'graphql-for-ecommerce' );
2✔
49
                                },
296✔
50
                        ],
296✔
51
                        'force' => [
296✔
52
                                'type'        => 'Boolean',
296✔
53
                                'description' => static function () {
296✔
54
                                        return __( 'Force delete the refund. Defaults to true.', 'graphql-for-ecommerce' );
2✔
55
                                },
296✔
56
                        ],
296✔
57
                ];
296✔
58
        }
59

60
        /**
61
         * Defines the mutation output field configuration.
62
         *
63
         * @return array
64
         */
65
        public static function get_output_fields() {
66
                return [
296✔
67
                        'refund' => [
296✔
68
                                'type'    => 'Refund',
296✔
69
                                'resolve' => static function ( $payload ) {
296✔
70
                                        return ! empty( $payload['refund'] ) ? $payload['refund'] : null;
1✔
71
                                },
296✔
72
                        ],
296✔
73
                        'order'  => [
296✔
74
                                'type'    => 'Order',
296✔
75
                                'resolve' => static function ( $payload ) {
296✔
76
                                        return ! empty( $payload['order_id'] ) ? new Order( $payload['order_id'] ) : null;
1✔
77
                                },
296✔
78
                        ],
296✔
79
                ];
296✔
80
        }
81

82
        /**
83
         * Defines the mutation data modification closure.
84
         *
85
         * @return callable
86
         */
87
        public static function mutate_and_get_payload() {
88
                return static function ( $input, AppContext $context, ResolveInfo $info ) {
296✔
89
                        $refund_id = \WPGraphQL\Utils\Utils::get_database_id_from_id( $input['id'] );
3✔
90

91
                        if ( empty( $refund_id ) ) {
3✔
NEW
92
                                throw new UserError( __( 'Invalid refund ID.', 'graphql-for-ecommerce' ) );
×
93
                        }
94

95
                        /** @var \WC_Order_Refund|false $refund */
96
                        $refund = \wc_get_order( $refund_id );
3✔
97
                        if ( ! $refund || 'shop_order_refund' !== $refund->get_type() ) {
3✔
98
                                throw new UserError( __( 'Invalid refund ID.', 'graphql-for-ecommerce' ) );
2✔
99
                        }
100

101
                        $order_id = $refund->get_parent_id();
1✔
102
                        if ( ! \wc_rest_check_post_permissions( 'shop_order', 'delete', $order_id ) ) {
1✔
103
                                throw new UserError( __( 'You do not have permission to delete this refund.', 'graphql-for-ecommerce' ) );
1✔
104
                        }
105

106
                        // Capture refund data before deletion for the response.
107
                        $refund_model = new Order( $refund_id );
1✔
108

109
                        /**
110
                         * Action called before a refund is deleted.
111
                         *
112
                         * @param int                                  $refund_id Refund ID.
113
                         * @param int                                  $order_id  Order ID.
114
                         * @param array                                $input     Input data.
115
                         * @param \WPGraphQL\AppContext                $context   AppContext instance.
116
                         * @param \GraphQL\Type\Definition\ResolveInfo $info      ResolveInfo instance.
117
                         */
118
                        do_action( 'graphql_woocommerce_before_refund_delete', $refund_id, $order_id, $input, $context, $info );
1✔
119

120
                        $force  = isset( $input['force'] ) ? $input['force'] : true;
1✔
121
                        $result = $refund->delete( $force );
1✔
122

123
                        if ( ! $result ) {
1✔
NEW
124
                                throw new UserError( __( 'Could not delete refund.', 'graphql-for-ecommerce' ) );
×
125
                        }
126

127
                        /**
128
                         * Action called after a refund is deleted.
129
                         *
130
                         * @param int                                  $refund_id Refund ID.
131
                         * @param int                                  $order_id  Order ID.
132
                         * @param array                                $input     Input data.
133
                         * @param \WPGraphQL\AppContext                $context   AppContext instance.
134
                         * @param \GraphQL\Type\Definition\ResolveInfo $info      ResolveInfo instance.
135
                         */
136
                        do_action( 'graphql_woocommerce_after_refund_delete', $refund_id, $order_id, $input, $context, $info );
1✔
137

138
                        return [
1✔
139
                                'refund'   => $refund_model,
1✔
140
                                'order_id' => $order_id,
1✔
141
                        ];
1✔
142
                };
296✔
143
        }
144
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc