<% '------------------------------------------------------------------------------------------- ' PayPal Express Checkout Example Step 3 ' ====================================================================== ' Complete the final payment for PayPal. This ' page would normally be run to complete the ' payment with PayPal, and display the result ' back to the buyer '------------------------------------------------------------------------------------------- On Error Resume Next Dim token Dim payerID Dim paymentAmount Dim currCodeType Dim paymentType Dim pgt Dim pgtrans '------------------------------------------------------------------------------------------- ' Gather the information to make the final call to ' finalize the PayPal payment. The variable nvpstr ' holds the name value pairs '------------------------------------------------------------------------------------------- dim rs4 set conn = Server.Createobject("adodb.connection") set rs = server.createobject("adodb.recordset") conn.open connstr if session("orderid") = "" then orderid="0" else orderid = session("orderid") end if if orderid = "0" then session("errmsg")="Your shopping cart is empty" response.redirect "http://www.spiritfitness.com/shop/form.asp" else rs.open "select * from orders where id = " & orderid, conn,3,3 if rs.eof then rs.close conn.close session("errmsg")="Order has not been created, can't update, please try again" response.redirect "http://www.spiritfitness.com/shop/abandon.asp" end if if rs("approved") then rs.close conn.close session("errmsg")="Order has been completed and paid for, can't update" response.redirect "http://www.spiritfitness.com/shop/abandon.asp" end if end if token = SESSION("token") currCodeType = SESSION("currencyCodeType") paymentAmount = SESSION("paymentAmount") paymentType = SESSION("PaymentType") payerID = SESSION("PayerID") nvpstr = "&" & Server.URLEncode("TOKEN") & "=" & Server.URLEncode(token) & "&" &_ Server.URLEncode("PAYERID")&"=" &Server.URLEncode(payerID) & "&" &_ Server.URLEncode("PAYMENTACTION")&"=" & Server.URLEncode(paymentType) & "&" &_ Server.URLEncode("AMT") &"=" & Server.URLEncode(paymentAmount)&"&"&_ Server.URLEncode("CURRENCYCODE")& "=" &Server.URLEncode(currCodeType) '------------------------------------------------------------------------------------------- ' Make the call to PayPal to finalize payment ' If an error occured, show the resulting errors '------------------------------------------------------------------------------------------- Set resArray=hash_call("DoExpressCheckoutPayment",nvpstr) ack = UCase(resArray("ACK")) '------------------------------------------------------------------------------------------- ' Display the API request and API response back to the browser using APIError.asp. ' If the response from PayPal was a success, display the response parameters ' If the response was an error, display the errors received '------------------------------------------------------------------------------------------- pgt = "" pgtrans = "" If ack=UCase("Success") Then message = "Thank you for your payment!
You will receive a confirmation email from PayPal shortly." coupon=rs("coupon")&"" rs("approved") = true 'approved rs("method") = "PayPal Express Checkout" rs("authcode") = resArray("TRANSACTIONID") rs.update rs.close if coupon <>""then set rs3 = server.createobject("adodb.recordset") sql = "select * from coupons where couponname='"& coupon &"'" rs3.open sql,conn,3,3 if not rs3.eof then rs3("amountused") = rs3("amountused") + 1 rs3.update end if rs3.close end if '============================== set rs2 = server.createobject("adodb.recordset") set rs4 = server.createobject("adodb.recordset") rs2.open "select * from orderdetail where orderid = " & orderid, conn, 3,3 do while not rs2.eof rs4.open "select * from products where id = " & rs2("productid"),conn,3,1 if not rs4.eof then qty = rs2("qty") unitprice = rs2("unitprice") totalprice1 = rs2("totalprice") code=rs4("code") desc=rs4("name") if rs2("altcode") &"" <> "" then code=rs2("altcode")&"" desc = desc & " - " &rs2("option") end if pgt = pgt & "pageTracker._addItem(""" & orderid & """, """ & code & """, """ & desc & """, """", """ & unitprice & """, """ & qty & """);" & chr(13) &chr(10) end if rs4.close rs2.movenext loop rs2.close rs2.open "select * from orders where id = "&orderid,conn shippingcity = rs2("shippingcity")&"" shippingstate = rs2("shippingstate")&"" shippingzip = rs2("shippingzip")&"" shippingcountry = rs2("shippingcountry")&"" shipping = rs2("shipping")&"" tax = rs2("tax")&"" ordertotal = rs2("ordertotal")&"" pgtrans = pgtrans + "pageTracker._addTrans(""" & orderid & """, """ & ordertotal & """, """ & tax & """, """ & shipping & """, """ & shippingCity & """, """ & shippingstate & """, """ & shippingcountry & """);" & chr(13) &chr(10) rs2.close '============================== conn.close Else rs.close conn.close Set SESSION("nvpErrorResArray") = resArray Response.Redirect "APIError.asp" End If '-------------------------------------------------------------------------------------------- ' If there is no Errors Construct the HTML page with a table of variables Loop through the associative array ' for both the request and response and display the results. '-------------------------------------------------------------------------------------------- %>
Confirmation


<%=message%>

Transaction ID: <%=resArray("TRANSACTIONID")%>
Amount: <%=resArray("CURRENCYCODE")%><%=resArray("AMT")%>
<% If Err.Number <> 0 Then SESSION("ErrorMessage") = ErrorFormatter(Err.Description,Err.Number,Err.Source,"DoExpressCheckoutPayment.asp") Response.Redirect "APIError.asp" Else SESSION("ErrorMessage") = Null End If %>
Home <%session.abandon%>