Skip to content

Commit

Permalink
Merge pull request #39 from pronamic/wp-mollie-4-dynamic-properties
Browse files Browse the repository at this point in the history
Update for payment details through `ObjectAccess` (pronamic/wp-mollie#4).
  • Loading branch information
remcotolsma committed Oct 4, 2023
2 parents 918d67d + 83f2747 commit db6e935
Showing 1 changed file with 31 additions and 34 deletions.
65 changes: 31 additions & 34 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -1136,8 +1136,8 @@ public function update_payment_from_mollie_payment( Payment $payment, MolliePaym
// Use wallet method as payment method.
$mollie_payment_details = $mollie_payment->get_details();

if ( null !== $mollie_payment_details && isset( $mollie_payment_details->wallet ) ) {
$wallet_method = $method_transformer->transform_mollie_to_wp( $mollie_payment_details->wallet );
if ( null !== $mollie_payment_details && $mollie_payment_details->has_property( 'wallet' ) ) {

Check failure on line 1139 in src/Gateway.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Call to an undefined method Pronamic\WordPress\Mollie\PaymentDetails::has_property().
$wallet_method = $method_transformer->transform_mollie_to_wp( $mollie_payment_details->get_property( 'wallet' ) );

Check failure on line 1140 in src/Gateway.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Call to an undefined method Pronamic\WordPress\Mollie\PaymentDetails::get_property().

if ( null !== $wallet_method ) {
$payment_method = $wallet_method;
Expand Down Expand Up @@ -1281,46 +1281,46 @@ public function update_payment_from_mollie_payment( Payment $payment, MolliePaym
$payment->set_consumer_bank_details( $consumer_bank_details );
}

if ( isset( $mollie_payment_details->consumerName ) ) {
$consumer_bank_details->set_name( $mollie_payment_details->consumerName );
if ( $mollie_payment_details->has_property( 'consumerName' ) ) {

Check failure on line 1284 in src/Gateway.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Call to an undefined method Pronamic\WordPress\Mollie\PaymentDetails::has_property().
$consumer_bank_details->set_name( $mollie_payment_details->get_property( 'consumerName' ) );

Check failure on line 1285 in src/Gateway.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Call to an undefined method Pronamic\WordPress\Mollie\PaymentDetails::get_property().
}

if ( isset( $mollie_payment_details->cardHolder ) ) {
$consumer_bank_details->set_name( $mollie_payment_details->cardHolder );
if ( $mollie_payment_details->has_property( 'cardHolder' ) ) {

Check failure on line 1288 in src/Gateway.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Call to an undefined method Pronamic\WordPress\Mollie\PaymentDetails::has_property().
$consumer_bank_details->set_name( $mollie_payment_details->get_property( 'cardHolder' ) );

Check failure on line 1289 in src/Gateway.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Call to an undefined method Pronamic\WordPress\Mollie\PaymentDetails::get_property().
}

if ( isset( $mollie_payment_details->cardNumber ) ) {
if ( $mollie_payment_details->has_property( 'cardNumber' ) ) {

Check failure on line 1292 in src/Gateway.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Call to an undefined method Pronamic\WordPress\Mollie\PaymentDetails::has_property().
// The last four digits of the card number.
$consumer_bank_details->set_account_number( $mollie_payment_details->cardNumber );
$consumer_bank_details->set_account_number( $mollie_payment_details->get_property( 'cardNumber' ) );

Check failure on line 1294 in src/Gateway.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Call to an undefined method Pronamic\WordPress\Mollie\PaymentDetails::get_property().
}

if ( isset( $mollie_payment_details->cardCountryCode ) ) {
if ( $mollie_payment_details->has_property( 'cardCountryCode' ) ) {

Check failure on line 1297 in src/Gateway.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Call to an undefined method Pronamic\WordPress\Mollie\PaymentDetails::has_property().
// The ISO 3166-1 alpha-2 country code of the country the card was issued in.
$consumer_bank_details->set_country( $mollie_payment_details->cardCountryCode );
$consumer_bank_details->set_country( $mollie_payment_details->get_property( 'cardCountryCode' ) );

Check failure on line 1299 in src/Gateway.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Call to an undefined method Pronamic\WordPress\Mollie\PaymentDetails::get_property().
}

if ( isset( $mollie_payment_details->consumerAccount ) ) {
if ( $mollie_payment_details->has_property( 'consumerAccount' ) ) {
switch ( $mollie_payment->get_method() ) {
case Methods::BELFIUS:
case Methods::DIRECT_DEBIT:
case Methods::IDEAL:
case Methods::KBC:
case Methods::SOFORT:
$consumer_bank_details->set_iban( $mollie_payment_details->consumerAccount );
$consumer_bank_details->set_iban( $mollie_payment_details->get_property( 'consumerAccount' ) );

break;
case Methods::BANCONTACT:
case Methods::BANKTRANSFER:
case Methods::PAYPAL:
default:
$consumer_bank_details->set_account_number( $mollie_payment_details->consumerAccount );
$consumer_bank_details->set_account_number( $mollie_payment_details->get_property( 'consumerAccount' ) );

break;
}
}

if ( isset( $mollie_payment_details->consumerBic ) ) {
$consumer_bank_details->set_bic( $mollie_payment_details->consumerBic );
if ( $mollie_payment_details->has_property( 'consumerBic' ) ) {
$consumer_bank_details->set_bic( $mollie_payment_details->get_property( 'consumerBic' ) );
}

/**
Expand All @@ -1342,51 +1342,48 @@ public function update_payment_from_mollie_payment( Payment $payment, MolliePaym
$bank_transfer_recipient_details->set_bank_account( $bank_details );
}

if ( isset( $mollie_payment_details->bankName ) ) {
if ( $mollie_payment_details->has_property( 'bankName' ) ) {
/**
* Set `bankName` as bank details name, as result "Stichting Mollie Payments"
* is not the name of a bank, but the account holder name.
*/
$bank_details->set_name( $mollie_payment_details->bankName );
$bank_details->set_name( $mollie_payment_details->get_property( 'bankName' ) );
}

if ( isset( $mollie_payment_details->bankAccount ) ) {
$bank_details->set_iban( $mollie_payment_details->bankAccount );
if ( $mollie_payment_details->has_property( 'bankAccount' ) ) {
$bank_details->set_iban( $mollie_payment_details->get_property( 'bankAccount' ) );
}

if ( isset( $mollie_payment_details->bankBic ) ) {
$bank_details->set_bic( $mollie_payment_details->bankBic );
if ( $mollie_payment_details->has_property( 'bankBic' ) ) {
$bank_details->set_bic( $mollie_payment_details->get_property( 'bankBic' ) );
}

if ( isset( $mollie_payment_details->transferReference ) ) {
$bank_transfer_recipient_details->set_reference( $mollie_payment_details->transferReference );
if ( $mollie_payment_details->has_property( 'transferReference' ) ) {
$bank_transfer_recipient_details->set_reference( $mollie_payment_details->get_property( 'transferReference' ) );
}

/*
* Failure reason.
*/
$failure_reason = $payment->get_failure_reason();

if ( null === $failure_reason ) {
$failure_reason = new FailureReason();
}

// SEPA Direct Debit.
if ( isset( $mollie_payment_details->bankReasonCode ) ) {
$failure_reason->set_code( $mollie_payment_details->bankReasonCode );
if ( $mollie_payment_details->has_property( 'bankReasonCode' ) ) {
$failure_reason->set_code( $mollie_payment_details->get_property( 'bankReasonCode' ) );
}

if ( isset( $mollie_payment_details->bankReason ) ) {
$failure_reason->set_message( $mollie_payment_details->bankReason );
if ( $mollie_payment_details->has_property( 'bankReason' ) ) {
$failure_reason->set_message( $mollie_payment_details->get_property( 'bankReason' ) );
}

// Credit card.
if ( isset( $mollie_payment_details->failureReason ) ) {
$failure_reason->set_code( $mollie_payment_details->failureReason );
if ( $mollie_payment_details->has_property( 'failureReason' ) ) {
$failure_reason->set_code( $mollie_payment_details->get_property( 'failureReason' ) );
}

if ( isset( $mollie_payment_details->failureMessage ) ) {
$failure_reason->set_message( $mollie_payment_details->failureMessage );
if ( $mollie_payment_details->has_property( 'failureMessage' ) ) {
$failure_reason->set_message( $mollie_payment_details->get_property( 'failureMessage' ) );
}

$failure_code = $failure_reason->get_code();
Expand Down

0 comments on commit db6e935

Please sign in to comment.