diff --git a/payment_ubercart.info b/payment_ubercart.info
index 3cf158c..54e6aa7 100644
--- a/payment_ubercart.info
+++ b/payment_ubercart.info
@@ -7,5 +7,6 @@ dependencies[] = uc_payment
 test_dependencies[] = xtools
 package = Payment
 files[] = tests/PaymentUbercartCallablesWebTestCase.test
+files[] = tests/PaymentUbercartCheckoutWebTestCase.test
 files[] = tests/PaymentUbercartDeleteOrderWebTestCase.test
 files[] = tests/PaymentUbercartMenuRouterItemPermissionWebTestCase.test
diff --git a/payment_ubercart.module b/payment_ubercart.module
index 015e58f..0a284f0 100644
--- a/payment_ubercart.module
+++ b/payment_ubercart.module
@@ -212,8 +212,8 @@ function payment_ubercart_callback($op, &$order, array $form = NULL, array &$for
   // Checkout form submission.
   elseif ($op == 'cart-process') {
     $payment = $form_state['payment'];
-    $order_id_save = (bool) $payment->pid;
     entity_save('payment', $payment);
+    $order_id_save = (bool) $payment->pid;
     if ($order_id_save) {
       payment_ubercart_order_id_save($payment);
     }
diff --git a/tests/PaymentUbercartCheckoutWebTestCase.test b/tests/PaymentUbercartCheckoutWebTestCase.test
new file mode 100644
index 0000000..09a50ac
--- /dev/null
+++ b/tests/PaymentUbercartCheckoutWebTestCase.test
@@ -0,0 +1,54 @@
+<?php
+
+class PaymentUbercartCheckoutWebTestCase extends PaymentWebTestCase {
+
+  static function getInfo() {
+    return array(
+      'name' => 'Checkout',
+      'group' => 'Payment for Ubercart',
+      'dependencies' => array('payment_ubercart'),
+    );
+  }
+
+  function setUp(array $modules = array()) {
+    parent::setUp($modules + array('paymentmethodbasic', 'payment_ubercart', 'uc_cart'));
+  }
+
+  function testCheckout() {
+    // Create payment method.
+    $payment_method = $this->paymentMethodCreate(0, payment_method_controller_load('PaymentMethodBasicController'));
+    entity_save('payment_method', $payment_method);
+
+    // Create a user.
+    $user = $this->drupalCreateUser(array('create product content', 'create orders'));
+    $this->drupalLogin($user);
+
+    // Set up the store.
+    $this->drupalPost('node/add/product', array(
+      'title' => 'foo',
+      'model' => 'bar',
+      'sell_price' => '12.34',
+    ), t('Save'));
+
+    // Perform the checkout.
+    $this->drupalPost(NULL, array(), t('Add to cart'));
+    $this->drupalPost(NULL, array(), t('Checkout'));
+    $values = array();
+    foreach (array('delivery', 'billing') as $type) {
+      $values['panes[' . $type . '][' . $type . '_first_name]'] = 'foo';
+      $values['panes[' . $type . '][' . $type . '_last_name]'] = 'foo';
+      $values['panes[' . $type . '][' . $type . '_street1]'] = 'foo';
+      $values['panes[' . $type . '][' . $type . '_city]'] = 'foo';
+      $values['panes[' . $type . '][' . $type . '_zone]'] = 1;
+      $values['panes[' . $type . '][' . $type . '_postal_code]'] = 'foo';
+    }
+    $this->drupalPost(NULL, $values, t('Review order'));
+    $this->drupalPost('cart/checkout/review', array(), t('Submit order'));
+    $pids = payment_ubercart_pids_load(1);
+    $payment = entity_load_single('payment', reset($pids));
+    $this->assertTrue((bool) $payment);
+    if ($payment) {
+      $this->assertEqual($payment->getStatus()->status, PAYMENT_STATUS_SUCCESS);
+    }
+  }
+}
\ No newline at end of file
