|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* CLI |
|
4
|
|
|
* |
|
5
|
|
|
* @author Pronamic <[email protected]> |
|
6
|
|
|
* @copyright 2005-2021 Pronamic |
|
7
|
|
|
* @license GPL-3.0-or-later |
|
8
|
|
|
* @package Pronamic\WordPress\Pay\Buckaroo |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\Buckaroo; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Title: CLI |
|
15
|
|
|
* Description: |
|
16
|
|
|
* Copyright: 2005-2021 Pronamic |
|
17
|
|
|
* Company: Pronamic |
|
18
|
|
|
* |
|
19
|
|
|
* @author Remco Tolsma |
|
20
|
|
|
* @version 2.1.0 |
|
21
|
|
|
* @since 2.1.0 |
|
22
|
|
|
* @link https://github.com/woocommerce/woocommerce/blob/3.9.0/includes/class-wc-cli.php |
|
23
|
|
|
*/ |
|
24
|
|
|
class CLI { |
|
25
|
|
|
/** |
|
26
|
|
|
* Gateway integration. |
|
27
|
|
|
* |
|
28
|
|
|
* @var Integration |
|
29
|
|
|
*/ |
|
30
|
|
|
private $integration; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Construct CLI. |
|
34
|
|
|
* |
|
35
|
|
|
* @param Integration $integration Integration. |
|
36
|
|
|
* @retrun void |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct( $integration ) { |
|
39
|
|
|
$this->integration = $integration; |
|
40
|
|
|
|
|
41
|
|
|
// Check WP-CLI. |
|
42
|
|
|
if ( ! \class_exists( '\WP_CLI' ) ) { |
|
43
|
|
|
return; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
\WP_CLI::add_command( |
|
47
|
|
|
'pronamic-pay buckaroo transaction status', |
|
48
|
|
|
function( $args, $assoc_args ) { |
|
49
|
|
|
$this->wp_cli_transaction_status( $args, $assoc_args ); |
|
50
|
|
|
}, |
|
51
|
|
|
array( |
|
52
|
|
|
'shortdesc' => 'This returns the status for the provided transaction', |
|
53
|
|
|
) |
|
54
|
|
|
); |
|
55
|
|
|
|
|
56
|
|
|
\WP_CLI::add_command( |
|
57
|
|
|
'pronamic-pay buckaroo transaction refund-info', |
|
58
|
|
|
function( $args, $assoc_args ) { |
|
59
|
|
|
$this->wp_cli_transaction_refund_info( $args, $assoc_args ); |
|
60
|
|
|
}, |
|
61
|
|
|
array( |
|
62
|
|
|
'shortdesc' => 'This returns the refund info', |
|
63
|
|
|
) |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* CLI transaction status. |
|
69
|
|
|
* |
|
70
|
|
|
* @link https://testcheckout.buckaroo.nl/json/Docs/Api/GET-json-Transaction-Status-transactionKey |
|
71
|
|
|
* @param array<string> $args Arguments. |
|
72
|
|
|
* @param array<string> $assoc_args Associative arguments. |
|
73
|
|
|
* @return void |
|
74
|
|
|
*/ |
|
75
|
|
|
public function wp_cli_transaction_status( $args, $assoc_args ) { |
|
76
|
|
|
$gateway = $this->integration->get_gateway( (int) $assoc_args['config_id'] ); |
|
77
|
|
|
|
|
78
|
|
|
foreach ( $args as $transaction_key ) { |
|
79
|
|
|
$result = $gateway->request( 'GET', 'Transaction/Status/' . $transaction_key ); |
|
80
|
|
|
|
|
81
|
|
|
\WP_CLI::line( \wp_json_encode( $result, \JSON_PRETTY_PRINT ) ); |
|
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* CLI transaction refund info. |
|
87
|
|
|
* |
|
88
|
|
|
* @link https://testcheckout.buckaroo.nl/json/Docs/Api/GET-json-Transaction-Status-transactionKey |
|
89
|
|
|
* @param array<string> $args Arguments. |
|
90
|
|
|
* @param array<string> $assoc_args Associative arguments. |
|
91
|
|
|
* @return void |
|
92
|
|
|
*/ |
|
93
|
|
|
public function wp_cli_transaction_refund_info( $args, $assoc_args ) { |
|
94
|
|
|
$gateway = $this->integration->get_gateway( (int) $assoc_args['config_id'] ); |
|
95
|
|
|
|
|
96
|
|
|
foreach ( $args as $transaction_key ) { |
|
97
|
|
|
$result = $gateway->request( 'GET', 'Transaction/RefundInfo/' . $transaction_key ); |
|
98
|
|
|
|
|
99
|
|
|
\WP_CLI::line( \wp_json_encode( $result, \JSON_PRETTY_PRINT ) ); |
|
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|