Get payer from order instead of customer

This commit is contained in:
dinamiko 2022-08-12 10:38:42 +02:00
parent 0e24b1d0f8
commit 76a81b535b
4 changed files with 5 additions and 9 deletions

View file

@ -118,8 +118,7 @@ class VaultedCreditCardHandler
public function handle_payment( public function handle_payment(
string $saved_credit_card, string $saved_credit_card,
WC_Order $wc_order, WC_Order $wc_order
WC_Customer $customer
): WC_Order { ): WC_Order {
$change_payment = filter_input( INPUT_POST, 'woocommerce_change_payment', FILTER_SANITIZE_STRING ); $change_payment = filter_input( INPUT_POST, 'woocommerce_change_payment', FILTER_SANITIZE_STRING );
@ -146,8 +145,7 @@ class VaultedCreditCardHandler
} }
$purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order ); $purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
$payer = $this->payer_factory->from_customer( $customer ); $payer = $this->payer_factory->from_wc_order( $wc_order);
$shipping_preference = $this->shipping_preference_factory->from_state( $shipping_preference = $this->shipping_preference_factory->from_state(
$purchase_unit, $purchase_unit,
'' ''

View file

@ -361,12 +361,9 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
$saved_credit_card = filter_input( INPUT_POST, 'saved_credit_card', FILTER_SANITIZE_STRING ); $saved_credit_card = filter_input( INPUT_POST, 'saved_credit_card', FILTER_SANITIZE_STRING );
if($saved_credit_card) { if($saved_credit_card) {
try { try {
$customer = new WC_Customer( $wc_order->get_customer_id() );
$wc_order = $this->vaulted_credit_card_handler->handle_payment( $wc_order = $this->vaulted_credit_card_handler->handle_payment(
$saved_credit_card, $saved_credit_card,
$wc_order, $wc_order
$customer
); );
return $this->handle_payment_success( $wc_order ); return $this->handle_payment_success( $wc_order );

View file

@ -105,7 +105,7 @@ class VaultedCreditCardHandlerTest extends TestCase
$customer = Mockery::mock(WC_Customer::class); $customer = Mockery::mock(WC_Customer::class);
$payer = Mockery::mock(Payer::class); $payer = Mockery::mock(Payer::class);
$this->payerFactory->shouldReceive('from_customer') $this->payerFactory->shouldReceive('from_wc_order')
->andReturn($payer); ->andReturn($payer);
$this->shippingPreferenceFactory->shouldReceive('from_state') $this->shippingPreferenceFactory->shouldReceive('from_state')
->andReturn('some_preference'); ->andReturn('some_preference');

View file

@ -90,6 +90,7 @@ class CreditCardGatewayTest extends TestCase
public function testProcessPaymentVaultedCard() public function testProcessPaymentVaultedCard()
{ {
$wc_order = Mockery::mock(WC_Order::class); $wc_order = Mockery::mock(WC_Order::class);
$wc_order->shouldReceive('get_customer_id')->andReturn(1);
when('wc_get_order')->justReturn($wc_order); when('wc_get_order')->justReturn($wc_order);
$savedCreditCard = 'abc123'; $savedCreditCard = 'abc123';