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

Remove verification status and add test coverage for ppcp-gateway #33

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/inc/payment-gateways/ppcp-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ function select_first_payments_capture( $ppcp_data_order ) {
add_filter( 'sift_for_woocommerce_ppcp-gateway_card_last4', fn( $value, $ppcp_data ) => $ppcp_data['wc_order']?->get_meta_data( PayPalGateway::FRAUD_RESULT_META_KEY )['card_last_digits'] ?? $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 );
add_filter( 'sift_for_woocommerce_ppcp-gateway_cvv_result_code', fn( $value, $ppcp_data ) => select_first_payments_authorization( $ppcp_data['order'] )?->fraud_processor_response()->cvv_code() ?? $value, 10, 2 );
add_filter( 'sift_for_woocommerce_ppcp-gateway_verification_status', fn( $value, $ppcp_data ) => select_first_payments_authorization( $ppcp_data['order'] )?->status()->name() ?? $value, 10, 2 );
add_filter( 'sift_for_woocommerce_ppcp-gateway_decline_reason_code', fn( $value, $ppcp_data ) => select_first_payments_authorization( $ppcp_data['order'] )?->to_array()['reason_code'] ?? $value, 10, 2 );

add_filter( 'sift_for_woocommerce_ppcp-gateway_paypal_payer_id', fn( $value, $ppcp_data ) => $ppcp_data['order']?->payer()?->payer_id() ?? $value, 10, 2 );
Expand Down
378 changes: 377 additions & 1 deletion tests/PaymentMethodTest.php

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions tests/mocks/ppcp-gateway/PPCP_Mock_Authorization.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php declare( strict_types=1 );

namespace Sift_For_WooCommerce\Tests\Mocks\PPCP_Gateway;

/**
* Mock class that stores authorization related data.
*/
class PPCP_Mock_Authorization {
/**
* Provide the fraud processor response.
*
* @return PPCP_Mock_Fraud_Processor_Response
*/
public function fraud_processor_response() {
return new PPCP_Mock_Fraud_Processor_Response();
}

/**
* Provide the status.
*
* @return PPCP_Mock_Authorization_Status
*/
public function status() {
return new PPCP_Mock_Authorization_Status();
}

/**
* Return this class as an array
*
* @return array
*/
public function to_array() {
return array(
'reason_code' => 'PPCP-decline-reason-code',
);
}
}
17 changes: 17 additions & 0 deletions tests/mocks/ppcp-gateway/PPCP_Mock_Authorization_Status.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php declare( strict_types=1 );

namespace Sift_For_WooCommerce\Tests\Mocks\PPCP_Gateway;

/**
* Mock object representing authorization status related data.
*/
class PPCP_Mock_Authorization_Status {
/**
* Get the name.
*
* @return string
*/
public function name() {
return 'PPCP-authorization-status';
}
}
26 changes: 26 additions & 0 deletions tests/mocks/ppcp-gateway/PPCP_Mock_Capture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php declare( strict_types=1 );

namespace Sift_For_WooCommerce\Tests\Mocks\PPCP_Gateway;

/**
* Mock object that represents payments capture data
*/
class PPCP_Mock_Capture {
/**
* Get the status.
*
* @return PPCP_Mock_Capture_Status
*/
public function status() {
return new PPCP_Mock_Capture_Status();
}

/**
* Get the seller protection
*
* @return PPCP_Mock_Seller_Protection
*/
public function seller_protection() {
return new PPCP_Mock_Seller_Protection();
}
}
17 changes: 17 additions & 0 deletions tests/mocks/ppcp-gateway/PPCP_Mock_Capture_Status.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php declare( strict_types=1 );

namespace Sift_For_WooCommerce\Tests\Mocks\PPCP_Gateway;

/**
* Mock object that represents capture status.
*/
class PPCP_Mock_Capture_Status {
/**
* Get the name of the status.
*
* @return string
*/
public function name() {
return 'PPCP-capture-status';
}
}
26 changes: 26 additions & 0 deletions tests/mocks/ppcp-gateway/PPCP_Mock_Fraud_Processor_Response.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php declare( strict_types=1 );

namespace Sift_For_WooCommerce\Tests\Mocks\PPCP_Gateway;

/**
* Mock object that represents fraud processor response related information.
*/
class PPCP_Mock_Fraud_Processor_Response {
/**
* Get the AVS code.
*
* @return string
*/
public function avs_code() {
return 'AVS-OK';
}

/**
* Get the CVV code.
*
* @return string
*/
public function cvv_code() {
return 'CVV-OK';
}
}
26 changes: 26 additions & 0 deletions tests/mocks/ppcp-gateway/PPCP_Mock_Order.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php declare( strict_types=1 );

namespace Sift_For_WooCommerce\Tests\Mocks\PPCP_Gateway;

/**
* Mock class that stores order related data.
*/
class PPCP_Mock_Order {
/**
* Get the purchase_units array
*
* @return array
*/
public function purchase_units() {
return array( new PPCP_Mock_Purchase_Unit() );
}

/**
* Get the payer object.
*
* @return PPCP_Mock_Payer
*/
public function payer() {
return new PPCP_Mock_Payer();
}
}
26 changes: 26 additions & 0 deletions tests/mocks/ppcp-gateway/PPCP_Mock_Payer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php declare( strict_types=1 );

namespace Sift_For_WooCommerce\Tests\Mocks\PPCP_Gateway;

/**
* Mock object that represents payer related data.
*/
class PPCP_Mock_Payer {
/**
* Get the payer id.
*
* @return string
*/
public function payer_id() {
return 'PPCP-Payer-ID';
}

/**
* Get the payer's email address.
*
* @return string
*/
public function email_address() {
return '[email protected]';
}
}
26 changes: 26 additions & 0 deletions tests/mocks/ppcp-gateway/PPCP_Mock_Payments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php declare( strict_types=1 );

namespace Sift_For_WooCommerce\Tests\Mocks\PPCP_Gateway;

/**
* Mock object representing payments related data.
*/
class PPCP_Mock_Payments {
/**
* Get the payment captures.
*
* @return array
*/
public function captures() {
return array( new PPCP_Mock_Capture() );
}

/**
* Get the payment authorizations.
*
* @return array
*/
public function authorizations() {
return array( new PPCP_Mock_Authorization() );
}
}
17 changes: 17 additions & 0 deletions tests/mocks/ppcp-gateway/PPCP_Mock_Purchase_Unit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php declare( strict_types=1 );

namespace Sift_For_WooCommerce\Tests\Mocks\PPCP_Gateway;

/**
* Mock class that stores purchase unit related data.
*/
class PPCP_Mock_Purchase_Unit {
/**
* Get the payments.
*
* @return PPCP_Mock_Payments
*/
public function payments() {
return new PPCP_Mock_Payments();
}
}
10 changes: 10 additions & 0 deletions tests/mocks/ppcp-gateway/PPCP_Mock_Seller_Protection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare( strict_types=1 );

namespace Sift_For_WooCommerce\Tests\Mocks\PPCP_Gateway;

/**
* Mock class that stores seller protection related data.
*/
class PPCP_Mock_Seller_Protection {
public $status = 'PPCP-seller-protection-status';
}
22 changes: 22 additions & 0 deletions tests/mocks/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

namespace Sift_For_WooCommerce\Tests\Mocks\Utils;

use Sift_For_WooCommerce\Tests\Mocks\PPCP_Gateway\PPCP_Mock_Order;

require_once __DIR__ . '/ppcp-gateway/PPCP_Mock_Authorization.php';
require_once __DIR__ . '/ppcp-gateway/PPCP_Mock_Authorization_Status.php';
require_once __DIR__ . '/ppcp-gateway/PPCP_Mock_Capture.php';
require_once __DIR__ . '/ppcp-gateway/PPCP_Mock_Capture_Status.php';
require_once __DIR__ . '/ppcp-gateway/PPCP_Mock_Fraud_Processor_Response.php';
require_once __DIR__ . '/ppcp-gateway/PPCP_Mock_Order.php';
require_once __DIR__ . '/ppcp-gateway/PPCP_Mock_Payer.php';
require_once __DIR__ . '/ppcp-gateway/PPCP_Mock_Payments.php';
require_once __DIR__ . '/ppcp-gateway/PPCP_Mock_Purchase_Unit.php';
require_once __DIR__ . '/ppcp-gateway/PPCP_Mock_Seller_Protection.php';

/**
* Build an object (or array) which represents the payment method returned by the Stripe API.
*
Expand Down Expand Up @@ -52,3 +65,12 @@ function build_mock_stripe_payment_method_object( array $config, bool $as_array
),
);
}

/**
* Build a mock order object from PPCP-Gateway
*
* @return PPCP_Mock_Order
*/
function build_mock_ppcp_order_object(): object {
return new PPCP_Mock_Order();
}
Loading