adding to cart with javascript - how to use HMAC?

puremoxiepuremoxie Member
in Help
Hi, I'm trying to add items to the cart using javascript on the checkout page (using code in the custom footer). I have HMAC required. Is there a javascript version of the PHP get_verification() function?

Context: This is related to automatically adding and removing shipping box products depending on the other products in the cart I have posted about in other messages.
Comments
  • fc_adamfc_adam FoxyCart Team
    @puremoxie,

    Good question. There isn't a javascript version of the product signing functionality - mainly because as it would be clientside javascript, a user would have access to your signing secret.

    For adding signed products on the checkout, your best bet will be to pre-sign them manually, and then use the signed add to carts within your checkout javascript.

    Would that approach work for what you're needing?
  • puremoxiepuremoxie Member
    @fc_adam ,

    That makes sense, but how exactly do I "pass" the pre-signed products from my site over to the checkout page so they can be added from the checkout javascript?
  • puremoxiepuremoxie Member
    Oh, I think you mean that I would manually create the signed URL strings necessary for adding to the cart and just have those hard coded in my checkout javascript. I will try that, but let me know if that's not what you meant.
  • fc_adamfc_adam FoxyCart Team
    edited May 2
    @puremoxie,

    Sorry for not being more specific in my last reply. Assuming it would be one of a static set of products that you would be dynamically adding on the checkout, you would embed the signed product links directly within your javascript on the checkout.

    You could manually sign the links from the "Sample Code" section of the administration, and then include the signed links directly within your javascript in the custom footer or checkout template (depending where you're including your javascript).

    Does that help clarify?

    [edit] Looks like we posted at the same time there, and that we're both on the same page :smile:
Sign In or Register to comment.