dbTalk Databases Forums  

Paypal IPN Email

comp.databases.ms-access comp.databases.ms-access


Discuss Paypal IPN Email in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jim Rojas
 
Posts: n/a

Default Paypal IPN Email - 04-20-2010 , 08:30 AM






How can I fix this?


sub SendErrorEmail(err)
Dim mailer
set mailer = server.CreateObject("CDONTS.NewMail")

'set the properties
mailer.From = "webmaster (AT) mywebsite (DOT) com"
mailer.To = "email (AT) mywebsite (DOT) com"
mailer.Subject = "Process payment problem"
mailer.Body = err & vbcrlf & Details
mailer.Send
response.end
end sub


sub SendThankYou()
Dim mailer
set mailer = server.CreateObject("CDONTS.NewMail")
mailer.From = "email (AT) mywebsite (DOT) com"
mailer.To = Payer_email
mailer.Subject = "Thank you for your order"
mailer.Body = "Thank you for your order."
mailer.Send
end sub

Reply With Quote
  #2  
Old   
Arvin Meyer
 
Posts: n/a

Default Re: Paypal IPN Email - 04-24-2010 , 02:08 PM






It's doubtful that you'll get an answer until you can show how this relates
to MS-Access, and specifically what's wrong with it. What error message(s)
are you getting, and at what line(s) do you get them?
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.accessmvp.com
http://www.mvps.org/access


"Jim Rojas" <jrojas (AT) tech-man (DOT) com> wrote

Quote:
How can I fix this?


sub SendErrorEmail(err)
Dim mailer
set mailer = server.CreateObject("CDONTS.NewMail")

'set the properties
mailer.From = "webmaster (AT) mywebsite (DOT) com"
mailer.To = "email (AT) mywebsite (DOT) com"
mailer.Subject = "Process payment problem"
mailer.Body = err & vbcrlf & Details
mailer.Send
response.end
end sub


sub SendThankYou()
Dim mailer
set mailer = server.CreateObject("CDONTS.NewMail")
mailer.From = "email (AT) mywebsite (DOT) com"
mailer.To = Payer_email
mailer.Subject = "Thank you for your order"
mailer.Body = "Thank you for your order."
mailer.Send
end sub

Reply With Quote
  #3  
Old   
Jim Rojas
 
Posts: n/a

Default Re: Paypal IPN Email - 04-24-2010 , 03:53 PM



The IPN data gets written to my MS Access Database, which now works.
Afterwards, the script then suppose to send me an email, and a thank you
email to the paypal customer. I can post the entire script with the
changes I made thus far.

Jim Rojas



Arvin Meyer wrote:
Quote:
It's doubtful that you'll get an answer until you can show how this relates
to MS-Access, and specifically what's wrong with it. What error message(s)
are you getting, and at what line(s) do you get them?

Reply With Quote
  #4  
Old   
Jim Rojas
 
Posts: n/a

Default Re: Paypal IPN Email - 04-24-2010 , 07:58 PM



Here is the complete code with the MS Access calls.

Thank you for replying.

Jim Rojas


<%
Dim Item_name, Item_number, Payment_status, Payment_amount
Dim Txn_id, Receiver_email, Payer_email
Dim objHttp, str

set conn = Server.CreateObject("ADODB.Connection")
conn.open = application("connStr")


YourEmail = "myemailaddress"

'set fs = server.CreateObject("scripting.fileSystemObject")
'set a = fs.createTextFile("c:\temp\ipn" & rnd & ".txt", true)
Details = ""
for each var in request.Form
Details = Details & var & " = " & request.Form(var) & vbcrlf
next
'a.close
'response.end


str = Request.Form & "&cmd=_notify-validate"
'set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
' set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP.4.0")
set objHttp = Server.CreateObject("Microsoft.XMLHTTP")
objHttp.open "POST", "https://www.paypal.com/cgi-bin/webscr", false
objHttp.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
objHttp.Send str

' assign posted variables to local variables
Item_name = Request.Form("item_name")
Item_number = Request.Form("item_number")
Payment_status = Request.Form("payment_status")
Payment_amount = Request.Form("mc_gross")
Payment_currency = Request.Form("mc_currency")
Txn_id = Request.Form("txn_id")
Receiver_email = Request.Form("receiver_email")
Payer_email = Request.Form("payer_email")
Usernum = request.Form("custom")

' Check notification validation
if (objHttp.status <> 200 ) then
' HTTP error handling
elseif (objHttp.responseText = "VERIFIED") then
if Payment_status = "Completed" and lcase(Receiver_email) =
lcase(YourEmail) and Payment_currency = "USD" then
' check that Payment_amount/Payment_currency are correct
' process payment

set rs = conn.Execute("Select * from Transactions where
TransactionID='" & Txn_id & "'")
if not rs.eof then
response.Write("Transaction already processed")
response.end
end if

'record this transaction
sql = "insert into Transactions (TransactionID, Usernum, PayerEmail,
Total, Details) values ("
sql = sql & "'" & replace(Txn_id, "'", "''") & "',"
sql = sql & clng(userNum) & ","
sql = sql & "'" & replace(Payer_email, "'", "''") & "',"
sql = sql & clng(payment_amount) & ","
sql = sql & "'" & replace(Details, "'", "''") & "')"
conn.execute(sql)

set rs = conn.Execute("select * from AccessLevels where ID=" &
item_number)
price = rs("price")
daysToAdd = rs("Days")

aType = 2
if price >= 250 then aType=7

set rs = conn.Execute("Select expires from tUsers where userNum=" &
userNum)
if isnull(expires) then expires = now()
if not isDate(expires) then expires = now()
if expires < now() then expires = now()

expires = dateAdd("d", daysToAdd, expires)

conn.Execute("update tUsers set Expires='" & expires &
"',Account_type=" & aType & " where UserNum=" & UserNum)

SendThankYou
response.Write("process payment")
else
'something is wrong
SendErrorEmail "unverified"
end if
elseif (objHttp.responseText = "INVALID") then
SendErrorEmail "invalid"
else
SendErrorEmail "something else"

end if
set objHttp = nothing

sub SendErrorEmail(err)
Dim sendmail
Dim cdoConfig

'sets variables
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = Server.CreateObject("CDO.Configuration")

cdoConfig.Fields.Item(sch & "sendusing") = 2
cdoConfig.Fields.Item(sch & "smtpserver") = "localhost"
cdoConfig.Fields.Item(sch & "smtpserverport") = 25
cdoConfig.Fields.Item(sch & "connectiontimeout") = 10
cdoConfig.fields.update

Set sendmail = Server.CreateObject("CDO.Message")
Set sendmail.Configuration = cdoConfig

'set the properties
Sendmail.From = "myemailaddress"
Sendmail.To = Youremail
Sendmail.Subject = "Process payment problem"
Sendmail.HTMLBody = err & vbcrlf & Details
Sendmail.Send

response.end
end sub


sub SendThankYou()
Dim sendmail
Dim cdoConfig

'sets variables
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = Server.CreateObject("CDO.Configuration")
cdoConfig.Fields.Item(sch & "sendusing") = 2
cdoConfig.Fields.Item(sch & "smtpserver") = "localhost"
cdoConfig.Fields.Item(sch & "smtpserverport") = 25
cdoConfig.Fields.Item(sch & "connectiontimeout") = 10

cdoConfig.fields.update
Set sendmail = Server.CreateObject("CDO.Message")
Set sendmail.Configuration = cdoConfig

'set the properties
Sendmail.From = "myemailaddress"
Sendmail.To = Payer_email
Sendmail.Subject = "Thank you for your order"
Sendmail.HTMLBody = "Thank you for your order at mywebsite"
Sendmail.Send

response.end
end sub
%>

Reply With Quote
  #5  
Old   
Arvin Meyer
 
Posts: n/a

Default Re: Paypal IPN Email - 04-24-2010 , 10:32 PM



I don't see anything that stands out. What error messages are you getting? I
don't see any error code in there that would display errors, so you may want
to add msgbox(s) to check values and display errors.

--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.accessmvp.com
http://www.mvps.org/access


"Jim Rojas" <jrojas (AT) tech-man (DOT) com> wrote

Quote:
Here is the complete code with the MS Access calls.

Thank you for replying.

Jim Rojas


%
Dim Item_name, Item_number, Payment_status, Payment_amount
Dim Txn_id, Receiver_email, Payer_email
Dim objHttp, str

set conn = Server.CreateObject("ADODB.Connection")
conn.open = application("connStr")


YourEmail = "myemailaddress"

'set fs = server.CreateObject("scripting.fileSystemObject")
'set a = fs.createTextFile("c:\temp\ipn" & rnd & ".txt", true)
Details = ""
for each var in request.Form
Details = Details & var & " = " & request.Form(var) & vbcrlf
next
'a.close
'response.end


str = Request.Form & "&cmd=_notify-validate"
'set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
' set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP.4.0")
set objHttp = Server.CreateObject("Microsoft.XMLHTTP")
objHttp.open "POST", "https://www.paypal.com/cgi-bin/webscr", false
objHttp.setRequestHeader "Content-type",
"application/x-www-form-urlencoded"
objHttp.Send str

' assign posted variables to local variables
Item_name = Request.Form("item_name")
Item_number = Request.Form("item_number")
Payment_status = Request.Form("payment_status")
Payment_amount = Request.Form("mc_gross")
Payment_currency = Request.Form("mc_currency")
Txn_id = Request.Form("txn_id")
Receiver_email = Request.Form("receiver_email")
Payer_email = Request.Form("payer_email")
Usernum = request.Form("custom")

' Check notification validation
if (objHttp.status <> 200 ) then
' HTTP error handling
elseif (objHttp.responseText = "VERIFIED") then
if Payment_status = "Completed" and lcase(Receiver_email) =
lcase(YourEmail) and Payment_currency = "USD" then
' check that Payment_amount/Payment_currency are correct
' process payment

set rs = conn.Execute("Select * from Transactions where TransactionID='" &
Txn_id & "'")
if not rs.eof then
response.Write("Transaction already processed")
response.end
end if

'record this transaction
sql = "insert into Transactions (TransactionID, Usernum, PayerEmail,
Total, Details) values ("
sql = sql & "'" & replace(Txn_id, "'", "''") & "',"
sql = sql & clng(userNum) & ","
sql = sql & "'" & replace(Payer_email, "'", "''") & "',"
sql = sql & clng(payment_amount) & ","
sql = sql & "'" & replace(Details, "'", "''") & "')"
conn.execute(sql)

set rs = conn.Execute("select * from AccessLevels where ID=" &
item_number)
price = rs("price")
daysToAdd = rs("Days")

aType = 2
if price >= 250 then aType=7

set rs = conn.Execute("Select expires from tUsers where userNum=" &
userNum)
if isnull(expires) then expires = now()
if not isDate(expires) then expires = now()
if expires < now() then expires = now()

expires = dateAdd("d", daysToAdd, expires)

conn.Execute("update tUsers set Expires='" & expires & "',Account_type=" &
aType & " where UserNum=" & UserNum)

SendThankYou
response.Write("process payment")
else
'something is wrong SendErrorEmail "unverified"
end if
elseif (objHttp.responseText = "INVALID") then
SendErrorEmail "invalid"
else
SendErrorEmail "something else"

end if
set objHttp = nothing

sub SendErrorEmail(err)
Dim sendmail
Dim cdoConfig

'sets variables
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = Server.CreateObject("CDO.Configuration")

cdoConfig.Fields.Item(sch & "sendusing") = 2
cdoConfig.Fields.Item(sch & "smtpserver") = "localhost"
cdoConfig.Fields.Item(sch & "smtpserverport") = 25
cdoConfig.Fields.Item(sch & "connectiontimeout") = 10
cdoConfig.fields.update

Set sendmail = Server.CreateObject("CDO.Message")
Set sendmail.Configuration = cdoConfig

'set the properties
Sendmail.From = "myemailaddress"
Sendmail.To = Youremail
Sendmail.Subject = "Process payment problem"
Sendmail.HTMLBody = err & vbcrlf & Details
Sendmail.Send

response.end
end sub


sub SendThankYou()
Dim sendmail
Dim cdoConfig

'sets variables
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = Server.CreateObject("CDO.Configuration")
cdoConfig.Fields.Item(sch & "sendusing") = 2
cdoConfig.Fields.Item(sch & "smtpserver") = "localhost"
cdoConfig.Fields.Item(sch & "smtpserverport") = 25
cdoConfig.Fields.Item(sch & "connectiontimeout") = 10

cdoConfig.fields.update
Set sendmail = Server.CreateObject("CDO.Message")
Set sendmail.Configuration = cdoConfig

'set the properties
Sendmail.From = "myemailaddress"
Sendmail.To = Payer_email
Sendmail.Subject = "Thank you for your order"
Sendmail.HTMLBody = "Thank you for your order at mywebsite"
Sendmail.Send

response.end
end sub
%

Reply With Quote
  #6  
Old   
Jim Rojas
 
Posts: n/a

Default Re: Paypal IPN Email - 04-24-2010 , 10:42 PM



The IPN portion works as it should. It is adding the data to my MDB.
What is not happening is the emails I am suppose to get, and a thank you
email to the customer.

This code was working fine when it was sending CDONTS. Now that I was
forced to switch to CDOSYS, it no longer sends messages to me & the
customer.

Jim Rojas




Arvin Meyer wrote:
Quote:
I don't see anything that stands out. What error messages are you getting? I
don't see any error code in there that would display errors, so you may want
to add msgbox(s) to check values and display errors.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.