Rollback WCAPI create_order if exception is thrown after wc_create_order

When you use the api to create an order and specify an method_id for
the payment details, but no method_title. You recieve a WP_Error as the
response but a pending order of $0 is still created.
This commit is contained in:
matttallan 2015-03-13 15:53:30 +10:00
parent a66d627c70
commit 4d0e0b71f3
1 changed files with 7 additions and 0 deletions

View File

@ -356,9 +356,12 @@ class WC_API_Orders extends WC_API_Resource {
* @return array
*/
public function create_order( $data ) {
global $wpdb;
$data = isset( $data['order'] ) ? $data['order'] : array();
$wpdb->query( 'START TRANSACTION' );
try {
// permission check
@ -463,10 +466,14 @@ class WC_API_Orders extends WC_API_Resource {
do_action( 'woocommerce_api_create_order', $order->id, $data, $this );
$wpdb->query( 'COMMIT' );
return $this->get_order( $order->id );
} catch ( WC_API_Exception $e ) {
$wpdb->query( 'ROLLBACK' );
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
}
}