OMARS, the Order Management and Reporting Services, is the merchant user's interface to the MIT I/S credit card order processing system. It includes an Application Programming Interface (API) to connect your own Web and E-commerce applications to the system. The API lets client programs enter new orders in your ClearCommerce store just like the point-of-sale Web service does for interactive users.
This manual describes the Java API. This is currently the only API available, although it should be possible to provide API clients in other languages since the client-server communication is based on HTTP-SSL and XML. There are no plans for such ports at this time, however.
The life cycle of each order follows these steps:
OrderDocument
object and set the relevant
fields. Some data are stored in subordinate structures called Records
.
There is a set of mandatory fields which must be set.
OrderDocument
to submit it for processing. This submits the order to the ClearCommerce
Engine, which gets it authorized (or declined) by the processor.
The process()
call returns an
OrderResponse
object with full details on the status
of the transaction, and results such as the order identifier.
OrderResponse
, taking appropriate actions
and relaying the information to the customer.
process()
can only be called once on any
OrderDocument
.
To process another transaction, you must create a new OrderDocument
.
http://web.mit.edu/ecommerce/www/omars/api/
import edu.mit.is.ecommerce.api.OrderResponse; import edu.mit.is.ecommerce.api.OrderDocument; import edu.mit.is.ecommerce.api.OrderException; import edu.mit.is.ecommerce.api.Record; OrderDocument doc = new OrderDocument(); Record rec; rec = doc.getRoot(); rec.setField("Type", "PreAuth"); rec.setField("CardNumber","4242424242424242"); rec.setField("ExpireMonth","03"); rec.setField("ExpireYear","14"); rec.setField("Total","42.13"); try { OrderResponse resp = doc.process("https://omars.mit.edu/mystore_api", "mycert.pem"); if (resp.getRoot().getField("Status").equals(OrderResponse.APPROVED)) { ..report success.. } else if (resp.getRoot().getField("Status").equals(OrderResponse.DECLINED)) { ..tell customer to correct problem and try again.. } else if (resp.getRoot().getField("Status").equals(OrderResponse.ERROR)) { ..tell customer to report error, contact maintainer.. } } catch (OrderException e) { ..tell customer to report error, contact maintainer.. } catch (java.io.IOException e) { ..tell customer to report error, contact maintainer.. }
Note how the "top level" fields are actually set in the root Record
of the document, not in the OrderDocument
itself. Just
copy this code in your own applications.
The separate import
statements are shown to demonstrate
which packages are used. You can just
import edu.mit.is.ecommerce.api.*
.
When you receive a new OMARS certificate, it will be good for exactly 1 year. Plan now to ask to renew it at least two weeks before it expires.
WARNING: It can sometimes take several days to process certificate requests. You MUST remember to renew your certificate before it expires, or your application will be down and there is nothing we can do about it.
We recommend using a automated tool like setting an "Event" in TechTime or a cron job on your computer to remind you to renew your OMARS certificate.
-----BEGIN RSA PRIVATE KEY----- Proc-Type: 4,ENCRYPTED DEK-Info: DES-CBC,1C6ADB959ECFD677 D0/aBcx1h3fo8GoqKsa60jrW/T08QMydwIkNTlBG2PjJrd8my76GGgtNzMK0KKsr pQSQpt082b74HVplOF3sL8OIgt58Sd2L9pznryBjqAkno2krQZu7WL14vjahCCPy .... omhHiN9bir4McjK1hmA2LTMyzPERBvJQNqDaQBjbosmXVqHxc7kdQQ== -----END RSA PRIVATE KEY----- -----BEGIN CERTIFICATE----- MIIC1jCCAj+hAwIBAgIDE8VLMA0GCSqGSIb3DQEBBAUAMGwxCzAJBgNVBAYTAlVT pQSQpt082b74HVplOF3sL8OIgt58Sd2L9pznryBjqAkno2krQZu7WL14vjahCCPy .... omhHiN9bir4McQ== -----END CERTIFICATE-----
You will need the following libraries
in your CLASSPATH:
They should be available in the ecommerce locker, under /mit/ecommerce/omars-current/lib (for the current OMARS release).
When a new version of OMARS is deployed, you will be responsible for updating your copy of the OMARS client library omars-client.jar as well as any necessary upgrades of other libraries. Subscribe to the omars-users mailing list (send mail to omars-users-request@mit.edu) so you will get these announcements.
this | that
. Free-text fields
have sample contents in italics
. The contents
of the fields are surrounded by extra spaces for readability in this
example only; when assigning field values you should strip off all
leading and trailing spaces.
<OrderDocument> -- Order properties <Type> PreAuth | Auth </Type> <OrderID> unique order identifier (36 chars) </OrderID> <Comments> up to 64 chars of "comment" text </Comments> <Mode> P|T|Y|N|R </Mode> -- (Default is P; Y,N,R are for testing) <IPAddress> customer's IP address </IPAddress> <Email> customer's email address </Email> -- Credit card information <CardNumber> credit card number </CardNumber> <ExpireMonth> expiration month, 2 digits </ExpireMonth> <ExpireYear> expiration year, 2 digits </ExpireYear> <CVM> Card Verification Method numbers </CVM> -- Order totals <TaxExempt> true|false </TaxExempt> <StateTax> amount of state tax </StateTax> -- [see note 1] <Shipping> amount of shipping </Shipping> -- [see note 1] <SubTotal> amount of subtotal </SubTotal> -- [see note 1,2] <Total> amount of total </Total> -- [see note 1,2] -- Optional structures <BillingAddress> <Location> <Name> Jack Florey </Name> <Company> Mass Tool & Die (screws in all sizes) </Company> <Street1> 77 Mass Ave </Street1> <Street2> Room 7-013 </Street2> <Street3> Third Cubical on the Left </Street3> <City> Cambridge </City> <State> MA </State> <Zip> 02139 </Zip> <Country> 840 </Country> -- Must be 3-digit ISO country code <TelVoice> 617-555-1212 </TelVoice> <TelFax> 617-555-1212 </TelFax> </Location> </BillingAddress> <ShippingAddress> <Location> (same contents as Location tag under BillingAddress above) </Location> </ShippingAddress> <ItemList> <Item> -- Repeated for each line in item list <ItemNumber> 1 </ItemNumber> -- "line number", 1..N <Qty> 1 </Qty> -- quantity of units ordered <ProductCode> 666-999 </ProductCode> -- (up to 12 chars) SKU or stock number <Id> widget01 </Id> -- (up to 40 chars) Item Identifier <Desc> LH Widget </Desc> -- (64 chars) Product description <Price> 1.39 </Price> -- [1] unit price, decimal dollars <TaxExempt> true/false </TaxExempt> -- tax-exempt status, "true" or "false" <StateTax> 0.09 </StateTax> -- [1] total tax for line, decimal dollars <Shipping> 1.06 </Shipping> -- [1] total shipping for line, decimal dollars <Total> 1.48 </Total> -- [1] total charge for line, incl tax <UnitMeasure> thing </UnitMeasure> -- (up to 12 chars) unit of measurements (lbs, gross, etc) </Item> </ItemList>
Total
and SubTotal
fields must be set. See the descriptions of each
field, below, for details.
OrderDocument
FieldsType
PreAuth
just
"authorizes" the sale and reserves the funds for the total in the customer's
account, while Auth
does that and also captures the funds
for the merchant (although no money is actually transferred until
settlement, usually at the end of the day). A PreAuth transaction must
be captured ("fulfilled") later, using the interactive OMARS Order
Management service. Use PreAuth when the customer is buying hard goods,
such as books, which are not delivered immediately. The merchant is
only allowed to capture funds after the goods have been delivered.
OrderID
Comments
Mode
IPAddress
Email
CardNumber
ExpireMonth
ExpireYear
CVM
TaxExempt
true
or false
.
Declares that the order is tax-exempt (although if you specify a
StateTax amount it will still get added into the total). The default
is false. This is not really needed, since you can just leave out
the tax amounts on untaxed orders.
StateTax
SubTotal
field when computing the
total to be charged.
Although it is not necessary to separate out the tax, we strongly recommend you do so. You can then get ClearCommerce to produce cumulative reports of the state tax collected, which helps with accounting. Very few items sold by MIT merchants are subject to sales tax anyway, so this is usually not even a consideration.
Like all amount figures this must be a decimal number without any other puctuation or currency symbols.
Shipping
SubTotal
field when computing the
total to be charged.
Like all amount figures this must be a decimal number without any
other puctuation or currency symbols.
SubTotal
Total
field
is specified. This is the amount to be charged for goods and services
ordered. It is added to the StateTax
and Shipping
fields to compute the total amount to charge for the order.
Like all amount figures this must be a decimal number without any
other puctuation or currency symbols.
Total
SubTotal
field
is specified. This is the total amount to be charged for the order.
If an item list or other amount fields were specified, this total
must match the sum of the subtotal, tax, and shipping.
Like all amount figures this must be a decimal number without any
other puctuation or currency symbols.
BillingAddress
See the section below describing Location fields for more details.
ShippingAddress
See the section below describing Location fields for more details.
ItemList
See the section below describing Item Fields for more details on constructing the item list.
Location
sub-RecordsBillingAddress
and
ShippingAddress
, contains a sub-Record named Location
.
This record may include the following fields:
Name
This field in the Billing address is used for address verification, so make all efforts to include it, since a matching address will get you a better discount rate on the transaction.
Company
Street1
This field in the Billing address is used for address verification, so make all efforts to include it, since a matching address will get you a better discount rate on the transaction.
Street2
Street3
City
State
Zip
This field in the Billing address is used for address verification, so make all efforts to include it, since a matching address will get you a better discount rate on the transaction.
Country
http://www.tu-berlin.de/zrz/dienste/netz/mail/iso-3166.html
http://ftp.ics.uci.edu/pub/ietf/http/related/iso3166.txt
TelVoice
TelFax
Item
sub-RecordsItemList
sub-Record is composed of a list of
Item
records. Note that four of the Item fields are required,
and must be present in each Item
record:
ItemNumber
,
Qty
,
Desc
, and
Price
.
An Item record may contain the fields:
ItemNumber
Qty
ProductCode
Id
Desc
Price
Qty
is the goods subtotal
for this line of the item list.
TaxExempt
true
or false
.
Declares that the item is tax-exempt (although if you specify a
StateTax amount it will still get added into the total). The default
is false. This is not really needed, since you can just leave out
the tax amounts on untaxed items.
StateTax
StateTax
field.
Although it is not necessary to separate out the tax, we strongly recommend you do so. You can then get ClearCommerce to produce cumulative reports of the state tax collected, which helps with accounting. Very few items sold by MIT merchants are subject to sales tax anyway, so this is usually not even a consideration.
Shipping
Shipping
field.
Total
UnitMeasure
OrderResponse
document returned by the process()
method has the following structure. Fields shown in bold are
always present. The presence of other fields depends on the value of
<
<OrderResponse> <Status> APPROVED | DECLINED | ERROR </Status> <Time> timestamp </Time> <OrderID> unique order identifier (36 chars) </OrderID> <ErrorSummary> Explanation of ERROR or DECLINED status </Message> <AuthCode> authorization code returned by processor </AuthCode> <Span> credit card number span </Span> <Amount> 0.00 </Amount> <ErrorList> <Error> <ContextId> context identifier </ContextId> <ResourceId> resource identifier </ResourceId> <Severity> severity code </Severity> <Message> message text </Message> <AdvisedAction> action code </AdvisedAction> <DataState> data loss code </DataState> </Error> [...] </ErrorList> </OrderResponse>
OrderResponse
FieldsStatus
OrderResponse.APPROVED
ErrorSummary
will contain data.
OrderResponse.DECLINED
ErrorSummary
field contains an explanation, and Error
has the details.
OrderResponse.ERROR
ErrorSummary
field
contains the reason it was rejected,
and Error
has the details.
Time
java.util.Date
object with this number.
This field is always present in APPROVED and DECLINED responses, but
it is not included in all ERROR responses.
OrderID
OrderID
field, it was automatically assigned,
so the application can only discover it by reading this field. Use
this identifier to find the order in the OMARS Order Management service.
ErrorSummary
ErrorSummary
is set, the subrecords under
ErrorList
will have more detailed and structured information about the failure.
AuthCode
Span
6011*********4242
".
Amount
Total
field from the order.
ErrorList
Status
field is either DECLINED or ERROR, this
field is a list of Error
sub-records. These are the
error messages and other information returned by the ClearCommerce Engine.
Each Error
record contains the following fields:
ContextId
ResourceId
it uniquely identifies an error message. It is usually a short string
such as "ACH" or "Payment".
ResourceId
Severity
0 Success 5 Error 1 Debug 6 Critical 2 Informational 7 Alert 3 Notice 8 Emergency 4 Warning
Message
AdvisedAction
DataState
OrderDocument
fields
and sub-records, the method of adding addresses and items to the
order can be explained.
BillingAddress
to your order is always a good idea,
since the processor will try to match it with
Address Verification Service (AVS) and get you
a better discount rate.
You must include the
Name
, Street1
, and Zip
fields
for AVS to get a match.
The billing name also appears
in reports produced by the OMARS interactive services, where it can
help you locate an order.
The ShippingAddress
is only needed if your application has
some use for it. You will see it again in the detailed order report of the
OMARS Order Management service, but otherwise it is not used by the system.
ClearCommerce can compute shipping charges automatically based on this
address but we have no way to use the feature at this time.
Adding an ItemList
gives several benefits: It documents the
goods purchased in a way you can see later through the OMARS Order
Management interface. That service also lets you fullfil or credit
individual item lines in the order. In some cases, the item list is
sent to the credit card processor and will appear on the customer's
credit card statement.
OrderDocument
variable doc
. Note how a BillingAddress
sub-record is added to the document root and a Location
is added to it. The Location
contains the address fields.
Record addr = doc.getRoot().addRecord("BillingAddress").addRecord("Location"); addr.setField("Name", "Jack Florey"); addr.setField("Street1", "60 Vassar St."); addr.setField("Zip", "02139");
The code to add an item list is similar, except that more
than one Item
record can be added to the ItemList
.
Also, when you have an item list, the order does not need a
SubTotal
or Total
field, since the subtotal is
computed automatically from the sum of all item lines. If you do include
a SubTotal
, it must match the sum of all item prices, and
if you include a Total
field, it must match the sum of the
subtotal plus any tax and shipping amounts.
This example adds three item lines to the order:
Record iList = doc.getRoot().addRecord("ItemList"); Record item = iList.addRecord("Item"); item.setField("ItemNumber", "1"); item.setField("Qty", "3"); item.setField("Desc", "Slide-rule cozy"); item.setField("Price", "1.99"); item = iList.addRecord("Item"); item.setField("ItemNumber", "2"); item.setField("Qty", "1"); item.setField("Desc", "Official MIT Propellor Beanie"); item.setField("Price", "5.99"); item = iList.addRecord("Item"); item.setField("ItemNumber", "3"); item.setField("Qty", "1"); item.setField("Desc", "2-inch \"Nerd Pride\" pin"); item.setField("Price", "1.00");
Error Messages: This code fragment prints all of the error messages in the OrderResponse response, which is assumed to be the result of an error or declined transaction:
Record errorList = response.getRecord("ErrorList"); if (errorList != null) { Record err; for (err = errorList.getFirstRecord("Error"); err != null; err = errorList.getNextRecord("Error")) { System.out.println("Error Record: ContextId="+ err.getField("ContextId")+ ", ResourceId="+err.getField("ResourceId")+ ", AdvisedAction="+err.getField("AdvisedAction")+ ", DataState="+err.getField("DataState")+ "\n Severity="+err.getField("Severity")+ ", Message="+err.getField("Message")); } }
OrderDocument
, or would
just like the visualize the result, use the write()
method
to print it. OrderResponse
documents have this method
too. This example writes a formatted view of the document to the
standard error stream, which Web servlet engines usually record in
a log file:
doc.write(System.err);
NOTE: This produces a valid XML document, so if any of the field values contain XML metacharacters they will be escaped. The following characters will be printed as entity strings:
> prints as > < prints as < & prints as &