<% response.Buffer = true %> <% Dim pcv_strPayPalmethod pcv_strPayPalmethod = "PayPalExp" '// Set the PayPal Class Obj set objPayPalClass = New pcPayPalClass '***************************************************************************************************** ' START: Check store on/off, start PC session, check affiliate ID '***************************************************************************************************** %> <% '***************************************************************************************************** ' END: Check store on/off, start PC session, check affiliate ID '***************************************************************************************************** '***************************************************************************************************** '// START: Validate AND Set "pcCartArray" AND "pcCartIndex" '***************************************************************************************************** %><% pcs_VerifySession '***************************************************************************************************** '// END: Validate AND Set "pcCartArray" AND "pcCartIndex" '***************************************************************************************************** ppcCartIndex=Session("pcCartIndex") If session("customerType")=1 Then if calculateCartTotal(pcCartArray, ppcCartIndex) show message response.redirect "msg.asp?message=205" end if Else if calculateCartTotal(pcCartArray, ppcCartIndex) show message response.redirect "msg.asp?message=206" end if End If '/////////////////////////////////////////////////////////////////////////////// '// START: GET DATA FROM DB '/////////////////////////////////////////////////////////////////////////////// '// Open Db call opendb() '// Declare Local Variables at once '>>> pcPay_PayPal_TransType '>>> PaymentAction '>>> pcPay_PayPal_Username '>>> pcPay_PayPal_Password '>>> pcPay_PayPal_Sandbox '>>> pcPay_PayPal_Method '>>> pcPay_PayPal_Signature objPayPalClass.pcs_SetAllVariables() '// Close Db call closedb() '/////////////////////////////////////////////////////////////////////////////// '// END: GET DATA FROM DB '/////////////////////////////////////////////////////////////////////////////// '/////////////////////////////////////////////////////////////////////////////// '// START: GET ORDER DETAILS '/////////////////////////////////////////////////////////////////////////////// '// Order Total if session("pcPay_PayPalExp_OrderTotal")="" OR session("pcPay_PayPalExp_OrderTotal")=0 then session("pcPay_PayPalExp_OrderTotal")=calculateCartTotal(pcCartArray, ppcCartIndex) end if OrderTotal=session("pcPay_PayPalExp_OrderTotal") if OrderTotal="" then OrderTotal=0 end if OrderTotal=money(OrderTotal) OrderTotal=pcf_CurrencyField(OrderTotal) '// Currency Code Type currencyCodeType = pcPay_PayPal_Currency '// Express URLs url = objPayPalClass.GetURL() returnURL = url & "pcPay_ExpressPayUK_Start.asp?currencyCodeType=" & currencyCodeType & "&paymentAmount=" & OrderTotal & "&paymentType=" &PaymentAction cancelURL = url & "viewcart.asp?cmd=_express-checkout" If (scSSL<>"" AND scSSL<>"0" AND scCompanyLogo<>"") Then tempURL=scSslURL &"/"& scPcFolder & "/pc/" & "catalog/" & scCompanyLogo tempURL=replace(tempURL,"///","/") tempURL=replace(tempURL,"//","/") tempURL=replace(tempURL,"https:/","https://") tempURL=replace(tempURL,"http:/","http://") logoURL = tempURL End If '// Sandbox or Live URL pcv_PayPal_URL = objPayPalClass.GetECURL(pcPay_PayPal_Method) pcv_PayPal_URL = pcv_PayPal_URL & "?cmd=_express-checkout&token=" '//Declare and Retrieve Customer's IP Address Dim pcCustIpAddress pcCustIpAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR") If pcCustIpAddress="" Then pcCustIpAddress = Request.ServerVariables("REMOTE_ADDR") '/////////////////////////////////////////////////////////////////////////////// '// END: GET ORDER DETAILS '/////////////////////////////////////////////////////////////////////////////// '/////////////////////////////////////////////////////////////////////////////// '// START: Express Checkout Method '/////////////////////////////////////////////////////////////////////////////// '// Set our token Dim Token Token=Request.Querystring("TOKEN") session("PayPalExpressToken")=Token '// Begin Post If No Token If Request.QueryString("token")="" Then '*********************************************************************** '// Start: Posting Details to PayPal '*********************************************************************** '--------------------------------------------------------------------------- ' Construct the parameter string that describes the PayPal payment the varialbes ' were set in the web form, and the resulting string is stored in nvpstr ' ' Note: Make sure you set the class obj "objPayPalClass" at the top of this page. '--------------------------------------------------------------------------- nvpstr="" '// clear objPayPalClass.AddNVP "CLIENTIP", pcCustIpAddress objPayPalClass.AddNVP "AMT", OrderTotal objPayPalClass.AddNVP "TENDER", "P" '// C = credit card, P = PayPal objPayPalClass.AddNVP "ACTION", "S" '// S = Set, G = Get, D = Do objPayPalClass.AddNVP "TRXTYPE", PaymentAction '// S = Sale transaction, A = Authorisation, C = Credit, D = Delayed Capture, V = Void objPayPalClass.AddNVP "CURRENCY", pcPay_PayPal_Currency objPayPalClass.AddNVP "RETURNURL", returnURL objPayPalClass.AddNVP "CANCELURL", cancelURL if logoURL<>"" then ' objPayPalClass.AddNVP "HDRIMG", logoURL end if 'response.Write(nvpstr) 'response.End() '--------------------------------------------------------------------------- ' Make the call to PayPal to set the Express Checkout token ' If the API call succeded, then redirect the buyer to PayPal ' to begin to authorize payment. If an error occurred, show the ' resulting errors '--------------------------------------------------------------------------- Set resArray = objPayPalClass.hash_call("SetExpressCheckout",nvpstr) Set Session("nvpResArray")=resArray ack = UCase(resArray("RESPMSG")) 'response.Write(ack) 'response.End() if err.number <> 0 then '// PayPal Error Handler Include: Returns an User Friendly Error Message as the string "pcv_PayPalErrMessage" Dim pcv_PayPalErrMessage %><% session("ExpressCheckoutPayment")="" end if If instr(ack,"APPROVED")>0 Then '// Redirect to paypal.com here token = resArray("TOKEN") payPalURL = pcv_PayPal_URL & token objPayPalClass.ReDirectURL(payPalURL) Else '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' Start: Error Reporting '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '// Combine User Friendly Errors from "pcPay_PayPal_Errors.asp" '// with Code errors from string "Declined String". '// Return a formatted error report as the string "pcv_PayPalErrMessage". objPayPalClass.GenerateErrorReport() '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' End: Error Reporting '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ session("ExpressCheckoutPayment")="" End If '*********************************************************************** '// End: Posting Details to PayPal '*********************************************************************** Else '*********************************************************************** '// Start: Get Details from PayPal '*********************************************************************** '// Create a Session Flag session("ExpressCheckoutPayment")="YES" '--------------------------------------------------------------------------- ' At this point, the buyer has completed in authorizing payment ' at PayPal. The script will now call PayPal with the details ' of the authorization, incuding any shipping information of the ' buyer. Remember, the authorization is not a completed transaction ' at this state - the buyer still needs an additional step to finalize ' the transaction '--------------------------------------------------------------------------- Session("currencyCodeType") = Request.Querystring("currencyCodeType") Session("paymentAmount") = Request.Querystring("paymentAmount") Session("PaymentType")= Request.Querystring("PaymentType") Session("PayerID")= Request.Querystring("PayerID") '--------------------------------------------------------------------------- ' Build a second API request to PayPal, using the token as the ' ID to get the details on the payment authorization ' ' Note: Make sure you set the class obj "objPayPalClass" at the top of this page. '--------------------------------------------------------------------------- nvpstr="" '// clear objPayPalClass.AddNVP "IPADDRESS", pcCustIpAddress objPayPalClass.AddNVP "TENDER", "P" '// C = credit card, P = PayPal objPayPalClass.AddNVP "ACTION", "G" '// S = Set, G = Get, D = Do objPayPalClass.AddNVP "TRXTYPE", "S" '// PaymentAction '// S = Sale transaction, A = Authorisation, C = Credit, D = Delayed Capture, V = Void objPayPalClass.AddNVP "TOKEN", session("PayPalExpressToken") '--------------------------------------------------------------------------- ' Make the API call and store the results in an array. If the ' call was a success, show the authorization details, and provide ' an action to complete the payment. If failed, show the error '--------------------------------------------------------------------------- Set resArray = objPayPalClass.hash_call("GetExpressCheckoutDetails",nvpstr) ack = UCase(resArray("RESPMSG")) Set Session("nvpResArray")=resArray '// Successful Get Express Details If ack="APPROVED" Then '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' Start: Set Express Details '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 'TOKEN 'CUSTOM 'INVNUM pcStrShippingPhone=resArray("PHONENUM") pcv_Payer=resArray("EMAIL") session("Payer")=pcv_Payer pcv_PayerID=resArray("PAYERID") session("PayerId")=pcv_PayerID pcv_PayerStatus=resArray("PAYERSTATUS") pcv_PayerBusiness=resArray("BUSINESS") pcv_FirstName=resArray("FIRSTNAME") pcv_LastName=resArray("LASTNAME") pcv_FullName= pcv_FirstName & " " & pcv_LastName pcv_ShipToName = resArray("SHIPTONAME") pcv_Street1=resArray("SHIPTOSTREET") pcv_Street2=resArray("SHIPTOSTREET2") pcv_CityName=resArray("SHIPTOCITY") pcv_StateOrProvince=resArray("SHIPTOSTATE") pcv_StateCode=resArray("SHIPTOSTATE") pcv_Country=resArray("SHIPTOCOUNTRY") pcv_CountryName=resArray("SHIPTOCOUNTRYNAME") pcv_PostalCode=resArray("SHIPTOZIP") response.Write(pcv_PayerBusiness) & "
" response.Write(pcv_FullName) & "
" response.Write(pcv_Payer) & "
" response.Write(pcv_ShipToName) & "
" response.Write(pcv_Street1) & "
" response.Write(pcv_Street2) & "
" response.Write(pcv_CityName) & "
" response.Write(pcv_StateOrProvince) & "
" response.Write(pcv_Country) & "
" response.Write(pcv_PostalCode) & "
" response.Write(pcStrShippingPhone) & "
" 'response.End() strEmail=session("Payer") strPassword=randomNumber(9999999) strPassword=enDeCrypt(strPassword, scCrypPass) pCustomerType = 0 pIdRefer = 0 pRecvNews = 0 pcv_strPhoneQuery = "" if len(pcv_StateCode)>4 then pcv_StateCode="" '// Show Province Field, This is not a valid ISO Code end if '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' END: Set Express Details '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '// Open Db call opendb() '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' Start: Update Customer Details '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '// Customer Logged into ProductCart if session("idCustomer")<>"" and session("idCustomer")<>0 then query="UPDATE pcCustomerSessions SET idCustomer="&session("idCustomer")&", pcCustSession_ShippingNickName='"&pcv_ShipToName&"', pcCustSession_ShippingFirstName='"&pcv_FirstName&"', pcCustSession_ShippingLastName='"&pcv_LastName&"', pcCustSession_ShippingCompany='"&pcv_PayerBusiness&"', pcCustSession_ShippingAddress='"&pcv_Street1&"', pcCustSession_ShippingPostalCode='"&pcv_PostalCode&"', pcCustSession_ShippingStateCode='"&pcv_StateCode&"', pcCustSession_ShippingProvince='"&pcv_StateOrProvince&"', pcCustSession_ShippingPhone='"&pcStrShippingPhone&"', pcCustSession_ShippingCity='"&pcv_CityName&"', pcCustSession_ShippingCountryCode='"&pcv_Country&"', pcCustSession_ShippingAddress2='"&pcv_Street2&"' WHERE (((idDbSession)="&session("pcSFIdDbSession")&") AND ((randomKey)="&session("pcSFRandomKey")&"));" set rs=server.CreateObject("ADODB.RecordSet") set rs=conntemp.execute(query) set rs=nothing call closedb() response.redirect "login.asp" '// Customer NOT Logged into ProductCart else '// Check if Customer Exists query="SELECT idCustomer FROM customers WHERE email='"&strEmail&"';" set rs=server.CreateObject("ADODB.RecordSet") set rs=conntemp.execute(query) '// Email Does Not Exist - Create New Customer if rs.eof then query="INSERT INTO customers (name, lastName, email, [password], city, zip, CountryCode, state, stateCode,shippingcity,shippingZip,shippingCountryCode, shippingState, shippingStateCode, phone, address, shippingAddress, customercompany, customerType, IDRefer, CI1, CI2, address2, shippingCompany, shippingAddress2,RecvNews) VALUES ('" &pcv_FirstName& "', '" &pcv_LastName& "', '" &strEmail& "', '" &strPassword&"','" &pcv_CityName& "','" &pcv_PostalCode& "','" &pcv_Country& "', '"&pcv_StateOrProvince&"', '" &pcv_StateCode& "','" &pcv_CityName& "','" &pcv_PostalCode& "','" &pcv_Country& "', '"&pcv_StateOrProvince&"', '" &pcv_StateCode& "', '" &pcStrShippingPhone& "', '" &pcv_Street1& "', '" &pcv_Street1& "', '"&pcv_PayerBusiness&"', " &pCustomerType& ","&pIdRefer&",'" &pCI1& "','" &pCI2& "', '" &pcv_Street2& "','','" &pcv_Street2& "',"&pRecvNews&" )" set rstemp=server.CreateObject("ADODB.RecordSet") set rstemp=conntemp.execute(query) query="SELECT idCustomer FROM customers WHERE email='"&strEmail&"' ORDER BY idCustomer DESC;" set rstemp=server.CreateObject("ADODB.RecordSet") set rstemp=conntemp.execute(query) session("idCustomer")=rstemp("idCustomer") session("isCustomerNew")="YES" set rstemp=nothing '// Email Does Exist - Login Customer else intIdCustomer=rs("idCustomer") session("idCustomer")=intIdCustomer set rstemp=nothing end if end if set rs=nothing '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' End: Update Customer Details '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' Start: Update Customer Sessions '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ query="UPDATE pcCustomerSessions SET idCustomer="&session("idCustomer")&", pcCustSession_ShippingNickName='"&pcv_ShipToName&"', pcCustSession_ShippingFirstName='"&pcv_FirstName&"', pcCustSession_ShippingLastName='"&pcv_LastName&"', pcCustSession_ShippingCompany='"&pcv_PayerBusiness&"', pcCustSession_ShippingPhone='"&pcStrShippingPhone&"', pcCustSession_ShippingAddress='"&pcv_Street1&"', pcCustSession_ShippingPostalCode='"&pcv_PostalCode&"', pcCustSession_ShippingStateCode='"&pcv_StateCode&"', pcCustSession_ShippingProvince='"&pcv_StateOrProvince&"', pcCustSession_ShippingCity='"&pcv_CityName&"', pcCustSession_ShippingCountryCode='"&pcv_Country&"', pcCustSession_ShippingAddress2='"&pcv_Street2&"' WHERE (((idDbSession)="&session("pcSFIdDbSession")&") AND ((randomKey)="&session("pcSFRandomKey")&"));" set rs=server.CreateObject("ADODB.RecordSet") set rs=conntemp.execute(query) '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' Start: Update Customer Sessions '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ set rs=nothing call closedb() If session("customerType")=1 Then if calculateCartTotal(pcCartArray, ppcCartIndex) show message response.redirect "msg.asp?message=205" end if Else if calculateCartTotal(pcCartArray, ppcCartIndex) show message response.redirect "msg.asp?message=206" end if End If response.redirect "login.asp" '// Failed Get Express Details Else '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' Start: Error Reporting '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '// Combine User Friendly Errors from "pcPay_PayPal_Errors.asp" '// with Code errors from string "Declined String". '// Return a formatted error report as the string "pcv_PayPalErrMessage". objPayPalClass.GenerateErrorReport() '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' End: Error Reporting '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ session("ExpressCheckoutPayment")="" End If '*********************************************************************** '// End: Get Details from PayPal '*********************************************************************** End If '/////////////////////////////////////////////////////////////////////////////// '// END: Express Checkout Method '/////////////////////////////////////////////////////////////////////////////// function randomNumber(limit) randomize randomNumber=int(rnd*limit)+2 end function %>

 

<%=pcv_PayPalErrMessage%>