2019-07-29 19:01:42 -04:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Connection - PaymentGateways
|
|
|
|
|
*
|
|
|
|
|
* Registers connections to PaymentGateway
|
|
|
|
|
*
|
2019-10-25 19:13:36 -04:00
|
|
|
* @package WPGraphQL\WooCommerce\Connection
|
2019-07-29 19:01:42 -04:00
|
|
|
*/
|
|
|
|
|
|
2019-10-25 19:13:36 -04:00
|
|
|
namespace WPGraphQL\WooCommerce\Connection;
|
2019-07-29 19:01:42 -04:00
|
|
|
|
2020-02-27 21:30:21 -03:00
|
|
|
use GraphQL\Type\Definition\ResolveInfo;
|
|
|
|
|
use WPGraphQL\AppContext;
|
2021-08-11 14:26:09 -04:00
|
|
|
use WPGraphQL\WooCommerce\Data\Connection\Payment_Gateway_Connection_Resolver;
|
2019-07-29 19:01:42 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class - PaymentGateways
|
|
|
|
|
*/
|
|
|
|
|
class Payment_Gateways {
|
|
|
|
|
/**
|
2020-02-27 21:30:21 -03:00
|
|
|
* Registers the various connections from other Types to Customer.
|
2023-06-13 23:17:02 +03:00
|
|
|
*
|
|
|
|
|
* @return void
|
2019-07-29 19:01:42 -04:00
|
|
|
*/
|
|
|
|
|
public static function register_connections() {
|
|
|
|
|
register_graphql_connection( self::get_connection_config() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Given an array of $args, this returns the connection config, merging the provided args
|
2020-02-27 21:30:21 -03:00
|
|
|
* with the defaults.
|
2019-07-29 19:01:42 -04:00
|
|
|
*
|
|
|
|
|
* @param array $args - Connection configuration.
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2022-08-26 14:53:36 -04:00
|
|
|
public static function get_connection_config( $args = [] ): array {
|
2020-02-27 21:30:21 -03:00
|
|
|
return array_merge(
|
2022-08-26 14:53:36 -04:00
|
|
|
[
|
2020-02-27 21:30:21 -03:00
|
|
|
'fromType' => 'RootQuery',
|
|
|
|
|
'toType' => 'PaymentGateway',
|
|
|
|
|
'fromFieldName' => 'paymentGateways',
|
|
|
|
|
'connectionArgs' => self::get_connection_args(),
|
2023-07-19 22:56:42 +03:00
|
|
|
'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
|
2021-08-11 14:26:09 -04:00
|
|
|
$resolver = new Payment_Gateway_Connection_Resolver();
|
|
|
|
|
|
|
|
|
|
return $resolver->resolve( $source, $args, $context, $info );
|
2020-02-27 21:30:21 -03:00
|
|
|
},
|
2022-08-26 14:53:36 -04:00
|
|
|
],
|
2020-02-27 21:30:21 -03:00
|
|
|
$args
|
2019-07-29 19:01:42 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-02-27 21:30:21 -03:00
|
|
|
* Returns array of where args.
|
2019-07-29 19:01:42 -04:00
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2020-02-27 21:30:21 -03:00
|
|
|
public static function get_connection_args(): array {
|
2022-08-26 14:53:36 -04:00
|
|
|
return [
|
|
|
|
|
'all' => [
|
2019-07-29 19:01:42 -04:00
|
|
|
'type' => 'Boolean',
|
2026-03-30 23:37:51 -04:00
|
|
|
'description' => static function () {
|
2026-06-30 10:16:21 -04:00
|
|
|
return __( 'Include disabled payment gateways?', 'graphql-for-ecommerce' );
|
2026-03-30 23:37:51 -04:00
|
|
|
},
|
2022-08-26 14:53:36 -04:00
|
|
|
],
|
|
|
|
|
];
|
2019-07-29 19:01:42 -04:00
|
|
|
}
|
|
|
|
|
}
|