Merge pull request #400 from woocommerce/pcp-458-payment-complete

Use payment_complete instead of updating status directly
This commit is contained in:
Emili Castells 2021-12-14 16:02:10 +01:00 committed by GitHub
commit 15d5182901
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 23 deletions

View file

@ -136,7 +136,7 @@ class CheckoutOrderApproved implements RequestHandler {
}
if ( $order->intent() === 'CAPTURE' ) {
$this->order_endpoint->capture( $order );
$order = $this->order_endpoint->capture( $order );
}
} catch ( RuntimeException $error ) {
$message = sprintf(
@ -187,23 +187,18 @@ class CheckoutOrderApproved implements RequestHandler {
return rest_ensure_response( $response );
}
$new_status = $order->intent() === 'CAPTURE' ? 'processing' : 'on-hold';
$status_message = $order->intent() === 'CAPTURE' ?
__( 'Payment received.', 'woocommerce-paypal-payments' )
: __( 'Payment can be captured.', 'woocommerce-paypal-payments' );
foreach ( $wc_orders as $wc_order ) {
if ( ! in_array( $wc_order->get_status(), array( 'pending', 'on-hold' ), true ) ) {
continue;
}
/**
* The WooCommerce order.
*
* @var \WC_Order $wc_order
*/
$wc_order->update_status(
$new_status,
$status_message
);
if ( $order->intent() === 'CAPTURE' ) {
$wc_order->payment_complete();
} else {
$wc_order->update_status(
'on-hold',
__( 'Payment can be captured.', 'woocommerce-paypal-payments' )
);
}
$this->logger->log(
'info',
sprintf(

View file

@ -134,15 +134,7 @@ class CheckoutOrderCompleted implements RequestHandler {
if ( ! in_array( $wc_order->get_status(), array( 'pending', 'on-hold' ), true ) ) {
continue;
}
/**
* The WooCommerce order.
*
* @var \WC_Order $wc_order
*/
$wc_order->update_status(
'processing',
__( 'Payment received.', 'woocommerce-paypal-payments' )
);
$wc_order->payment_complete();
$this->logger->log(
'info',
sprintf(