![]() |
17. Internet Commerce
<MvCOMMERCE> Tag
The <MvCOMMERCE> tag is the point of communications between a Miva Script application and a commerce library.
The <MvCOMMERCE> block is made up of the following:
- a start tag (<MvCOMMERCE>)
- three attributes
- An end-tag </MvCOMMERCE>
The commerce library performs its functions and passes the data back to the Miva Script application.
The output from the commerce library is a binary tree that allows the library to make results available to a Miva Script application.
Commerce Library Exported Functions
A commerce library communicates with a Miva Script application through the Miva Engine. When the Miva Engine encounters the <MvCOMMERCE> tag in a Miva Script application, it consults its list of registered commerce libraries. If a matching commerce library is found, the Miva Engine loads the corresponding DLL.
To develop a commerce library for a Miva Script application, the DLL must export the following four functions:
- miva_commerce_init
- miva_commerce_loop
- miva_commerce_cleanup
- miva_commerce_error
All communication from a Miva commerce library to the Miva Script application is through these four exported functions.
miva_commerce_init
This function is called when the Miva Engine encounters a <MvCOMMERCE> block. Its purpose is to initialize any data that will be used inside the <MvCOMMERCE> block. The DLL can store any application-specific values in the "data" parameter. This parameter is passed to the other exported functions.
Syntax:
- Miva_Commerce_Status miva_commerce_init ( Miva_Context context,
- void **data,
- const char *method,
- const char *action,
- Miva_VariableList input,
- Miva_VariableTree output );
Parameters
Return Value
miva_commerce_loop
When miva_commerce_init returns MIVA_COMMERCE_OK, the Miva Engine calls the miva_commerce_loop function.
This function is called once per iteration of a <MvCOMMERCE> block. The parameter "iteration" indicates the number of times that miva_commerce_loop has been called.
Syntax:
- Miva_Commerce_Status miva_commerce_loop ( Miva_Context context,
- void **data,
- const char *method,
- const char *action,
- Miva_VariableList input,
- Miva_VariableTree output,
- int iteration );
Parameters
Return Value
The action that the Miva Engine takes is dependent on the return value of the miva_commerce_loop.
miva_commerce_cleanup
Whenever the Miva Engine has completed using the commerce library, regardless of the return value, it calls miva_commerce_cleanup.
Syntax:
- void miva_commerce_cleanup (
- Miva_Context context,
- void **data,
- const char *method,
- const char *action,
- Miva_VariableList input );
Parameters
Return Value
miva_commerce_error
If either miva_commerce_init or miva_commerce_loop returns MIVA_COMMERCE_ERROR, the Miva Engine calls miva_commerce_error to receive a description of the error. It makes this call prior to calling miva_commerce_cleanup.
This function is called by the Miva Engine to receive a description of an error. It is called prior to calling miva_commerce_cleanup.
Syntax
- const char *miva_commerce_error (
- Miva_Context context,
- void **data,
- const char *method,
- const char *action,
- Miva_VariableList input );
Parameters
Return Value
The text for the error is returned.
Using UPS Quick Cost
<MvCOMMERCE> supports the 'UPSRSS' METHOD. This enables your program to submit information about a shipment (weight, origin, destination, etc.) to UPS's Quick Cost calculator and receive back the shipping cost and other information. <MvCOMMERCE> provides a convenient way to do pre- and post-processing of UPS shipping information without having to prepare your own CGI scripts to do so. UPS's documentation on Quick Cost is available from http://www.ups.com/tools/tools.html.
Quick Cost can calculate costs only for shipments that originate in the United States.
The basic format of <MvCOMMERCE> is as follows:
- <MvCOMMERCE
- METHOD = "UPSRSS"
- ACTION = "http://www.ups.com/using/services/rave/qcost_dss.cgi"
- FIELDS="var1, var2,...">
The values of ACTION and METHOD must be exactly as indicated. The value of the FIELDS attribute is a series of input variables giving information about the shipment. These variables will generally get their values from a form in your document. There are specific variable names (listed below) that must be used; these variables are case-sensitive.
To set up UPS processing, follow these steps:
- Create a form that contains fields for each input variable (that is, each type of information) that you want to send to the Quick Cost calculator. Some variables are required; others are optional.
- The name (NAME attribute) of each field must be the same as the corresponding variable name.
- Choose form objects that are appropriate to the type of data: for example, check boxes for yes/no choices, text boxes for text, and radio buttons or drop-down lists for choices from a defined group.
- Set the form's ACTION attribute to point to the Miva Script program containing the <MvCOMMERCE> tag. If it's the same as the script containing the form, just use the macro &[documenturl]; as the value of ACTION.
- Set the form's METHOD attribute to 'POST'.
- Include each of the input variables from the form in the FIELDS attribute of <MvCOMMERCE>. The order is unimportant, and you need include only those variables that actually appear in the form.
- Between the <MvCOMMERCE> and </MvCOMMERCE> tags, insert code that processes the information sent back by the Quick Cost calculator. The information is sent back in the output variables listed below. You don't have to use all of these variables in your code, just the ones you need. The processing that you do can be as simple as just displaying values of certain variables, or you can do more complex processing as desired. As a minimum, you should probably display the cost (totalchrg), or an error message (errmsg) if there is one.
UPS Input Variables
The table below displays the input variables that you can use in a form and pass to the Quick Cost calculator using the FIELDS attribute. The Description column identifies the type(s) of value that each variable must have. Required variables are bold and in red. Contact UPS or consult their online documentation for detailed definitions and service descriptions.
Return Fields
The following fields are returned inside the <MvCOMMERCE>...</MvCOMMERCE>:
- <MvCOMMERCE
- METHOD = "UPSRSS"
- ACTION = "http://www.ups.com/using/services/rave/qcost_dss.cgi"
- FIELDS = "{ l.fields }">
Returned Fields
AcceptUPSLicenseAgreement = <MvEVAL EXPR = "{ g.AcceptUPSLicenseAgreement}"
UPSOnLine = <MvEVAL EXPR = "{ s.UPSOnLine }">
AppVersion = <MvEVAL EXPR = "{ s.AppVersion }">
ReturnCode = <MvEVAL EXPR = "{ s.ReturnCode }">
MessageText = <MvEVAL EXPR = "{ s.MessageText }">
ActionCode = <MvEVAL EXPR = "{ s.ActionCode }">
ServiceLevelCode = <MvEVAL EXPR = "{ s.ServiceLevelCode }">
ShipperPostalCode = <MvEVAL EXPR = "{ s.ShipperPostalCode }">
ShipperCountry = <MvEVAL EXPR = "{ s.ShipperCountry }">
ConsigneePostalCode = <MvEVAL EXPR = "{ s.ConsigneePostalCode }">
ConsigneeCountry = <MvEVAL EXPR = "{ s.ConsigneeCountry }">
DeliveryZone = <MvEVAL EXPR = "{ s.DeliveryZone }">
PackageActualWeight = <MvEVAL EXPR = "{ s.PackageActualWeight }">
ProductCharge = <MvEVAL EXPR = "{ s.ProductCharge }">
AccessorySurcharge = <MvEVAL EXPR = "{ s.AccessorySurcharge }">
TotalCharge = <MvEVAL EXPR = "{ s.TotalCharge }">
CommitTime = <MvEVAL EXPR = "{ s.CommitTime }">
Example
The file http://www.miva.com/products/engine/mia/templates/frame-ups.html gives an example of using UPSCost. Here is a shorter example that uses only required fields.
- <HTML><HEAD><TITLE>UPS Cost Calculator</TITLE></HEAD>
- <BODY BGCOLOR = "#ffffff">
- <MvIF EXPR = "{ g.AcceptUPSLicenseAgreement EQ 'yes' }">
- <MvCOMMENT> This branch is expected if the form has been submitted.</MvCOMMENT>
- <TABLE BORDER = 0 WIDTH = "100%">
- <TR><TD>
- <B>Product</B>
- </TD>
- <TD WIDTH = "100%">
- <B>Name</B>
- </TD><TD>
- <B>Price</B>
- </TD></TR>
- <TR><TD COLSPAN = 3>
- <HR>
- </TD></TR>
- <MIVA MvCOMMERCE_Error = "nonfatal, nodisplay">
- <MvCOMMERCE METHOD = "UPSRSS"
- ACTION = "http://www.ups.com/using/services/rave/qcost_dss.cgi"
- FIELDS ="AcceptUPSLicenseAgreement,
- ActionCode,
- ServiceLevelCode,
- RateChart,
- ShipperPostalCode,
- ConsigneePostalCode,
- ConsigneeCountry,
- PackageActualWeight,
- ResidentialInd,
- PackagingType">
- <MvIF EXPR = "{ s.ReturnCode NE '0000' }">
- <MvASSIGN NAME = "g.Error" VALUE = "{ s.MessageText }">
- <MvCOMMERCESTOP>
- <MvELSE>
- <TR><TD>
- <MvEVAL EXPR = "{ s.ServiceLevelCode }">
- </TD><TD>
- <MvIF EXPR = "{ s.ServiceLevelCode EQ '1DM' }">
- Next Day Early AM
- </MvIF>
- <MvIF EXPR = "{ s.ServiceLevelCode EQ '1DA' }">
- Next Day Air
- </MvIF>
- <MvIF EXPR = "{ s.ServiceLevelCode EQ '1DAPI' }">
- Next Day Air Intra (Puerto Rico)
- </MvIF>
- <MvIF EXPR = "{ s.ServiceLevelCode EQ '1DP' }">
- Next Day Air Saver
- </MvIF>
- <MvIF EXPR = "{ s.ServiceLevelCode EQ '2DM' }">
- 2nd Day Air AM
- </MvIF>
- <MvIF EXPR = "{ s.ServiceLevelCode EQ '2DA' }">
- 2nd Day Air
- </MvIF>
- <MvIF EXPR = "{ s.ServiceLevelCode EQ '3DS' }">
- 3 Day Select
- </MvIF>
- <MvIF EXPR = "{ s.ServiceLevelCode EQ 'GND' }">
- Ground
- </MvIF>
- <MvIF EXPR = "{ s.ServiceLevelCode EQ 'STD' }">
- Canada Standard
- </MvIF>
- <MvIF EXPR = "{ s.ServiceLevelCode EQ 'XPR' }">
- Worldwide Express
- </MvIF>
- <MvIF EXPR = "{ s.ServiceLevelCode EQ 'XDM' }">
- Worldwide Express Plus
- </MvIF>
- <MvIF EXPR = "{ s.ServiceLevelCode EQ 'XPD' }">
- Worldwide Expedited
- </MvIF>
- </TD><TD>
- <MvEVAL EXPR = "{ s.TotalCharge }">
- </TD></TR>
- </MvIF>
- </MvCOMMERCE>
- </TABLE>
- <MvIF EXPR = "{ MvCOMMERCE_Error }">
- <P><B><MvEVAL EXPR = "{ MvCOMMERCE_Error }"></B></P>
- <MvELSE>
- <MvIF EXPR = "{ g.Error }">
- <P><B><MvEVAL EXPR = "{ g.Error }"></B></P>
- </MvIF>
- </MvIF>
- <P><A HREF = "&[s.documenturl];">Calculate shipping for another package.</A></P>
- <MvELSE>
- <FORM METHOD = "post" ACTION = "&[s.documenturl];">
- <TABLE BORDER = 0>
- <TR><TD>
- </TD><TD>
- <B>AcceptUPSLicenseAgreement</B>
- <INPUT TYPE = "checkbox" NAME = "AcceptUPSLicenseAgreement" VALUE = "yes" CHECKED>
- </TD></TR>
- <TR><TD>
- <B>ActionCode:</B>
- </TD><TD>
- <INPUT TYPE = "radio" NAME = "ActionCode" VALUE = 4 CHECKED> All Services<BR>
- <INPUT TYPE = "radio" NAME = "ActionCode" VALUE = 3> Specified Service Only<BR>
- </TD></TR>
- <TR><TD>
- <B>ServiceLevelCode:</B>
- </TD><TD>
- <SELECT NAME = "ServiceLevelCode">
- <OPTION VALUE = "1DM">Next Day Early AM
- <OPTION VALUE = "1DA">Next Day Air
- <OPTION VALUE = "1DAPI">Next Day Air Intra (Puerto Rico)
- <OPTION VALUE = "1DP">Next Day Air Saver
- <OPTION VALUE = "2DM">2nd Day Air AM
- <OPTION VALUE = "2DA">2nd Day Air
- <OPTION VALUE = "3DS">3 Day Select
- <OPTION VALUE = "GND">Ground
- <OPTION VALUE = "STD">Canada Standard
- <OPTION VALUE = "XPR">Worldwide Express
- <OPTION VALUE = "XDM">Worldwide Express Plus
- <OPTION VALUE = "XPD">Worldwide Expedited
- </SELECT>
- </TD></TR>
- <TR><TD>
- <B>RateChart:</B>
- </TD><TD>
- <SELECT NAME = "RateChart">
- <OPTION VALUE = "Customer Counter" SELECTED>Customer Counter</OPTION>
- <OPTION VALUE = "Letter Center">Letter Center</OPTION>
- <OPTION VALUE = "On Call Air">On Call Air</OPTION>
- <OPTION VALUE = "One Time Pickup">One Time Pickup</OPTION>
- <OPTION VALUE = "Regular Daily Pickup">Regular Daily Pickup</OPTION>
- </SELECT>
- </TD></TR>
- <TR><TD>
- <B>ShipperPostalCode:</B>
- </TD><TD>
- <INPUT TYPE = "text" NAME = "ShipperPostalCode" SIZE = 10 VALUE = "92117">
- </TD></TR>
- <TR><TD ALIGN = "left">
- <B>ConsigneePostalCode:</B>
- </TD><TD ALIGN ="left">
- <INPUT TYPE = "text" NAME = "ConsigneePostalCode" SIZE = 10 VALUE = "44145">
- </TD></TR>
- <TR><TD ALIGN = "left">
- <B>ConsigneeCountry:</B>
- </TD><TD ALIGN = "left">
- <INPUT TYPE = "text" NAME = "ConsigneeCountry" SIZE = 4 VALUE = "US">
- </TD></TR>
- <TR><TD ALIGN = "left">
- <B>PackageActualWeight:</B>
- </TD><TD ALIGN = "left">
- <INPUT TYPE = "text" NAME = "PackageActualWeight" SIZE = 10 VALUE = "5">
- </TD></TR>
- <TR><TD>
- <B>ResidentialInd:</B>
- </TD><TD ALIGN = "left">
- <SELECT NAME = "ResidentialInd">
- <OPTION VALUE = "0" SELECTED>Commercial</OPTION>
- <OPTION VALUE = "1">Residential</OPTION>
- </SELECT>
- </TD></TR>
- <TR><TD>
- <B>PackagingType:</B>
- </TD><TD ALIGN = "left">
- <SELECT NAME = "PackagingType">
- <OPTION VALUE = "00" SELECTED>Shipper Supplied Packaging</OPTION>
- <OPTION VALUE = "01">UPS Letter Envelope</OPTION>
- <OPTION VALUE = "03">UPS Tube</OPTION>
- <OPTION VALUE = "21">UPS Express Box</OPTION>
- <OPTION VALUE = "24">International UPS 25KG Box</OPTION>
- <OPTION VALUE = "25">International UPS 10KG Box</OPTION>
- </SELECT>
- </TD></TR>
- <TR><TD>
- </TD><TD ALIGN = "left">
- <INPUT TYPE = "submit" VALUE = "Calculate">
- </TD></TR>
- </TABLE>
- </FORM>
- </MvIF>
- </BODY>
- </HTML>
| Join Our Mailing List | Privacy Policy | Store Policies | Contact Us |
| © Copyright 2008 Miva Merchant. All Rights Reserved. |