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