PaymentResultHelper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 20
c 3
b 0
f 0
dl 0
loc 47
ccs 19
cts 19
cp 1
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A update_payment() 0 39 4
1
<?php
2
/**
3
 * Payment result helper
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\Payment;
14
15
/**
16
 * Payment result helper
17
 *
18
 * @author  Remco Tolsma
19
 * @version 1.1.2
20
 * @since   1.0.0
21
 */
22
class PaymentResultHelper {
23
	/**
24
	 * Update payment to the payment result response.
25
	 *
26
	 * @param Payment               $payment  Payment.
27
	 * @param PaymentResultResponse $response Response.
28
	 * @return void
29
	 */
30 1
	public static function update_payment( Payment $payment, PaymentResultResponse $response ) {
31
		// Add note.
32 1
		$note = sprintf(
33 1
			'<p>%s</p>',
34 1
			sprintf(
35
				/* translators: %s: payment provider name */
36 1
				__( 'Verified payment result.', 'pronamic_ideal' ),
37 1
				__( 'Adyen', 'pronamic_ideal' )
38
			)
39
		);
40
41 1
		$json = wp_json_encode( $response->get_json(), JSON_PRETTY_PRINT );
42
43 1
		if ( false !== $json ) {
44 1
			$note .= sprintf(
45 1
				'<pre>%s</pre>',
46
				$json
47
			);
48
		}
49
50 1
		$payment->add_note( $note );
51
52
		// PSP reference.
53 1
		$psp_reference = $response->get_psp_reference();
54
55 1
		if ( null !== $psp_reference ) {
56 1
			$payment->set_transaction_id( $psp_reference );
57
		}
58
59
		// Result code.
60 1
		$result_code = $response->get_result_code();
61
62 1
		$status = ResultCode::transform( $result_code );
63
64 1
		if ( null !== $status ) {
65 1
			$payment->set_status( $status );
66
		}
67
68 1
		$payment->save();
69 1
	}
70
}
71