<%@ Language="JScript" %> <% //***************************************************************************** // // actions/custommerchant.actions6.asp // // GoLive actions for CustomMerchant. // // ADOBE SYSTEMS INCORPORATED // Copyright 1999-2002 Adobe Systems Incorporated. All Rights Reserved. // // NOTICE: Notwithstanding the terms of the Adobe GoLive End User // License Agreement, Adobe permits you to reproduce and distribute this // file only as an integrated part of a web site created with Adobe // GoLive software and only for the purpose of enabling your client to // display their web site. All other terms of the Adobe license // agreement remain in effect. // // ***************************************************************************** // CART ACTIONS // // ----------------------------------------------------------------------------- // Dispatch a CustomMerchant action over http to the provider. function DoCMAction(providerURL, action, merchantId, shopperId, args) { var queryString = "action=" + action; queryString += "&merchant-id=" + merchantId; queryString += "&shopper-id=" + shopperId; if (typeof(args) == "object") { for (var key in args) { args[key] = urlencode(args[key]); } queryString += "&" + queryArrayToString(args); } return GetHTTPResultsAsText(providerURL, queryString); } // ----------------------------------------------------------------------------- function AddToCart(providerURL, merchantId, shopperId) { // // Collect the known parameters: // var args = new Array; args["sku"] = Request.Form("$sku"); args["description"] = Request.Form("$description"); args["unit-price"] = Request.Form("$unit-price"); // // Collect anything else that appeared in the form: // var e = new Enumerator(Request.Form); for (; !e.atEnd(); e.moveNext()) { var name = e.item(); if (name.charAt(0) == '$') { continue; } var indexed = name.search(/\[(.+)\]/); if (indexed > 0) { var fieldName = name.slice(0, indexed); args[fieldName] = Request.Form(name); } else { args[name] = Request.Form(name); } } var result = DoCMAction(providerURL, "add-to-cart", merchantId, shopperId, args); if (result.indexOf("$error") == 0) { Redirect(String(Request.Form("$add-to-cart_failure"))); } else if (result.indexOf("") > 0) { Redirect(String(Request.Form("$add-to-cart_failure"))); } Redirect(String(Request.Form("$add-to-cart_success"))); } // ----------------------------------------------------------------------------- function UpdateCart(providerURL, merchantId, shopperId) { // // Collect form arguments: // var args = new Array; var e = new Enumerator(Request.Form); for (; !e.atEnd(); e.moveNext()) { var name = e.item(); if (name.match(/(.*)(\[[0-9]+\])/)) { if (RegExp.$1 == "$key") { args["sku" + RegExp.$2] = Request.Form(name); } else { args[name] = Request.Form(name); } } } var result = DoCMAction(providerURL, "change-cart-props", merchantId, shopperId, args); if (result.indexOf("$error") == 0) { Redirect(String(Request.Form("$change-cart-props_failure"))); } else if (result.indexOf("") > 0) { Redirect(String(Request.Form("$change-cart-props_failure"))); } else { Redirect(String(Request.Form("$change-cart-props_success"))); } } // ----------------------------------------------------------------------------- function ClearCart(providerURL, merchantId, shopperId) { var result = DoCMAction(providerURL, "clear-cart", merchantId, shopperId); if (result.indexOf("$error") == 0) { Redirect(String(Request.Form("$clear-cart_failure"))); } Redirect(String(Request.Form("$clear-cart_success"))); } // ***************************************************************************** // ORDER FORM ACTIONS // // ----------------------------------------------------------------------------- function UpdateOrder(providerURL, merchantId, shopperId) { // // Collect form arguments: // var args = new Array; var e = new Enumerator(Request.Form); for (; !e.atEnd(); e.moveNext()) { var name = e.item(); if (name.charAt(0) == '$') { continue; } var indexed = name.search(/\[(.+)\]/); if (indexed > 0) { var fieldName = name.slice(0, indexed); args[fieldName] = Request.Form(name); } else { args[name] = Request.Form(name); } } var result = DoCMAction(providerURL, "change-order-form-props", merchantId, shopperId, args); if (result.indexOf("$error") == 0) { Redirect(String(Request.Form("$change-order-form-props_failure"))); } else if (result.indexOf("") > 0) { Redirect(String(Request.Form("$change-order-form-props_failure"))); } Redirect(String(Request.Form("$change-order-form-props_success"))); } // ----------------------------------------------------------------------------- function PurchaseNow(providerURL, merchantId, shopperId) { // // Collect form arguments: // var args = new Array; var e = new Enumerator(Request.Form); for (; !e.atEnd(); e.moveNext()) { var name = e.item(); if (name.charAt(0) == '$') { continue; } var indexed = name.search(/\[(.+)\]/); if (indexed > 0) { var fieldName = name.slice(0, indexed); args[fieldName] = Request.Form(name); } else { args[name] = Request.Form(name); } } var result = DoCMAction(providerURL, "change-order-form-props", merchantId, shopperId, args); if (result.indexOf("$error") == 0) { Redirect(String(Request.Form("$purchase_failure"))); } else if (result.indexOf("") > 0) { Redirect(String(Request.Form("$purchase_failure"))); } result = DoCMAction(providerURL, "purchase", merchantId, shopperId); if (result.indexOf("$error") == 0) { Redirect(String(Request.Form("$purchase_failure"))); } else if (result.indexOf("") > 0) { Redirect(String(Request.Form("$purchase_failure"))); } Redirect(String(Request.Form("$purchase_success"))); } //----------------------------------------------------------------------------- // Dispatch var providerURL = Request.Form("$provider-url"); var merchantId = Request.Form("$merchant-id"); var shopperId = Request.Form("$shopper-id"); if (Request("$AddToCart").Count > 0 || Request("$AddToCart.x").Count > 0) { AddToCart(providerURL, merchantId, shopperId); } else if (Request("$UpdateTotals").Count > 0 || Request("$UpdateTotals.x").Count > 0) { UpdateCart(providerURL, merchantId, shopperId); } else if (Request("$ClearCart").Count > 0 || Request("$ClearCart.x").Count > 0) { ClearCart(providerURL, merchantId, shopperId); } else if (Request("$UpdateOrder").Count > 0 || Request("$UpdateOrder.x").Count > 0) { UpdateOrder(providerURL, merchantId, shopperId); } else if (Request("$PurchaseNow").Count > 0 || Request("$PurchaseNow.x").Count > 0) { PurchaseNow(providerURL, merchantId, shopperId); } else { // no default action Response.End(); } %>