ResultCode   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 21
c 2
b 0
f 0
dl 0
loc 89
ccs 13
cts 13
cp 1
rs 10
wmc 8

1 Method

Rating   Name   Duplication   Size   Complexity  
B transform() 0 16 8
1
<?php
2
/**
3
 * Result code
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2020 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways\Adyen
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Adyen;
12
13
use Pronamic\WordPress\Pay\Payments\PaymentStatus;
14
15
/**
16
 * Result code
17
 *
18
 * @link https://docs.adyen.com/developers/checkout/payment-result-codes
19
 *
20
 * @author  Reüel van der Steege
21
 * @version 1.0.0
22
 * @since   1.0.0
23
 */
24
class ResultCode {
25
	/**
26
	 * Authorized.
27
	 *
28
	 * The payment was successfully authorised.
29
	 *
30
	 * @var string
31
	 */
32
	const AUTHORIZED = 'Authorised';
33
34
	/**
35
	 * Cancelled.
36
	 *
37
	 * The payment was cancelled (by either the shopper or
38
	 * your own system) before processing was completed.
39
	 *
40
	 * @var string
41
	 */
42
	const CANCELLED = 'Cancelled';
43
44
	/**
45
	 * Error.
46
	 *
47
	 * There was an error when the payment was being processed.
48
	 *
49
	 * @var string
50
	 */
51
	const ERROR = 'Error';
52
53
	/**
54
	 * Pending.
55
	 *
56
	 * It's not possible to obtain the final status of the payment at this time.
57
	 * This is common for payments with an asynchronous flow, such as Boleto, iDEAL, or Klarna.
58
	 *
59
	 * @var string
60
	 */
61
	const PENDING = 'Pending';
62
63
	/**
64
	 * Received.
65
	 *
66
	 * This is part of the standard payment flow for methods such as SEPA Direct Debit,
67
	 * where it can take some time before the final status of the payment is known.
68
	 *
69
	 * @var string
70
	 */
71
	const RECEIVED = 'Received';
72
73
	/**
74
	 * Redirect shopper.
75
	 *
76
	 * The shopper needs to be redirected to an external web page or app to complete the payment.
77
	 *
78
	 * @var string
79
	 */
80
	const REDIRECT_SHOPPER = 'RedirectShopper';
81
82
	/**
83
	 * Refused.
84
	 *
85
	 * The payment was refused.
86
	 *
87
	 * @var string
88
	 */
89
	const REFUSED = 'Refused';
90
91
	/**
92
	 * Transform Adyen result code to WordPress payment status.
93
	 *
94
	 * @param string|null $result_code Adyen result code.
95
	 * @return string|null WordPress payment status.
96
	 */
97 9
	public static function transform( $result_code ) {
98
		switch ( $result_code ) {
99 9
			case self::PENDING:
100 8
			case self::RECEIVED:
101 7
			case self::REDIRECT_SHOPPER:
102 3
				return PaymentStatus::OPEN;
103 6
			case self::CANCELLED:
104 1
				return PaymentStatus::CANCELLED;
105 5
			case self::ERROR:
106 4
			case self::REFUSED:
107 2
				return PaymentStatus::FAILURE;
108 3
			case self::AUTHORIZED:
109 2
				return PaymentStatus::SUCCESS;
110
		}
111
112 1
		return null;
113
	}
114
}
115