Giter Site home page Giter Site logo

Comments (6)

joshrainwater avatar joshrainwater commented on September 21, 2024

Confirmed where the addToCart and checkout are on two separate pages, and when they're piggybacked together (see #6) As soon as I remove the item from preorder, the list of regular error messages displays.

from responsive_checkout.

perrytew avatar perrytew commented on September 21, 2024

Josh,
Hey. It's recommended to do the checkout in at least two steps. The first containing the new item(s), and then the checkout. I speculate that the preorder warning is happening during an update routine that precedes the big validation routine.

Are you doing a POST or PUT to /rest/cart and then doing your call to /rest/cart/checkout? If not, please do so.

Thanks,
Perry

from responsive_checkout.

joshrainwater avatar joshrainwater commented on September 21, 2024

So I think I figured out why I'm getting the results I am. It seems that everything works fine, until I add the arbitraryUnitCost, and then it seems to return the preorder error with the cart regardless of whether or not all the rest of the info is right.

Run the below to see what I mean. If you run it with our data, MerchantID 'PUMPI' and item '463', it returns the errored CC# (intentionally). If you run it with 'PUMPI' and 'PACK_SA_SM_B' as an item, it returns the preorder error.

<html>
<head>
  <script type='text/javascript' src='//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js'></script>
  <script type='text/javascript' src='//cdnjs.cloudflare.com/ajax/libs/json2/20130526/json2.min.js'></script>

  <script type='text/javascript'>

    if (typeof String.prototype.trim === 'undefined') {
      String.prototype.trim = function () {
        return this.replace(/^\s+|\s+$/g, '');
      };
    }

    function checkout() {

      var merchantId = jQuery('#merchantId').val();
      var itemId = jQuery('#itemId').val();
      var themeCode = jQuery('#themeCode').val() || 'DFLT';

      var cart = {
        'merchantId': merchantId,
        'cartId': '', // will be populated by call

        "customField1": 'blah blah blah',
        "customField2": 'perhaps an affiliate id here?',
//        "coupons": [
//          {couponCode: '10OFF'}
//        ], // here is a coupon for $10 off the order
        "advertisingSource": "Radio",
        "screenBrandingThemeCode": themeCode, // The demo account has a second them set up using the code CSTM
        "shippingMethod": "FedEx: 2-Day",
        "shipToFirstName": "Testy",
        "shipToLastName": "Testerson",
        "shipToTitle": "Sir",
        "shipToCompany": "Ultra Trains",
        "shipToAddress1": "55 Main Street",
        "shipToAddress2": "Suite 101",
        "shipToCity": "Duluth",
        "shipToState": "GA",
        "shipToPostalCode": "30097",
        "shipToCountry": "United States",
        "shipToPhone": "555-555-1212",
        "shipToEveningPhone": "5555553434", // notice the different format?
        "billToDayPhone": "555-555-1212",
        "billToEveningPhone": "5555551212",
        "billToFirstName": "Smith",
        "billToLastName": "Joe",
        "billToTitle": "Chief",
        "billToCompany": "Widgets, INC",
        "billToAddress1": "2000 Montana Dr",
        "billToAddress2": "",
        "billToCity": "Duluth",
        "billToState": "GA",
        "billToPostalCode": "30097",
        "billToCountry": "United States",
        "email": "[email protected]",
        "emailConfirm": "[email protected]",
        // "paymentMethod": 'Purchase Order',
        // "purchaseOrderNumber": "000",
        "paymentMethod": "Credit Card",
        "creditCardType": "VISA",
        "creditCardNumber": "4444333322220000",
        "creditCardExpirationMonth": 12,
        "creditCardExpirationYear": 1942,  // Notice the year is intentionally broken
        "creditCardVerificationNumber": "123",
        'items': [
          {'itemId': itemId, 'quantity': 1, 'arbitraryUnitCost': 2.00}
        ]
      };

      // Notice: The checkout call does not take a cart.  It takes a CheckoutRequest which contains a cart.
      // Since the checkout process hands of to UltraCart to handle upsells, etc., we must also provide the
      // return point.
      var checkoutRequest = {
        'cart': cart,
        errorParameterName: 'error', // if there are errors after the handoff, the redirect page will receive those errors using this http parameter
        errorReturnUrl: document.URL, // this same page.
        secureHostName: null // can be null.  defaults to secure.ultracart.com if null.  could also be www.mystore.com if that was your url.
        // the secureHostName is where the checkout finishes on (receipt).  many merchants have dozens of sites.  So, if this isn't secure.ultracart and
        // you have more than one, you must specify it.
      };

      jQuery.ajax({
        // url: '/rest/cart/checkout',
        url: 'rest_proxy.php?_url=rest/cart',
        type: 'POST', // Notice
        headers: { "cache-control": "no-cache" },
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(cart),
        dataType: 'json'
      }).done(function (cart) {

            checkoutRequest.cart = cart;
            var txt = JSON.stringify(checkoutRequest, null, '  ');
            var pre = jQuery('<pre>');
            pre.text(txt);
            var resultsDiv = jQuery('#cartResults');
            resultsDiv.html('').append(pre);
            console.log(checkoutRequest);

            jQuery.ajax({
              // url: '/rest/cart/checkout',
              url: 'rest_proxy.php?_url=rest/cart/checkout',
              type: 'POST', // Notice
              headers: { "cache-control": "no-cache" },
              contentType: 'application/json; charset=UTF-8',
              data: JSON.stringify(checkoutRequest),
              dataType: 'json'
            }).done(function (checkoutResult) {

                  var txt = JSON.stringify(checkoutResult, null, '  ');
                  var pre = jQuery('<pre>');
                  pre.text(txt);

                  var resultsDiv = jQuery('#checkoutResults');
                  if (checkoutResult && checkoutResult.redirectToUrl) {
                    resultsDiv.append("<div><a target='_blank' href='" + checkoutResult.redirectToUrl + " '>" + checkoutResult.redirectToUrl + "</a></div>");
                  }
                  resultsDiv.html('').append(pre);
                });


          });


    }


    window.onload = function () {
    };


    function log(msg) {
      var div = document.getElementById('log');
      var txtNode = document.createTextNode(msg);
      var br = document.createElement('br');
      div.appendChild(txtNode);
      div.appendChild(br);
    }

  </script>
</head>
<body>

<table>
  <tr>
    <td>Merchant ID:</td>
    <td><input type='text' id='merchantId' value=''/></td>
  </tr>
  <tr>
    <td>Item ID:</td>
    <td><input type='text' id='itemId' value=''/></td>
  </tr>
  <tr>
    <td>Theme Code:</td>
    <td><input type='text' id='themeCode' value=''/> (optional)</td>
  </tr>

  <tr>
    <td colspan='2'><input type='button' value='Create Order with Item' onclick='checkout()'/></td>
  </tr>
</table>
<div id="cartResults"></div>
<div id='log' style='margin-top:20px;'>
  <div style='font-weight:bold'>Log Events Will Appear Below:</div>
</div>
<div id="checkoutResults"></div>


</body>
</html>

from responsive_checkout.

perrytew avatar perrytew commented on September 21, 2024

Josh,
What's the status of this? Sorry - I've been side tracked by our StoreFront go live.

from responsive_checkout.

perrytew avatar perrytew commented on September 21, 2024

Oh yeah, I did notice something. You don't want to do the entire order in one fell swoop. Pass the cart to the update method (POST /rest/cart) and get it back, checking for pre-order messages. Then pass that cart to the checkout method. This will allow all the errors and warning to process correctly.

from responsive_checkout.

perrytew avatar perrytew commented on September 21, 2024

Josh,
Reopen this ticked if this is still an issue. Thanks.

from responsive_checkout.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.