Avatar billede kenneth39 Nybegynder
13. marts 2002 - 22:28 Der er 5 kommentarer og
1 løsning

jeg skal have creditcard delen ud af dette script

<!-- #include file="db.asp" -->
<!-- #include file="functions.asp" -->
<%

Response.Buffer = true
For Each key in Request.Form
    strname = key
    strvalue = Request.Form(key)
    Session(strname) = strvalue
Next

Dim arrCart, scartItem
    arrCart = Session("MyCart")
    scartItem = Session("cartItem")
    if scartItem = 0 then
        Response.Redirect "error.asp?msg=" & Server.URLEncode ("Or your session has expired, or you tried to re-submit the form.")
    end if

If Request.Form("cardno") = "" OR len(Request.Form("cardno")) <=12 Then
    Response.Redirect "checkout.asp?msg=" & Server.URLEncode ("Please fill in a correct credit card number.")
Elseif Request.Form("cardname") = "" OR len(Request.Form("cardname")) <=6 Then
    Response.Redirect "checkout.asp?msg=" & Server.URLEncode ("Please fill in a correct credit card name.")
Else

strTotal = Cstr(Request.Form("ordertotal"))
intTotal = Replace(strTotal,",",".")

    imonth = Request.Form("expMonth")
    iyear = Request.Form("expYear")
    'use one of the following date formats: mm/dd/yyyy OR dd/mm/yyyy
    'if your server's settings are dd/mm/yyyy, please put a single quote in front of next line
    expDate = imonth & "/" & "28" & "/" & iyear
    'and remove single quote on next line:
    'expDate = "28" & "/" & imonth  & "/" & iyear

    'On error resume next
    sqlAdd = "INSERT INTO orders(ocustomerid,odate,orderamount,ocardtype,ocardno,"
    sqlAdd = sqlAdd & "ocardname,ocardexpires,ocardaddress"
    If Not Request.Form("shipaddress")="" then
        sqlAdd = sqlAdd & ",oshipaddress,oshiptown,oshipzip,oshipstate,oshipcountry"
    End If
    sqlAdd = sqlAdd & ") VALUES("
    sqlAdd = sqlAdd & Session("customerid") & ",#" & Date & "#," & intTotal
    sqlAdd = sqlAdd & ",'" & Request.Form("paymentm") & "','" & Request.Form("cardno") & "'"
    sqlAdd = sqlAdd & ",'" & TwoSingleQ(Request.Form("cardname")) & "',#" & expDate & "#"
    sqlAdd = sqlAdd & ",'" & TwoSingleQ(Request.Form("cardaddress")) & " '"
    If Not Request.Form("shipaddress")="" then
        sqlAdd = sqlAdd & ",'" & TwoSingleQ(Request.Form("shipaddress")) & "'"
        sqlAdd = sqlAdd & ",'" & TwoSingleQ(Request.Form("shiptown")) & " '"
        sqlAdd = sqlAdd & ",'" & Request.Form("shipzip") & " '"
        sqlAdd = sqlAdd & ",'" & Request.Form("shipstate") & " '"
        sqlAdd = sqlAdd & ",'" & Request.Form("shipcountry") & " '"
    End If
    sqlAdd = sqlAdd & ")"
       
    call openConn()
    dbc.execute sqlAdd, intAffected

    if dbc.Errors.count > 0 then
        call closeConn()
        Response.Redirect "error.asp?msg=" & server.URLEncode("Error occurred sending info to Database. Please contact us.")   
    elseif intAffected = 1 then
        Dim oid, sqlo
        sqlo = "SELECT max(orderID) FROM orders"
        Set rso = dbc.Execute(sqlo)   
        oid = Cint(rso(0))
        rso.Close
       
        If oid < 1 Then
            call closeConn()
            Response.Redirect "error.asp?msg=" & Server.URLEncode ("Error: No order id.")
        Else
            'insert order items into oitems table
            For i = 1 To scartItem
                sqlOItem = "INSERT INTO oitems(orderid,catalogid,numitems) VALUES("
                sqlOItem = sqlOItem & oid
                sqlOItem = sqlOItem & "," & arrCart(cProductid,i)
                sqlOItem = sqlOItem & "," & arrCart(cQuantity,i)
                sqlOItem = sqlOItem & ")"
                dbc.execute sqlOItem
            Next
            If dbc.Errors.Count > 0 then
                call closeConn()
                Response.Redirect "error.asp?msg=" & Server.URLEncode ("Not succeeded. Error: ") & dbc.Error.Description
            else
                'send mail to merchant, use function mailMerchant
                blnMail =  mailMerchant("youremail@yourserver",oid,nosmtp)
                if blnMail = false then
                    call closeConn()
                    Response.Redirect "error.asp?msg=" & Server.URLEncode ("Could not send mail to merchant.")
                end if
            end if
        End if
    else
        call closeConn()
        Response.Redirect "error.asp?msg=" & Server.URLEncode ("Order information could not be sent to database. Please try again later.")
    end if
        If dbc.Errors.Count > 0 then
            dbc.Close
            set dbc = nothing
            Response.Redirect "error.asp?msg=" & Server.URLEncode ("Not succeeded. Error: ") & dbc.Error.Description
        Else
            dbc.close
            set dbc = nothing
            Response.Redirect "thanks.asp"
        End If
End If

function mailMerchant(merchantmail,orderid,smtpServer)
    'get client info from DB
    set cmd = server.CreateObject("ADODB.Command")
    cmd.ActiveConnection = dbc
    cmd.CommandText = "qryOrderInfo"
    cmd.CommandType = adCmdStoredProc
    set param = cmd.CreateParameter("oid",adInteger,adParamInput,4)
    cmd.Parameters.Append param
    cmd("oid") = orderid
   
    'build message body strBody
    set rs = server.CreateObject("ADODB.recordset")
    set rs = cmd.Execute
    if not rs.eof then
        strBody = "Online order by a.shopKart on " & rs("odate") & vbCrLf & vbCrLf
        strBody = strBody & "Customer info:" & vbCrLf
        strBody = strBody & rs("cfirstname") & vbCrLf
        strBody = strBody & rs("clastname") & vbCrLf
        strBody = strBody & rs("cemail") & vbCrLf
        strBody = strBody & rs("caddress") & " - " & rs("caddress2") & vbCrLf
        strBody = strBody & rs("ctown") & vbCrLf
        strBody = strBody & rs("czip") & vbCrLf
        strBody = strBody & rs("cstate") & vbCrLf
        strBody = strBody & rs("ccountry") & vbCrLf
        strBody = strBody & rs("cphone") & vbCrLf & vbCrLf
       
        strBody = strBody & "Credit card info:" & vbCrLf
        strBody = strBody & rs("ocardtype") & vbCrLf
        strBody = strBody & left(rs("ocardno"),4) & "..." & vbCrLf
        strBody = strBody & rs("ocardname") & vbCrLf
        strBody = strBody & rs("ocardexpires") & vbCrLf & vbCrLf
       
        strBody = strBody & "Ordered items:" & vbCrLf
        strBody = strBody & "Code" & vbTab & "Item" & vbTab & "No." & vbTab & "Price" & vbCrLf
        strBody = strBody & "-------------------------------------------------------" & vbCrLf
        dblOrderTotal = 0
        while not rs.EOF
            strBody = strBody & rs("ccode") & vbTab & rs("cname") & vbTab
            lineTotal = rs("cprice")*rs("numitems")
            strBody = strBody & rs("numitems") & vbTab & lineTotal & vbCrLf
            dblOrderTotal = dblOrderTotal + lineTotal
            rs.MoveNext
        wend
        strBody = strBody & "-------------------------------------------------------" & vbCrLf
        strBody = strBody & "Total: " & dblOrderTotal & vbCrLf
        strBody = strBody & vbCrLf & vbCrLf
       
        rs.Close
        set rs = nothing
        set cmd = nothing
       
        'use CDONTS to send mail
        set Mailer = Server.CreateObject("CDONTS.NewMail")
        mailer.From = merchantmail
        Mailer.To = merchantmail
        Mailer.Subject = "Online order (a.shopKart)"
        Mailer.Body = strBody
        Mailer.Send
        if Err.number > 0 then
            mailMerchant = false
        else
            mailMerchant = true
        end if
   
        'OR use ASPMail - choose your own
        'Set Mailer = Server.CreateObject ("SMTPsvg.Mailer")
        'Mailer.FromName = "a.shopKart"
        'Mailer.FromAddress = merchantmail
        'Mailer.Subject = "a.shopKart Order"
        'Mailer.BodyText = strBody
        'Mailer.RemoteHost = smtpServer
   
        'Mailer.AddRecipient "", merchantmail
        'if Mailer.SendMail then
            ' Message sent sucessfully
        ' mailMerchant = true
        'else
          ' Message send failure
        '    mailMerchant = false
        'end if
    else
        rs.Close
        set rs = nothing
        set cmd = nothing
        mailMerchant = false
    end if

end function

%>
Avatar billede dmcn Praktikant
13. marts 2002 - 22:30 #1
Spørgsmål flyttet fra Eksperten : Kildekodehjælp til Programmering : ASP - forhåbentlig giver det lidt flere svar. :)
Avatar billede snigermunken Nybegynder
13. marts 2002 - 22:31 #2
spørg i asp kategorien, der er større chance for du får hjølp der.
Avatar billede kenneth39 Nybegynder
13. marts 2002 - 22:34 #3
takker og undskylde jeg fik lagt det forkert :)
Avatar billede coltau Juniormester
13. marts 2002 - 23:24 #4
Hvad skal blive tilbage. ?

1. Det med creditcard. ?
2. Det med mail. ?
3. Det med opdatering af ordre. ?
Avatar billede kenneth39 Nybegynder
13. marts 2002 - 23:48 #5
hej coltau
desvære fik jeg ikke hele scriptet lagt ind, jeg skal have det til at fungere uden credit card delen, jeg kan evt. maile scriptet til dig :)
Avatar billede coltau Juniormester
14. marts 2002 - 00:05 #6
Jeg lover ikke noget - men prøv bare. ccc@post11.tele.dk
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester