[thelist] Friday Freebie (2 this week)

Scott Dexter sgd at ti3.com
Fri May 26 15:31:12 2000


Here's a couple fun things I ran into this week--

<tip type="MS SiteServer Commerce Ed" title="Using the purchase pipeline
without credit cards">
Say you're using the Commerce Server's pipelines to get your transactions
done. A nifty way to visualize things, actually. But anyhoo, in the provided
template of the purchase pipeline (purchase.pcf) there are three Stages:
Purchase Check, Payment, and Accept.

What if you're using this pipeline and not using credit cards (say for a
points-oriented site)? You've gone through all the Store's pages and
stripped out any references to CC checks and requirements, and you've pulled
out all the CC related crap in the Purchase pipeline in the Payment Stage.
All set, right?

Except you get an error that your credit card wasn't authorized when you try
to run the pipeline?!

Well, you're almost there. The Payment stage has a little thing embedded
into it: it requires the CC Auth code to be set to something besides Null.
You can't pull out the stage (or pull the requirement out of the stage), but
you can get around it by dropping in the DefaultPayment component into the
Payment stage. All it does is set the CC Auth code to "FAITH" --satisfying
the stage's requirement and not touching anything else. Where in the stage
you put it does not matter.

Now you can get your pipeline to run, and go get a pizza and make it to the
T.V. in time to see the playoff games....
</tip>

And because a Friday Freebie wouldn't be the same without a little code....

<tip type="MS SiteServer Commerce Ed" title="Since we're talking about
pipelines">
One of the components you can drop into your pipeline is the SQLItemADO
component, which allows you to specify a SQL statement and the values from
the order that go into it (specifically, it runs through the order, firing
the SQL statement once for each item in the order).

For the life of me, I couldn't get the component to fire a stored procedure
with parameters. So instead I scripted a routine and used the Scriptor
component to get the job done:

function MSCSExecute(config, orderform, context, flags)
shopper = orderform.Shopper_id
Set oConn = CreateObject("ADODB.CONNECTION")
oConn.Open "DSN=xxx;UID=xxxxx;PWD=xxxxxx"
On Error Resume Next
for each item in orderform.items
  sqlstr = "Exec InsertRedemptions
@shopper='"&shopper&"',@cat_id='"&item.cat_id&"',@qty="&item.quantity
    oConn.Execute sqlstr
  If Err then
    AppendLog sqlstr,"pipeline.log"
   AppendLog Err.Description
  MSCSExecute = 2
  Exit Function
end if
Next
oConn.Close
Set oConn=Nothing
    MSCSExecute = 1
end function

Sub AppendLog(byval mesg, byval filename)
Dim ForAppending,fs,a,logstr
' drop the code, mesg to a file
ForAppending = 8
filename = "D:\" & filename
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.OpenTextFile(filename, ForAppending, True)
logstr = Now & ":" & mesg
a.WriteLine(logstr)
a.Close
Set a = Nothing
Set fs = Nothing
End Sub

(The item.cat_id is a field I added, it is not part of the default install)

And look! A bonus routine you can use inside your Scriptor components to
write information out to file. Its the only way I could seriously debug the
damn things....
</tip>

sgd
--
think safely