mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
Add retry counter meta to order to avoid duplicate invoice error on consequent tries
This commit is contained in:
parent
355bac28f9
commit
c072e8550a
6 changed files with 26 additions and 40 deletions
|
@ -121,9 +121,11 @@ class PurchaseUnitFactory {
|
|||
$payee = $this->payee_repository->payee();
|
||||
$wc_order_id = $order->get_order_number();
|
||||
$custom_id = $this->prefix . $wc_order_id;
|
||||
$invoice_id = $this->prefix . $wc_order_id;
|
||||
$retry = $order->get_meta( 'ppcp-retry' ) ? '-' . $order->get_meta( 'ppcp-retry' ) : '';
|
||||
$invoice_id = $this->prefix . $wc_order_id . $retry;
|
||||
$soft_descriptor = '';
|
||||
$purchase_unit = new PurchaseUnit(
|
||||
|
||||
$purchase_unit = new PurchaseUnit(
|
||||
$amount,
|
||||
$items,
|
||||
$shipping,
|
||||
|
|
|
@ -253,13 +253,19 @@ trait ProcessPaymentTrait {
|
|||
}
|
||||
}
|
||||
|
||||
// Adds retry counter meta to avoid duplicate invoice id error on consequent tries.
|
||||
$wc_order->update_meta_data( 'ppcp-retry', (int) $wc_order->get_meta( 'ppcp-retry' ) + 1 );
|
||||
$wc_order->save_meta_data();
|
||||
|
||||
$this->session_handler->destroy_session_data();
|
||||
wc_add_notice( $error_message, 'error' );
|
||||
|
||||
return $failure_data;
|
||||
}
|
||||
|
||||
WC()->cart->empty_cart();
|
||||
$this->session_handler->destroy_session_data();
|
||||
|
||||
return array(
|
||||
'result' => 'success',
|
||||
'redirect' => $this->get_return_url( $wc_order ),
|
||||
|
|
|
@ -189,8 +189,6 @@ class OrderProcessor {
|
|||
$wc_order->update_meta_data( AuthorizedPaymentsProcessor::CAPTURED_META_KEY, 'true' );
|
||||
$wc_order->update_status( 'processing' );
|
||||
}
|
||||
WC()->cart->empty_cart();
|
||||
$this->session_handler->destroy_session_data();
|
||||
$this->last_error = '';
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ class PurchaseUnitFactoryTest extends TestCase
|
|||
$wcOrder = Mockery::mock(\WC_Order::class);
|
||||
$wcOrder
|
||||
->expects('get_order_number')->andReturn($wcOrderId);
|
||||
$wcOrder->expects('get_meta')->andReturn('');
|
||||
$amount = Mockery::mock(Amount::class);
|
||||
$amountFactory = Mockery::mock(AmountFactory::class);
|
||||
$amountFactory
|
||||
|
@ -89,6 +90,7 @@ class PurchaseUnitFactoryTest extends TestCase
|
|||
$wcOrder = Mockery::mock(\WC_Order::class);
|
||||
$wcOrder
|
||||
->expects('get_order_number')->andReturn(1);
|
||||
$wcOrder->expects('get_meta')->andReturn('');
|
||||
$amount = Mockery::mock(Amount::class);
|
||||
$amountFactory = Mockery::mock(AmountFactory::class);
|
||||
$amountFactory
|
||||
|
@ -144,6 +146,7 @@ class PurchaseUnitFactoryTest extends TestCase
|
|||
$wcOrder = Mockery::mock(\WC_Order::class);
|
||||
$wcOrder
|
||||
->expects('get_order_number')->andReturn(1);
|
||||
$wcOrder->expects('get_meta')->andReturn('');
|
||||
$amount = Mockery::mock(Amount::class);
|
||||
$amountFactory = Mockery::mock(AmountFactory::class);
|
||||
$amountFactory
|
||||
|
|
|
@ -42,7 +42,7 @@ class WcGatewayTest extends TestCase
|
|||
$orderId = 1;
|
||||
$wcOrder = Mockery::mock(\WC_Order::class);
|
||||
$wcOrder->shouldReceive('get_customer_id')->andReturn(1);
|
||||
|
||||
$wcOrder->shouldReceive('get_meta')->andReturn('');
|
||||
$settingsRenderer = Mockery::mock(SettingsRenderer::class);
|
||||
$orderProcessor = Mockery::mock(OrderProcessor::class);
|
||||
$orderProcessor
|
||||
|
@ -106,6 +106,18 @@ class WcGatewayTest extends TestCase
|
|||
when('wc_get_checkout_url')
|
||||
->justReturn('test');
|
||||
|
||||
$woocommerce = Mockery::mock(\WooCommerce::class);
|
||||
$session = Mockery::mock(\WC_Session::class);
|
||||
when('WC')->justReturn($woocommerce);
|
||||
$woocommerce->session = $session;
|
||||
$session->shouldReceive('get')->andReturn([]);
|
||||
|
||||
$woocommerce = Mockery::mock(\WooCommerce::class);
|
||||
$cart = Mockery::mock(\WC_Cart::class);
|
||||
when('WC')->justReturn($woocommerce);
|
||||
$woocommerce->cart = $cart;
|
||||
$cart->shouldReceive('empty_cart');
|
||||
|
||||
$result = $testee->process_payment($orderId);
|
||||
|
||||
$this->assertIsArray($result);
|
||||
|
|
|
@ -88,8 +88,6 @@ class OrderProcessorTest extends TestCase
|
|||
$sessionHandler
|
||||
->expects('order')
|
||||
->andReturn($currentOrder);
|
||||
$sessionHandler
|
||||
->expects('destroy_session_data');
|
||||
|
||||
$orderEndpoint = Mockery::mock(OrderEndpoint::class);
|
||||
$orderEndpoint
|
||||
|
@ -129,15 +127,6 @@ class OrderProcessorTest extends TestCase
|
|||
$this->environment
|
||||
);
|
||||
|
||||
$cart = Mockery::mock(\WC_Cart::class);
|
||||
$cart
|
||||
->expects('empty_cart');
|
||||
$woocommerce = Mockery::mock(\WooCommerce::class);
|
||||
when('WC')
|
||||
->justReturn($woocommerce);
|
||||
|
||||
$woocommerce->cart = $cart;
|
||||
|
||||
$wcOrder
|
||||
->expects('update_meta_data')
|
||||
->with(
|
||||
|
@ -211,8 +200,6 @@ class OrderProcessorTest extends TestCase
|
|||
$sessionHandler
|
||||
->expects('order')
|
||||
->andReturn($currentOrder);
|
||||
$sessionHandler
|
||||
->expects('destroy_session_data');
|
||||
$orderEndpoint = Mockery::mock(OrderEndpoint::class);
|
||||
$orderEndpoint
|
||||
->expects('patch_order_with')
|
||||
|
@ -234,21 +221,8 @@ class OrderProcessorTest extends TestCase
|
|||
->shouldReceive('has')
|
||||
->andReturnFalse();
|
||||
|
||||
$cart = Mockery::mock(\WC_Cart::class);
|
||||
$cart
|
||||
->shouldReceive('empty_cart');
|
||||
|
||||
$woocommerce = Mockery::Mock(\Woocommerce::class);
|
||||
$woocommerce
|
||||
->shouldReceive('__get')
|
||||
->with('cart')
|
||||
->set('cart', $cart);
|
||||
when('WC')
|
||||
->justReturn($woocommerce);
|
||||
|
||||
$logger = Mockery::mock(LoggerInterface::class);
|
||||
|
||||
|
||||
$testee = new OrderProcessor(
|
||||
$sessionHandler,
|
||||
$orderEndpoint,
|
||||
|
@ -260,15 +234,6 @@ class OrderProcessorTest extends TestCase
|
|||
$this->environment
|
||||
);
|
||||
|
||||
$cart = Mockery::mock(\WC_Cart::class);
|
||||
$cart
|
||||
->expects('empty_cart');
|
||||
$woocommerce = Mockery::mock(\WooCommerce::class);
|
||||
$woocommerce->cart = $cart;
|
||||
|
||||
when('WC')
|
||||
->justReturn($woocommerce);
|
||||
|
||||
$wcOrder
|
||||
->expects('update_meta_data')
|
||||
->with(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue