2024-02-12 14:32:30 +01:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace WooCommerce\PayPalCommerce\Tests\E2e;
|
|
|
|
|
|
|
|
use WC_Payment_Token_CC;
|
|
|
|
use WC_Payment_Tokens;
|
|
|
|
use WooCommerce\PayPalCommerce\SavePaymentMethods\Helper\RealTimeAccountUpdaterHelper;
|
|
|
|
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
|
|
|
|
|
|
|
class RealTimeAccountUpdaterTest extends TestCase
|
|
|
|
{
|
|
|
|
public function tearDown(): void
|
|
|
|
{
|
|
|
|
$tokens = WC_Payment_Tokens::get_customer_tokens(1, CreditCardGateway::ID);
|
|
|
|
foreach ($tokens as $token) {
|
|
|
|
$token->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateCard()
|
|
|
|
{
|
|
|
|
$token = $this->createToken();
|
|
|
|
|
2024-02-13 14:26:58 +01:00
|
|
|
(new RealTimeAccountUpdaterHelper())->update_wc_card_token('2042-02', '0004', $token);
|
2024-02-12 14:32:30 +01:00
|
|
|
|
|
|
|
$this->assertTrue($token->get_expiry_year() === '2042');
|
|
|
|
$this->assertTrue($token->get_expiry_month() === '02');
|
|
|
|
$this->assertTrue($token->get_last4() === '0004');
|
|
|
|
}
|
|
|
|
|
2024-02-12 15:19:16 +01:00
|
|
|
public function testUpdateOnlyAllowedCards()
|
|
|
|
{
|
|
|
|
$token = $this->createToken('AMEX');
|
|
|
|
|
2024-02-13 14:26:58 +01:00
|
|
|
(new RealTimeAccountUpdaterHelper())->update_wc_card_token('2042-02', '0004', $token);
|
2024-02-12 15:19:16 +01:00
|
|
|
|
|
|
|
$this->assertTrue($token->get_expiry_year() === '2025');
|
|
|
|
$this->assertTrue($token->get_expiry_month() === '01');
|
|
|
|
$this->assertTrue($token->get_last4() === '1234');
|
|
|
|
}
|
2024-02-12 14:32:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return WC_Payment_Token_CC
|
|
|
|
*/
|
2024-02-12 15:19:16 +01:00
|
|
|
private function createToken($brand = 'VISA'): \WC_Payment_Token_CC
|
2024-02-12 14:32:30 +01:00
|
|
|
{
|
|
|
|
$token = new WC_Payment_Token_CC();
|
|
|
|
$token->set_token('abc123');
|
|
|
|
$token->set_user_id(1);
|
|
|
|
$token->set_gateway_id(CreditCardGateway::ID);
|
|
|
|
|
|
|
|
$token->set_last4('1234');
|
|
|
|
$token->set_expiry_month('01');
|
|
|
|
$token->set_expiry_year('2025');
|
2024-02-12 15:19:16 +01:00
|
|
|
$token->set_card_type($brand);
|
2024-02-12 14:32:30 +01:00
|
|
|
|
|
|
|
$token->save();
|
|
|
|
|
|
|
|
return $token;
|
|
|
|
}
|
|
|
|
}
|