SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2004
    Location
    Glasgow
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Does the PayPal Sandbox work with subscriptions?

    I used one of Paypal's own code to try and test a subscription system that I trying to create. I am getting subscription email through the 'fake' email that I setup but the sandbox is not posting anything into my database (in lamest terms, the IPN is not working). Does the Sandbox work well with subscription at all? Anyone you guys had any success with it in that department?

    Just in case, this is my ipn code: (long)

    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>
    <%

    ' dim some variables
    Dim Item_name, Item_number, Payment_status, Payment_amount
    Dim Txn_id, Receiver_email, Payer_email
    Dim objHttp, str

    'define subroutine to handle "all" payments ##
    sub allPayments() ' begin sub ###########################################################

    set conn = Server.CreateObject("ADODB.connection")
    conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("/maindb/gcode_db07.mdb")
    set rs = Server.CreateObject("ADODB.Recordset")
    rs.open "Payments", conn, 2, 2
    rs.addnew

    'add records to the Payments table

    rs.Fields("payment_date") = payment_date
    rs.Fields("pp_txn_id") = txn_id
    rs.Fields("parent_txn_id") = parent_txn_id
    rs.Fields("payment_status") = payment_status
    rs.Fields("pending_reason") = pending_reason
    rs.Fields("reason_code") = reason_code
    rs.Fields("txn_type") = txn_type
    rs.Fields("payment_type") = payment_type
    rs.Fields("mc_gross") = mc_gross
    rs.Fields("mc_fee") = mc_fee
    rs.Fields("payment_currency") = mc_currency
    rs.Fields("settle_amount") = settle_amount
    rs.Fields("settle_currency") = settle_currency
    rs.Fields("exchange_rate") = exchange_rate
    rs.Fields("payer_email") = payer_email
    rs.Fields("payment_status") = payer_status
    rs.Fields("cust_firstname") = first_name
    rs.Fields("cust_lastname") = last_name
    rs.Fields("cust_biz_name") = payer_business_name
    rs.Fields("gift_address_name") = address_name
    rs.Fields("cust_address_street") = address_street
    rs.Fields("cust_address_city") = address_city
    rs.Fields("cust_address_state") = address_state
    rs.Fields("cust_address_zip") = address_zip
    rs.Fields("cust_address_country") = address_country
    rs.Fields("cust_address_status") = address_status
    rs.Fields("notify_version") = notify_version
    rs.Fields("for_auction") = for_auction
    rs.Fields("auction_buyer_id") = auction_buyer_id
    rs.Fields("auction_closing_date") = auction_closing_date

    'finish up
    rs.Update
    rs.Close
    Set rs = Nothing
    Set conn = Nothing
    end sub 'end sub ###########################################################################


    'define subroutine to handle subscription payments ##
    sub subscriptionPayments() ' begin sub ###########################################################

    set conn = Server.CreateObject("ADODB.connection")
    conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("/maindb/gcode_db07.mdb")
    set rs = Server.CreateObject("ADODB.Recordset")
    rs.open "Subscriptions", conn, 2, 2
    rs.addnew

    'add records to the Subscriptions table
    rs.Fields("subscription_id") = subscr_id
    rs.Fields("subscription_date") = subscr_date
    rs.Fields("subscr_txn_type") = txn_type
    rs.Fields("sub_period1") = period1
    rs.Fields("sub_period2") = period2
    rs.Fields("sub_period3") = period3
    rs.Fields("sub_mcamount1") = amount1
    rs.Fields("sub_mcamount2") = amount2
    rs.Fields("sub_mcamount3") = amount3
    rs.Fields("sub_recurring") = recurring
    rs.Fields("sub_reattempt") = reattempt
    rs.Fields("sub_retry_at") = retry_at
    rs.Fields("sub_recur_times") = recur_times
    rs.Fields("sub_username") = username
    rs.Fields("sub_password") = password

    'finish up
    rs.Update
    rs.Close
    Set rs = Nothing
    Set conn = Nothing

    end sub 'end sub ###########################################################################

    'begin IPN handling
    ' read post from PayPal system and add 'cmd'
    str = Request.Form & "&cmd=_notify-validate"

    ' post back to PayPal system to 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.sandbox.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")
    txn_id = Request.Form("txn_id")
    parent_txn_id = Request.Form("parent_txn_id")
    receiver_email = Request.Form("receiver_email")
    payer_email = Request.Form("payer_email")
    reason_code = Request.Form("reason_code")
    business = Request.Form("business")
    quantity = Request.Form("quantity")
    invoice = Request.Form("invoice")
    custom = Request.Form("custom")
    tax = Request.Form("tax")
    option_name1 = Request.Form("option_name1")
    option_selection1 = Request.Form("option_selection1")
    option_name2 = Request.Form("option_name2")
    option_selection2 = Request.Form("option_selection2")
    num_cart_items = Request.Form("num_cart_items")
    pending_reason = Request.Form("pending_reason")
    payment_date = Request.Form("payment_date")
    mc_gross = Request.Form("mc_gross")
    mc_fee = Request.Form("mc_fee")
    mc_currency = Request.Form("mc_currency")
    settle_amount = Request.Form("settle_amount")
    settle_currency = Request.Form("settle_currency")
    exchange_rate = Request.Form("exchange_rate")
    txn_type = Request.Form("txn_type")
    first_name = Request.Form("first_name")
    last_name = Request.Form("last_name")
    payer_business_name = Request.Form("payer_business_name")
    address_name = Request.Form("address_name")
    address_street = Request.Form("address_street")
    address_city = Request.Form("address_city")
    address_state = Request.Form("address_state")
    address_zip = Request.Form("address_zip")
    address_country = Request.Form("address_country")
    address_status = Request.Form("address_status")
    payer_email = Request.Form("payer_email")
    payer_id = Request.Form("payer_id")
    payer_status = Request.Form("payer_status")
    payment_type = Request.Form("payment_type")
    notify_version = Request.Form("notify_version")
    verify_sign = Request.Form("verify_sign")

    'subscription information
    subscr_date = Request.Form("subscr_date")
    period1 = Request.Form("period1")
    period2 = Request.Form("period2")
    period3 = Request.Form("period3")
    amount1 = Request.Form("mc_amount1")
    amount2 = Request.Form("mc_amount2")
    amount3 = Request.Form("mc_amount3")
    recurring = Request.Form("recurring")
    reattempt = Request.Form("reattempt")
    retry_at = Request.Form("retry_at")
    recur_times = Request.Form("recur_times")
    username = Request.Form("username")
    password = Request.Form("password")
    subscr_id = Request.Form("subscr_id")

    'auction information
    for_auction = Request.Form("for_auction")
    auction_buyer_id = Request.Form("auction_buyer_id")
    auction_closing_date = Request.Form("auction_closing_date")


    ' Check notification validation
    if (objHttp.status <> 200 ) then
    ' HTTP error handling
    elseif (objHttp.responseText = "VERIFIED") then
    ' check that Payment_status=Completed
    ' check that Txn_id has not been previously processed
    ' check that Receiver_email is your Primary PayPal email
    ' check that Payment_amount/Payment_currency are correct
    ' process payment


    'implement IPN handling logic for DB insertion '#########################################################

    Dim paidadvert, paiddate, expirydate, user_id, subs_timescale, subs_userid, my_data, subs_duration, avd_category

    ' My own bits of information
    paidadvert = 1
    paiddate = date()
    my_data = Request.Form("custom")
    my_data = Split(my_data,",")
    subs_duration = Request.Form("p3")
    subs_timescale = Request.Form("t3")
    adv_category = my_data(0)
    subs_userid = my_data(1)
    expirydate = DateAdd(subs_timescale, subs_duration,date())


    set conn = Server.CreateObject("ADODB.connection")
    conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("/maindb/gcode_db07.mdb")
    set rs = Server.CreateObject("ADODB.Recordset")
    rs.open "adverts", conn, 2, 2
    rs.addnew

    rs.Fields("cat_advert") = adv_category
    rs.Fields("txn_id") = txn_id
    rs.Fields("item_name") = item_name
    rs.Fields("usr_advert") = subs_userid
    rs.Fields("paid_advert") = paidadvert
    rs.Fields("paid_date") = paiddate
    rs.Fields("expiry_date") = expirydate

    'finish up
    rs.Update
    rs.Close
    Set rs = Nothing
    Set conn = Nothing

    Response.write("SUCCESS! This is cool!")

    'decide what to do based on txn_type - using Select Case

    Select Case txn_type
    Case "subscr_signup"
    subscriptionPayments()
    Case "subscr_payment"
    subscriptionPayments()
    Case "subscr_modify"
    subscriptionPayments()
    Case "subscr_failed"
    subscriptionPayments()
    Case "subscr_cancel"
    subscriptionPayments()
    Case "subscr_eot"
    subscriptionPayments()
    Case Else
    allPayments()
    End Select


    elseif (objHttp.responseText = "INVALID") then
    ' log for manual investigation
    ' add code to handle the INVALID scenario

    Response.write("INVALID! An error occured!")

    else
    ' error
    Response.write("ERROR! Cannot Proceed!")
    end if
    set objHttp = nothing
    %>


    </body>
    </html>


    And the ASP Page that passes the susbscription values

    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <!--#include file="../Connections/mainCGODE_CONN.asp" -->
    <!--#include file="../includes/tNG/tNG.inc.asp" -->
    <%
    'Start Restrict Access to Page
    Dim restrict: Set restrict = new tNG_RestrictAccess
    restrict.Init MM_mainCGODE_CONN_STRING, "../"
    'Grand Levels: Level
    restrict.addLevel "2"
    restrict.Execute
    'End Restrict Access to Page
    %>
    <%
    Dim rsAdvCat
    Dim rsAdvCat_cmd
    Dim rsAdvCat_numRows

    Set rsAdvCat_cmd = Server.CreateObject ("ADODB.Command")
    rsAdvCat_cmd.ActiveConnection = MM_mainCGODE_CONN_STRING
    rsAdvCat_cmd.CommandText = "SELECT * FROM categories"
    rsAdvCat_cmd.Prepared = true

    Set rsAdvCat = rsAdvCat_cmd.Execute
    rsAdvCat_numRows = 0
    %>
    <%
    Dim Repeat1__numRows
    Dim Repeat1__index

    Repeat1__numRows = -1
    Repeat1__index = 0
    rsAdvCat_numRows = rsAdvCat_numRows + Repeat1__numRows
    %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/main_gcode_template.dwt.asp" codeOutsideHTMLIsLocked="false" -->
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <!-- InstanceBeginEditable name="doctitle" -->
    <title>GCode</title>
    <!-- InstanceEndEditable -->
    <link href="../css/default/main.css" rel="stylesheet" type="text/css" />
    <!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
    <style type="text/css">
    <!--
    .style1 {color: #990000}
    -->
    </style>
    </head>

    <body>
    <div id="container">
    <div id="banner">
    <br />
    </div>
    <div align="right" id="searchBox"><strong>
    Resources for <span class="style1">Machine Tool</span> and <span class="style1">GCode</span> Users </strong></div>
    <div id="content" class="clearfix">
    <div id="nav">
    <div id="site_nav">
    <ul>
    <li><a href="../index.asp" title="Home">Home</a></li>
    <li><a href="../sync_editor.asp" title="Sync Editor ™">Sync Editor ™</a></li>
    <li><a href="#3" title="Multi-Task Machine Users">Multi-Task Machine Users </a></li>
    <li><a href="#4" title="Jobs &amp; Vacancies">Jobs &amp; Vacancies</a></li>
    <li><a href="#" title="Programmers &amp; Contractors">Programmers &amp; Contractors </a></li>
    <li><a href="#" title="Wanted &amp; For Sale">Wanted &amp; For Sale </a></li>
    <li><a href="login.asp" title="Place An Advert">Place An Advert </a></li>
    <li><a href="../adverts/adverts.asp">View Adverts</a> </li>
    <li><a href="../forum/default.asp" title="Visit Forum">Visit Forum</a></li>
    <li><a href="#" title="Other Links">Other Links </a></li>
    </ul>
    </div>
    </div>

    <div id="main"><!-- InstanceBeginEditable name="Content" -->
    <h1><strong>Buy Advertising Space</strong></h1>
    <p>[ <a href="user_options.asp">Back to Options </a> ] </p>
    <p>&nbsp;</p>
    <p>As a registered advertiser, you can buy advertising space here on GCode. Simply select any of the options below and click the Buy button to purchase. Once you have made your choice, you will be directed to Paypal where your details will be required. Should you not have a payal account, you can created one or use your credit card. Upon payment receipt, you will bve redirected back to GCode where you will be allowed to upload your two images and text for your advert.</p>
    <p>&nbsp;</p>
    <p>Your options/p>
    <p>&nbsp;</p>

    <%
    While ((Repeat1__numRows <> 0) AND (NOT rsAdvCat.EOF))
    %>
    <table width="100%" border="0">
    <tr>
    <td width="60%"><strong><%=(rsAdvCat.Fields.Item("name_cat").Value)%></strong> : <strong>&pound;<%=(rsAdvCat.Fields.Item("charge_cat").Value)%> </strong><br />
    Duration: <strong><%=(rsAdvCat.Fields.Item("duration").Value)%> <%=(rsAdvCat.Fields.Item("timescale").Value)%></strong></td>
    <td>
    <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" name="_xclick">
    <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but20.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
    <img alt="" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1">
    <input type="hidden" name="cmd" value="_xclick-subscriptions">
    <input type="hidden" name="business" value="admin@gcode.net">
    <input type="hidden" name="item_name" value="<%=(rsAdvCat.Fields.Item("name_cat").Value)%> Advertising Space">
    <input type="hidden" name="no_shipping" value="1">
    <input type="hidden" name="return" value="http://gcode.somee.com/advertise/thankyou.asp">
    <input type="hidden" name="cancel_return" value="http://gcode.somee.com/advertise/cancel.asp">
    <input type="hidden" name="no_note" value="1">
    <input type="hidden" name="currency_code" value="GBP">
    <input type="hidden" name="lc" value="GB">
    <input type="hidden" name="bn" value="PP-SubscriptionsBF">
    <input type="hidden" name="a3" value="<%=formatnumber((rsAdvCat.Fields.Item("charge_cat").Value), 2)%>">
    <input type="hidden" name="p3" value="<%=(rsAdvCat.Fields.Item("duration").Value)%>">
    <input type="hidden" name="t3" value="<%=(rsAdvCat.Fields.Item("timescale").Value)%>">
    <input type="hidden" name="src" value="1">
    <input type="hidden" name="sra" value="1">
    <input type="hidden" name="custom" value="<%=(rsAdvCat.Fields.Item("id_cat").Value)%>,<%= Session("kt_login_id") %>">
    </form> </td>
    </tr>
    </table>
    <br />
    <%
    Repeat1__index=Repeat1__index+1
    Repeat1__numRows=Repeat1__numRows-1
    rsAdvCat.MoveNext()
    Wend
    %>
    <p>&nbsp;</p>
    <p><strong>Key</strong>: <strong>y</strong> = Years, <strong>m</strong> = Months, <strong>w</strong> = Weeks, <strong>d</strong> = Days </p>
    <p>&nbsp;</p>
    <p>&nbsp; </p>
    <!-- InstanceEndEditable --></div>
    </div>
    <div id="footer">
    <p>&copy; 2007 | GCode</p>
    <p>Contacta href="mailto:enquiries@gcode.com"> enquiries@gcode.com</a> </p>
    </div>
    </div>
    </body>
    <!-- InstanceEnd --></html>
    <%
    rsAdvCat.Close()
    Set rsAdvCat = Nothing
    %>



    I have enabled IPN on the Sandbox account and entered the IPN URL... So what are the values now being posted back? Any help will be appreciated.

    Thanks

    Emmanuel

  2. #2
    SitePoint Member
    Join Date
    Jun 2004
    Location
    Glasgow
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No help here!????

  3. #3
    SitePoint Zealot davejuk's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Classic ASP is old news, get stuck into ASP.NET. It makes your life so much easier once you've got to grips with the basics.

    To answer your question, yes you should get IPN notifications regardless of whether the payment is a subscription or a one off.

    I had trouble with the (ASP.NET) code provided by PayPal - it turns out it's incomplete. If you go on their developer forum, you'll probably get more help there than you will here.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •