Passed
Push — main ( 061772...28b955 )
by Remco
07:49 queued 12s
created

ResultCode   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 95
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B to_core() 0 18 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\Payvision
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Payvision;
12
13
use Pronamic\WordPress\Pay\Payments\PaymentStatus;
14
15
/**
16
 * Result Code
17
 *
18
 * @link    https://developers.acehubpaymentservices.com/reference#result-codes-2
19
 * @author  Remco Tolsma
20
 * @version 1.0.0
21
 * @since   1.0.0
22
 */
23
class ResultCode {
24
	/**
25
	 * Customer processing error.
26
	 *
27
	 * Error or cancellation of customer at supplier. For example, the customer
28
	 * abandoned their transaction at the supplier.
29
	 *
30
	 * @var int
31
	 */
32
	const CUSTOMER_ERROR = -10;
33
34
	/**
35
	 * Declined.
36
	 *
37
	 * Declines, etc. In these cases the processing was performed correctly,
38
	 * but the end-result for the customer is not.
39
	 *
40
	 * @var int
41
	 */
42
	const DECLINED = -4;
43
44
	/**
45
	 * Failed.
46
	 *
47
	 * The transaction failed because of a processing error at Payvision.
48
	 *
49
	 * @var int
50
	 */
51
	const FAILED = -2;
52
53
	/**
54
	 * Ok.
55
	 *
56
	 * The transaction was processed successfully.
57
	 *
58
	 * @var int
59
	 */
60
	const OK = 0;
61
62
	/**
63
	 * Waiting.
64
	 *
65
	 * The transaction was initiated successfully, but a payment was not yet made by the
66
	 * customer or not yet confirmed by the bank. Occurs for brands for which customers
67
	 * have to make a payment separately (like Boletos) or where the bank does not
68
	 * immediately confirm a payment (like SEPA).
69
	 *
70
	 * @var int
71
	 */
72
	const WAITING = 1;
73
74
	/**
75
	 * Pending.
76
	 *
77
	 * Pending transaction, the payment was initiated and waiting for the customer to
78
	 * complete the payment at the bank or payment processor.
79
	 *
80
	 * @var int
81
	 */
82
	const PENDING = 2;
83
84
	/**
85
	 * Timeout.
86
	 *
87
	 * The payment timeout expired before the customer completed the payment.
88
	 *
89
	 * @var int
90
	 */
91
	const TIMEOUT = 4;
92
93
	/**
94
	 * Transform Payvision result code to WordPress payment status.
95
	 *
96
	 * @param int|null $result_code Payvision result code.
97
	 * @return string|null WordPress payment status.
98
	 */
99 9
	public static function to_core( $result_code ) {
100
		switch ( $result_code ) {
101 9
			case self::CUSTOMER_ERROR:
102 1
				return PaymentStatus::CANCELLED;
103 8
			case self::DECLINED:
104 7
			case self::FAILED:
105 2
				return PaymentStatus::FAILURE;
106 6
			case self::TIMEOUT:
107 1
				return PaymentStatus::EXPIRED;
108 5
			case self::PENDING:
109 4
			case self::WAITING:
110 2
				return PaymentStatus::OPEN;
111 3
			case self::OK:
112 2
				return PaymentStatus::SUCCESS;
113
		}
114
115 1
		return null;
116
	}
117
}
118