protected void forwardCheckout(
      ActionRequest actionRequest, ActionResponse actionResponse, ShoppingOrder order)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    ShoppingCart cart = ShoppingUtil.getCart(actionRequest);

    ShoppingWebComponentProvider shoppingWebComponentProvider =
        ShoppingWebComponentProvider.getShoppingWebComponentProvider();

    SettingsFactory settingsFactory = shoppingWebComponentProvider.getSettingsFactory();

    ShoppingGroupServiceSettings shoppingGroupServiceSettings =
        settingsFactory.getSettings(
            ShoppingGroupServiceSettings.class,
            new GroupServiceSettingsLocator(
                themeDisplay.getScopeGroupId(), ShoppingConstants.SERVICE_NAME));

    String returnURL =
        ShoppingUtil.getPayPalReturnURL(
            ((ActionResponseImpl) actionResponse).createActionURL(), order);
    String notifyURL = ShoppingUtil.getPayPalNotifyURL(themeDisplay);

    if (shoppingGroupServiceSettings.usePayPal()) {
      double total =
          ShoppingUtil.calculateTotal(
              cart.getItems(),
              order.getBillingState(),
              cart.getCoupon(),
              cart.getAltShipping(),
              cart.isInsure());

      String redirectURL =
          ShoppingUtil.getPayPalRedirectURL(
              shoppingGroupServiceSettings, order, total, returnURL, notifyURL);

      actionResponse.sendRedirect(redirectURL);
    } else {
      ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

      ShoppingOrderLocalServiceUtil.sendEmail(order, "confirmation", serviceContext);

      actionResponse.sendRedirect(returnURL);
    }
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    ShoppingOrder newShoppingOrder = _persistence.create(pk);

    newShoppingOrder.setGroupId(RandomTestUtil.nextLong());

    newShoppingOrder.setCompanyId(RandomTestUtil.nextLong());

    newShoppingOrder.setUserId(RandomTestUtil.nextLong());

    newShoppingOrder.setUserName(RandomTestUtil.randomString());

    newShoppingOrder.setCreateDate(RandomTestUtil.nextDate());

    newShoppingOrder.setModifiedDate(RandomTestUtil.nextDate());

    newShoppingOrder.setNumber(RandomTestUtil.randomString());

    newShoppingOrder.setTax(RandomTestUtil.nextDouble());

    newShoppingOrder.setShipping(RandomTestUtil.nextDouble());

    newShoppingOrder.setAltShipping(RandomTestUtil.randomString());

    newShoppingOrder.setRequiresShipping(RandomTestUtil.randomBoolean());

    newShoppingOrder.setInsure(RandomTestUtil.randomBoolean());

    newShoppingOrder.setInsurance(RandomTestUtil.nextDouble());

    newShoppingOrder.setCouponCodes(RandomTestUtil.randomString());

    newShoppingOrder.setCouponDiscount(RandomTestUtil.nextDouble());

    newShoppingOrder.setBillingFirstName(RandomTestUtil.randomString());

    newShoppingOrder.setBillingLastName(RandomTestUtil.randomString());

    newShoppingOrder.setBillingEmailAddress(RandomTestUtil.randomString());

    newShoppingOrder.setBillingCompany(RandomTestUtil.randomString());

    newShoppingOrder.setBillingStreet(RandomTestUtil.randomString());

    newShoppingOrder.setBillingCity(RandomTestUtil.randomString());

    newShoppingOrder.setBillingState(RandomTestUtil.randomString());

    newShoppingOrder.setBillingZip(RandomTestUtil.randomString());

    newShoppingOrder.setBillingCountry(RandomTestUtil.randomString());

    newShoppingOrder.setBillingPhone(RandomTestUtil.randomString());

    newShoppingOrder.setShipToBilling(RandomTestUtil.randomBoolean());

    newShoppingOrder.setShippingFirstName(RandomTestUtil.randomString());

    newShoppingOrder.setShippingLastName(RandomTestUtil.randomString());

    newShoppingOrder.setShippingEmailAddress(RandomTestUtil.randomString());

    newShoppingOrder.setShippingCompany(RandomTestUtil.randomString());

    newShoppingOrder.setShippingStreet(RandomTestUtil.randomString());

    newShoppingOrder.setShippingCity(RandomTestUtil.randomString());

    newShoppingOrder.setShippingState(RandomTestUtil.randomString());

    newShoppingOrder.setShippingZip(RandomTestUtil.randomString());

    newShoppingOrder.setShippingCountry(RandomTestUtil.randomString());

    newShoppingOrder.setShippingPhone(RandomTestUtil.randomString());

    newShoppingOrder.setCcName(RandomTestUtil.randomString());

    newShoppingOrder.setCcType(RandomTestUtil.randomString());

    newShoppingOrder.setCcNumber(RandomTestUtil.randomString());

    newShoppingOrder.setCcExpMonth(RandomTestUtil.nextInt());

    newShoppingOrder.setCcExpYear(RandomTestUtil.nextInt());

    newShoppingOrder.setCcVerNumber(RandomTestUtil.randomString());

    newShoppingOrder.setComments(RandomTestUtil.randomString());

    newShoppingOrder.setPpTxnId(RandomTestUtil.randomString());

    newShoppingOrder.setPpPaymentStatus(RandomTestUtil.randomString());

    newShoppingOrder.setPpPaymentGross(RandomTestUtil.nextDouble());

    newShoppingOrder.setPpReceiverEmail(RandomTestUtil.randomString());

    newShoppingOrder.setPpPayerEmail(RandomTestUtil.randomString());

    newShoppingOrder.setSendOrderEmail(RandomTestUtil.randomBoolean());

    newShoppingOrder.setSendShippingEmail(RandomTestUtil.randomBoolean());

    _shoppingOrders.add(_persistence.update(newShoppingOrder));

    ShoppingOrder existingShoppingOrder =
        _persistence.findByPrimaryKey(newShoppingOrder.getPrimaryKey());

    Assert.assertEquals(existingShoppingOrder.getOrderId(), newShoppingOrder.getOrderId());
    Assert.assertEquals(existingShoppingOrder.getGroupId(), newShoppingOrder.getGroupId());
    Assert.assertEquals(existingShoppingOrder.getCompanyId(), newShoppingOrder.getCompanyId());
    Assert.assertEquals(existingShoppingOrder.getUserId(), newShoppingOrder.getUserId());
    Assert.assertEquals(existingShoppingOrder.getUserName(), newShoppingOrder.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingShoppingOrder.getCreateDate()),
        Time.getShortTimestamp(newShoppingOrder.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingShoppingOrder.getModifiedDate()),
        Time.getShortTimestamp(newShoppingOrder.getModifiedDate()));
    Assert.assertEquals(existingShoppingOrder.getNumber(), newShoppingOrder.getNumber());
    AssertUtils.assertEquals(existingShoppingOrder.getTax(), newShoppingOrder.getTax());
    AssertUtils.assertEquals(existingShoppingOrder.getShipping(), newShoppingOrder.getShipping());
    Assert.assertEquals(existingShoppingOrder.getAltShipping(), newShoppingOrder.getAltShipping());
    Assert.assertEquals(
        existingShoppingOrder.getRequiresShipping(), newShoppingOrder.getRequiresShipping());
    Assert.assertEquals(existingShoppingOrder.getInsure(), newShoppingOrder.getInsure());
    AssertUtils.assertEquals(existingShoppingOrder.getInsurance(), newShoppingOrder.getInsurance());
    Assert.assertEquals(existingShoppingOrder.getCouponCodes(), newShoppingOrder.getCouponCodes());
    AssertUtils.assertEquals(
        existingShoppingOrder.getCouponDiscount(), newShoppingOrder.getCouponDiscount());
    Assert.assertEquals(
        existingShoppingOrder.getBillingFirstName(), newShoppingOrder.getBillingFirstName());
    Assert.assertEquals(
        existingShoppingOrder.getBillingLastName(), newShoppingOrder.getBillingLastName());
    Assert.assertEquals(
        existingShoppingOrder.getBillingEmailAddress(), newShoppingOrder.getBillingEmailAddress());
    Assert.assertEquals(
        existingShoppingOrder.getBillingCompany(), newShoppingOrder.getBillingCompany());
    Assert.assertEquals(
        existingShoppingOrder.getBillingStreet(), newShoppingOrder.getBillingStreet());
    Assert.assertEquals(existingShoppingOrder.getBillingCity(), newShoppingOrder.getBillingCity());
    Assert.assertEquals(
        existingShoppingOrder.getBillingState(), newShoppingOrder.getBillingState());
    Assert.assertEquals(existingShoppingOrder.getBillingZip(), newShoppingOrder.getBillingZip());
    Assert.assertEquals(
        existingShoppingOrder.getBillingCountry(), newShoppingOrder.getBillingCountry());
    Assert.assertEquals(
        existingShoppingOrder.getBillingPhone(), newShoppingOrder.getBillingPhone());
    Assert.assertEquals(
        existingShoppingOrder.getShipToBilling(), newShoppingOrder.getShipToBilling());
    Assert.assertEquals(
        existingShoppingOrder.getShippingFirstName(), newShoppingOrder.getShippingFirstName());
    Assert.assertEquals(
        existingShoppingOrder.getShippingLastName(), newShoppingOrder.getShippingLastName());
    Assert.assertEquals(
        existingShoppingOrder.getShippingEmailAddress(),
        newShoppingOrder.getShippingEmailAddress());
    Assert.assertEquals(
        existingShoppingOrder.getShippingCompany(), newShoppingOrder.getShippingCompany());
    Assert.assertEquals(
        existingShoppingOrder.getShippingStreet(), newShoppingOrder.getShippingStreet());
    Assert.assertEquals(
        existingShoppingOrder.getShippingCity(), newShoppingOrder.getShippingCity());
    Assert.assertEquals(
        existingShoppingOrder.getShippingState(), newShoppingOrder.getShippingState());
    Assert.assertEquals(existingShoppingOrder.getShippingZip(), newShoppingOrder.getShippingZip());
    Assert.assertEquals(
        existingShoppingOrder.getShippingCountry(), newShoppingOrder.getShippingCountry());
    Assert.assertEquals(
        existingShoppingOrder.getShippingPhone(), newShoppingOrder.getShippingPhone());
    Assert.assertEquals(existingShoppingOrder.getCcName(), newShoppingOrder.getCcName());
    Assert.assertEquals(existingShoppingOrder.getCcType(), newShoppingOrder.getCcType());
    Assert.assertEquals(existingShoppingOrder.getCcNumber(), newShoppingOrder.getCcNumber());
    Assert.assertEquals(existingShoppingOrder.getCcExpMonth(), newShoppingOrder.getCcExpMonth());
    Assert.assertEquals(existingShoppingOrder.getCcExpYear(), newShoppingOrder.getCcExpYear());
    Assert.assertEquals(existingShoppingOrder.getCcVerNumber(), newShoppingOrder.getCcVerNumber());
    Assert.assertEquals(existingShoppingOrder.getComments(), newShoppingOrder.getComments());
    Assert.assertEquals(existingShoppingOrder.getPpTxnId(), newShoppingOrder.getPpTxnId());
    Assert.assertEquals(
        existingShoppingOrder.getPpPaymentStatus(), newShoppingOrder.getPpPaymentStatus());
    AssertUtils.assertEquals(
        existingShoppingOrder.getPpPaymentGross(), newShoppingOrder.getPpPaymentGross());
    Assert.assertEquals(
        existingShoppingOrder.getPpReceiverEmail(), newShoppingOrder.getPpReceiverEmail());
    Assert.assertEquals(
        existingShoppingOrder.getPpPayerEmail(), newShoppingOrder.getPpPayerEmail());
    Assert.assertEquals(
        existingShoppingOrder.getSendOrderEmail(), newShoppingOrder.getSendOrderEmail());
    Assert.assertEquals(
        existingShoppingOrder.getSendShippingEmail(), newShoppingOrder.getSendShippingEmail());
  }