wp-pay-gateways /
adyen
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Payment result helper |
||
| 4 | * |
||
| 5 | * @author Pronamic <[email protected]> |
||
| 6 | * @copyright 2005-2019 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.0.0 |
||
| 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 | */ |
||
| 29 | public static function update_payment( Payment $payment, PaymentResultResponse $response ) { |
||
| 30 | // Add note. |
||
| 31 | $note = sprintf( |
||
| 32 | '<p>%1$s</p><pre>%2$s</pre>', |
||
| 33 | sprintf( |
||
| 34 | /* translators: %s: payment provider name */ |
||
| 35 | __( 'Verified payment result.', 'pronamic_ideal' ), |
||
| 36 | __( 'Adyen', 'pronamic_ideal' ) |
||
| 37 | ), |
||
| 38 | wp_json_encode( $response->get_json(), JSON_PRETTY_PRINT ) |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 39 | ); |
||
| 40 | |||
| 41 | $payment->add_note( $note ); |
||
| 42 | |||
| 43 | // PSP reference. |
||
| 44 | $psp_reference = $response->get_psp_reference(); |
||
| 45 | |||
| 46 | if ( null !== $psp_reference ) { |
||
| 47 | $payment->set_transaction_id( $psp_reference ); |
||
| 48 | } |
||
| 49 | |||
| 50 | // Result code. |
||
| 51 | $result_code = $response->get_result_code(); |
||
| 52 | |||
| 53 | if ( null !== $result_code ) { |
||
| 54 | $payment->set_status( ResultCode::transform( $result_code ) ); |
||
| 55 | } |
||
| 56 | |||
| 57 | // Payment save. |
||
| 58 | $payment->save(); |
||
| 59 | } |
||
| 60 | } |
||
| 61 |