|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Connection - PaymentGateways |
| 4 | + * |
| 5 | + * Registers connections to PaymentGateway |
| 6 | + * |
| 7 | + * @package WPGraphQL\Extensions\WooCommerce\Connection |
| 8 | + */ |
| 9 | + |
| 10 | +namespace WPGraphQL\Extensions\WooCommerce\Connection; |
| 11 | + |
| 12 | +use WPGraphQL\Extensions\WooCommerce\Data\Factory; |
| 13 | + |
| 14 | +/** |
| 15 | + * Class - PaymentGateways |
| 16 | + */ |
| 17 | +class Payment_Gateways { |
| 18 | + /** |
| 19 | + * Registers the various connections from other Types to Customer |
| 20 | + */ |
| 21 | + public static function register_connections() { |
| 22 | + // From RootQuery. |
| 23 | + register_graphql_connection( self::get_connection_config() ); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * Given an array of $args, this returns the connection config, merging the provided args |
| 28 | + * with the defaults |
| 29 | + * |
| 30 | + * @access public |
| 31 | + * @param array $args - Connection configuration. |
| 32 | + * |
| 33 | + * @return array |
| 34 | + */ |
| 35 | + public static function get_connection_config( $args = [] ) { |
| 36 | + $defaults = array( |
| 37 | + 'fromType' => 'RootQuery', |
| 38 | + 'toType' => 'PaymentGateway', |
| 39 | + 'fromFieldName' => 'paymentGateways', |
| 40 | + 'connectionArgs' => self::get_connection_args(), |
| 41 | + 'resolve' => function ( $source, $args, $context, $info ) { |
| 42 | + return Factory::resolve_payment_gateway_connection( $source, $args, $context, $info ); |
| 43 | + }, |
| 44 | + ); |
| 45 | + return array_merge( $defaults, $args ); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Returns array of where args |
| 50 | + * |
| 51 | + * @return array |
| 52 | + */ |
| 53 | + public static function get_connection_args() { |
| 54 | + return array( |
| 55 | + 'all' => array( |
| 56 | + 'type' => 'Boolean', |
| 57 | + 'description' => __( 'Include disabled payment gateways?', 'wp-graphql-woocommerce' ), |
| 58 | + ), |
| 59 | + ); |
| 60 | + } |
| 61 | +} |
0 commit comments