Skip to content

Commit

Permalink
Code quality.
Browse files Browse the repository at this point in the history
  • Loading branch information
rvdsteege committed Feb 2, 2020
1 parent 3e5fa81 commit 12fcc47
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 68 deletions.
8 changes: 7 additions & 1 deletion src/AbstractGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ public function get_available_payment_methods() {
}

foreach ( $payment_methods_response->get_payment_methods() as $payment_method ) {
$core_payment_method = PaymentMethodType::to_wp( $payment_method->get_type() );
$type = $payment_method->get_type();

if ( null === $type ) {
continue;
}

$core_payment_method = PaymentMethodType::to_wp( $type );

$core_payment_methods[] = $core_payment_method;
}
Expand Down
42 changes: 18 additions & 24 deletions src/ActionInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,51 +32,45 @@ class ActionInformation extends ResponseObject {
*
* Possible values: GET, POST.
*
* @var string
* @var string|null
*/
private $method;

/**
* When non-empty, contains a value that you must submit to the /payments/details endpoint. In some cases, required for polling.
*
* @var string
* @var string|null
*/
private $payment_data;

/**
* Specifies the payment method.
*
* @var string
* @var string|null
*/
private $payment_method_type;

/**
* A token to pass to the 3DS2 Component to get the fingerprint/challenge.
*
* @var string
* @var string|null
*/
private $token;

/**
* Enum that specifies the action that needs to be taken by the client.
*
* @var string
* @var string|null
*/
private $type;

/**
* The URL, to which you must redirect a shopper to complete a payment
*
* @var string
* @var string|null
*/
private $url;

/**
* Construct action information.
*/
public function __construct() {
}

/**
* Get data.
*
Expand All @@ -99,7 +93,7 @@ public function set_data( $data ) {
/**
* Get method.
*
* @return string
* @return string|null
*/
public function get_method() {
return $this->method;
Expand All @@ -108,7 +102,7 @@ public function get_method() {
/**
* Set method.
*
* @param string $method Method.
* @param string|null $method Method.
* @return void
*/
public function set_method( $method ) {
Expand All @@ -118,7 +112,7 @@ public function set_method( $method ) {
/**
* Get payment data.
*
* @return string
* @return string|null
*/
public function get_payment_data() {
return $this->payment_data;
Expand All @@ -127,7 +121,7 @@ public function get_payment_data() {
/**
* Set payment data.
*
* @param string $payment_data Payment data.
* @param string|null $payment_data Payment data.
* @return void
*/
public function set_payment_data( $payment_data ) {
Expand All @@ -137,7 +131,7 @@ public function set_payment_data( $payment_data ) {
/**
* Get payment method type.
*
* @return string
* @return string|null
*/
public function get_payment_method_type() {
return $this->payment_method_type;
Expand All @@ -146,7 +140,7 @@ public function get_payment_method_type() {
/**
* Set payment method type.
*
* @param string $payment_method_type Payment method type.
* @param string|null $payment_method_type Payment method type.
* @return void
*/
public function set_payment_method_type( $payment_method_type ) {
Expand All @@ -156,7 +150,7 @@ public function set_payment_method_type( $payment_method_type ) {
/**
* Get token.
*
* @return string
* @return string|null
*/
public function get_token() {
return $this->token;
Expand All @@ -165,7 +159,7 @@ public function get_token() {
/**
* Set token.
*
* @param string $token Token.
* @param string|null $token Token.
* @return void
*/
public function set_token( $token ) {
Expand All @@ -175,7 +169,7 @@ public function set_token( $token ) {
/**
* Get type.
*
* @return mixed
* @return string|null
*/
public function get_type() {
return $this->type;
Expand All @@ -184,7 +178,7 @@ public function get_type() {
/**
* Set type.
*
* @param mixed $type Type.
* @param string|null $type Type.
* @return void
*/
public function set_type( $type ) {
Expand All @@ -194,7 +188,7 @@ public function set_type( $type ) {
/**
* Get URL.
*
* @return string
* @return string|null
*/
public function get_url() {
return $this->url;
Expand All @@ -203,7 +197,7 @@ public function get_url() {
/**
* Set URL.
*
* @param string $url URL.
* @param string|null $url URL.
* @return void
*/
public function set_url( $url ) {
Expand Down
18 changes: 6 additions & 12 deletions src/DetailsInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,21 @@ class DetailsInformation extends ResponseObject {
/**
* The value to provide in the result.
*
* @var string
* @var string|null
*/
private $key;

/**
* The type of the required input.
*
* @var string
* @var string|null
*/
private $type;

/**
* Construct action information.
*/
public function __construct() {
}

/**
* Get key.
*
* @return string
* @return string|null
*/
public function get_key() {
return $this->key;
Expand All @@ -52,7 +46,7 @@ public function get_key() {
/**
* Set key.
*
* @param string $key Key.
* @param string|null $key Key.
* @return void
*/
public function set_key( $key ) {
Expand All @@ -62,7 +56,7 @@ public function set_key( $key ) {
/**
* Get type.
*
* @return mixed
* @return string|null
*/
public function get_type() {
return $this->type;
Expand All @@ -71,7 +65,7 @@ public function get_type() {
/**
* Set type.
*
* @param mixed $type Type.
* @param string|null $type Type.
* @return void
*/
public function set_type( $type ) {
Expand Down
32 changes: 22 additions & 10 deletions src/DropInGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,19 @@ public function start( Payment $payment ) {
* @return void
*/
public function payment_redirect( Payment $payment ) {
// Check payment ID.
$payment_id = $payment->get_id();

if ( null === $payment_id ) {
return;
}

$payment_response = $payment->get_meta( 'adyen_payment_response' );

// Only show drop-in checkout page if payment method does not redirect.
if ( is_object( $payment_response ) ) {
if ( is_string( $payment_response ) && '' !== $payment_response ) {
$payment_response = \json_decode( $payment_response );

$payment_response = PaymentResponse::from_object( $payment_response );

$redirect = $payment_response->get_redirect();
Expand Down Expand Up @@ -197,7 +206,9 @@ public function payment_redirect( Payment $payment ) {
// Payment method type.
$payment_method_type = PaymentMethodType::transform( $payment->get_method() );

$request->set_allowed_payment_methods( array( $payment_method_type ) );
if ( null !== $payment_method_type ) {
$request->set_allowed_payment_methods( array( $payment_method_type ) );
}
}

$locale = Util::get_payment_locale( $payment );
Expand Down Expand Up @@ -242,7 +253,7 @@ public function payment_redirect( Payment $payment ) {
'pronamic-pay-adyen-checkout',
'pronamicPayAdyenCheckout',
array(
'paymentsUrl' => rest_url( Integration::REST_ROUTE_NAMESPACE . '/payments/' . $payment->get_id() ),
'paymentsUrl' => rest_url( Integration::REST_ROUTE_NAMESPACE . '/payments/' . $payment_id ),
'paymentsDetailsUrl' => rest_url( Integration::REST_ROUTE_NAMESPACE . '/payments/details/' ),
'paymentReturnUrl' => $payment->get_return_url(),
'configuration' => $configuration,
Expand Down Expand Up @@ -311,6 +322,8 @@ public function update_status( Payment $payment ) {
$payment_response = $payment->get_meta( 'adyen_payment_response' );

if ( is_string( $payment_response ) && '' !== $payment_response ) {
$payment_response = \json_decode( $payment_response );

$payment_response = PaymentResponse::from_object( $payment_response );

$details_result = $payment->get_meta( 'adyen_details_result' );
Expand All @@ -330,18 +343,16 @@ public function update_status( Payment $payment ) {
$input_type = ( 'POST' === Server::get( 'REQUEST_METHOD' ) ? INPUT_POST : INPUT_GET );

foreach ( $details as $detail ) {
$key = $detail->get_key();
$key = (string) $detail->get_key();

$details_result[ $key ] = \filter_input( $input_type, $key, FILTER_SANITIZE_STRING );
}

$details_result = Util::filter_null( $details_result );
}

$details_result = (object) $details_result;

if ( ! empty( $details_result ) ) {
$payment->set_meta( 'adyen_details_result', \wp_json_encode( $details_result ) );
}
if ( ! empty( $details_result ) ) {
$payment->set_meta( 'adyen_details_result', \wp_json_encode( (object) $details_result ) );
}
}

Expand All @@ -356,7 +367,7 @@ public function update_status( Payment $payment ) {
// Update payment status from payment details.
$payment_details_request = new PaymentDetailsRequest();

$payment_details_request->set_details( $details_result );
$payment_details_request->set_details( (object) $details_result );

$payment_details_request->set_payment_data( $payment_data );

Expand Down Expand Up @@ -467,6 +478,7 @@ public function create_payment( Payment $payment, PaymentMethod $payment_method
*
* @param PaymentDetailsRequest $payment_details_request Payment details request.
*
* @return PaymentResponse
* @throws \Exception Throws error if request fails.
*/
public function send_payment_details( PaymentDetailsRequest $payment_details_request ) {
Expand Down
6 changes: 3 additions & 3 deletions src/PaymentDetailsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public function get_details() {
/**
* Set details.
*
* @param DetailsInformation $details Details.
* @param object|null $details Details.
* @return void
*/
public function set_details( DetailsInformation $details ) {
public function set_details( $details ) {
$this->details = $details;
}

Expand All @@ -65,7 +65,7 @@ public function get_payment_data() {
/**
* Set payment data.
*
* @param string $payment_data Payment data.
* @param string|null $payment_data Payment data.
* @return void
*/
public function set_payment_data( $payment_data ) {
Expand Down
4 changes: 2 additions & 2 deletions src/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PaymentMethod extends ResponseObject {
/**
* Type.
*
* @var string
* @var string|null
*/
private $type;

Expand Down Expand Up @@ -53,7 +53,7 @@ public function __construct( $payment_method_object ) {
/**
* Get type.
*
* @return string
* @return string|null
*/
public function get_type() {
return $this->type;
Expand Down

0 comments on commit 12fcc47

Please sign in to comment.