Add unit tests for vaulted card handler

This commit is contained in:
dinamiko 2022-08-12 09:57:47 +02:00
parent 0f47b2ef37
commit 0e24b1d0f8
3 changed files with 155 additions and 5 deletions

View file

@ -118,7 +118,8 @@ class VaultedCreditCardHandler
public function handle_payment(
string $saved_credit_card,
WC_Order $wc_order
WC_Order $wc_order,
WC_Customer $customer
): WC_Order {
$change_payment = filter_input( INPUT_POST, 'woocommerce_change_payment', FILTER_SANITIZE_STRING );
@ -132,9 +133,7 @@ class VaultedCreditCardHandler
}
}
$user_id = (int) $wc_order->get_customer_id();
$customer = new WC_Customer( $user_id );
$tokens = $this->payment_token_repository->all_for_user_id( (int) $customer->get_id() );
$tokens = $this->payment_token_repository->all_for_user_id( $wc_order->get_customer_id() );
$selected_token = null;
foreach ( $tokens as $token ) {
if ( $token->id() === $saved_credit_card ) {
@ -148,6 +147,7 @@ class VaultedCreditCardHandler
$purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
$payer = $this->payer_factory->from_customer( $customer );
$shipping_preference = $this->shipping_preference_factory->from_state(
$purchase_unit,
''

View file

@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\WcGateway\Gateway;
use Exception;
use Psr\Log\LoggerInterface;
use WC_Customer;
use WC_Order;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PaymentsEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
@ -360,9 +361,12 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
$saved_credit_card = filter_input( INPUT_POST, 'saved_credit_card', FILTER_SANITIZE_STRING );
if($saved_credit_card) {
try {
$customer = new WC_Customer( $wc_order->get_customer_id() );
$wc_order = $this->vaulted_credit_card_handler->handle_payment(
$saved_credit_card,
$wc_order
$wc_order,
$customer
);
return $this->handle_payment_success( $wc_order );