Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PHP Warnings in PPCP Gateway #29

Merged
merged 4 commits into from
Jan 17, 2025

Conversation

chrismccluskey
Copy link
Collaborator

@chrismccluskey chrismccluskey commented Jan 16, 2025

Changes proposed in this Pull Request

  • Remove a PHP Warning that happens when a function returns null and we expect an array.

Testing instructions

  • Patch this to your installed plugin
  • Try triggering this warning by updating the account page for a user with PayPal payment methods, or by trying to purchase something with PayPal.

Alternatively, automated tests should cover this already.

Closes 602-gh-automattic/gold

Copy link

Code Coverage

Package Line Rate Complexity Health
inc/payment-gateways/index.php 0% 0
inc/payment-gateways/lib/stripe.php 63% 77
inc/payment-gateways/load.php 0% 0
inc/payment-gateways/ppcp-gateway.php 0% 26
inc/payment-gateways/stripe.php 23% 17
inc/payment-gateways/transact.php 100% 0
inc/payment-gateways/woocommerce-payments.php 30% 8
inc/sift-decisions/abuse-decisions.php 0% 14
inc/sift-decisions/sift-decision-rest-api-webhooks.php 0% 10
inc/sift-events/class-sift-event-types.php 100% 4
inc/sift-events/normalizers/sift-order.php 96% 6
inc/sift-events/normalizers/sift-payment-gateway.php 100% 5
inc/sift-events/normalizers/sift-payment-method.php 97% 31
inc/sift-events/normalizers/sift-payment-type.php 83% 3
inc/sift-events/normalizers/sift-property.php 100% 3
inc/sift-events/normalizers/sift-verification-status.php 50% 3
inc/sift-events/sift-events-validator.php 85% 140
inc/sift-events/sift-events.php 71% 126
inc/tracking-js.php 0% 4
inc/wc-admin-settings-tab.php 0% 24
index.php 0% 0
sift-for-woocommerce.php 14% 11
Summary 54% (1030 / 1909) 512

Copy link
Collaborator

@chrisfromthelc chrisfromthelc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chrismccluskey chrismccluskey merged commit 6737222 into trunk Jan 17, 2025
12 checks passed
@chrismccluskey chrismccluskey deleted the refactor/nullsafe-operators-in-payment-gateways branch January 17, 2025 16:43
add_filter( 'sift_for_woocommerce_ppcp-gateway_cvv_result_code', fn( $value, $ppcp_data ) => $ppcp_data['order']?->purchase_units()[0]?->payments()?->authorizations()[0]?->fraud_processor_response()->cvv_code() ?? $value, 10, 2 );
add_filter( 'sift_for_woocommerce_ppcp-gateway_verification_status', fn( $value, $ppcp_data ) => $ppcp_data['order']?->purchase_units()[0]?->payments()?->authorizations()[0]?->status()->name() ?? $value, 10, 2 );
add_filter( 'sift_for_woocommerce_ppcp-gateway_decline_reason_code', fn( $value, $ppcp_data ) => $ppcp_data['order']?->purchase_units()[0]?->payments()?->authorizations()[0]?->to_array()['reason_code'] ?? $value, 10, 2 );
add_filter( 'sift_for_woocommerce_ppcp-gateway_avs_result_code', fn( $value, $ppcp_data ) => select_first_payments_authorization( $ppcp_data['order'] )?->fraud_processor_response()->avs_code() ?? $value, 10, 2 );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So

add_filter( 'sift_for_woocommerce_ppcp-gateway_avs_result_code', fn( $value, $ppcp_data ) => $ppcp_data['order']?->purchase_units()?[0]?->payments()?->authorizations()[0]?->fraud_processor_response()->avs_code() ?? $value

Would not work? I did not know...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my first thought, but no - it's a syntax error. There is an alternative, but I'm not sure if we want to use it as it's a bit harder to read. (context: p1737057534401999-slack-C6JKZ8MLK):

print_r( ( ( ( $ppcp_data['order'] ?? null )?->purchase_units() ?? [ null ] )[0]?->payments()?->authorizations() ?? [ null ] )[0]?->to_array()['reason_code'] ?? $value );

or

print_r( ( ( ( $ppcp_data['order'] ?? null )?->purchase_units()[0] ?? null )?->payments()?->authorizations()[0] ?? null )?->to_array()['reason_code'] ?? $value );

(replacing print_r with the filter and function)

@millerf
Copy link
Collaborator

millerf commented Jan 17, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants