'=============================================================================== ' AlertPay Instant Payment Notification (IPN) '=============================================================================== ' THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY ' OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT ' LIMITED TO THE IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. '=============================================================================== ' Script: AlertURL.vb ' Platform: ASP.NET 1.0 or above ' Language: Visual Basic ' Purpose: ' -------- ' The purpose of this code is to help you to understand how to process the Instant Payment Notification ' variables for Subscription Button and integrate it in your ASP.NET site. ' How to Use: ' ----------- ' Put this code into the page which you have specified as Alert URL. ' The variables being read from the Request object in the below code are pre-defined IPN variables and the ' the conditional blocks provide you the logical placeholders to process the IPN variables. It is your responsibility ' to write appropriate code as per your requirements. ' Developer Feedback: ' -------------- ' If you have any questions about this script or any suggestions, please email to: devsupport@alertpay.com. Imports System Imports System.Web Imports System.Web.UI Public Class _Default Inherits System.Web.UI.Page ' Security code variable Dim ap_SecurityCode As String ' Customer info variables Dim ap_CustFirstName, ap_CustLastName, ap_CustAddress, ap_CustCity As String Dim ap_CustCountry, ap_CustZip, ap_CustEmailAddress As String 'Common transaction variables Dim ap_ReferenceNumber, ap_Status, ap_PurchaseType, ap_Merchant As String Dim ap_ItemName, ap_ItemCode, ap_Description, ap_Quantity, ap_Amount, ap_AdditionalCharges As String Dim ap_ShippingCharges, ap_TaxAmount, ap_DiscountAmount, ap_TotalAmount, ap_Currency As String Dim ap_Test As String ' Custom fields Dim ap_Apc_1, ap_Apc_2, ap_Apc_3, ap_Apc_4, ap_Apc_5, ap_Apc_6 As String ' Subscription variables Dim ap_SubscriptionReferenceNumber, ap_TimeUnit, ap_PeriodLength, ap_PeriodCount, ap_NextRunDate As String Dim ap_TrialTimeUnit, ap_TrialPeriodLength, ap_TrialAmount As String Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) 'Initialize varibale setSecurityCodeVariable() If ap_SecurityCode <> "W2cTGHv8v6ELEflpBndaQg" Then ' The Data is NOT sent by AlertPay. ' Take appropriate action Else If ap_Test = "1" Then ' Your site is currently being integrated with AlertPay IPN for TESTING PURPOSES ' ONLY. Don't store any information in your Production database and don't process ' this transaction as a real order. Else ' Initialize variables setCustomerInfoVariables() setCommonTransactionVariables() ' Initialize the custom field variables. setCustomFields() ' If the transaction is subscription-based (recurring payment), initialize the ' Subscription variables too. If ap_PurchaseType = "Subscription" Then setSubscriptionVariables() If ap_ReferenceNumber.Length = 0 And ap_TrialAmount <> "0" Then ' Invalid reference number. The reference number is invalid because the ap_ReferenceNumber doesn't ' contain a value and the ap_TrialAmount is not equal to 0. Else If ap_Status = "Success" Then ' Transaction is complete. It means that the amount was paid successfully. ' Process the order here. ' Process non-subscription order. If ap_PurchaseType <> "Subscription" Then ' NOTE: The subscription variables are not applicable here. Don't use them. ' Process the subscription order. Use ap_SubscriptionReferenceNumber to uniquely identify ' this particular subscription transaction. Else ' Check whether the trial is free or not If ap_TrialAmount = "0" Then ' Process the free trial here. ' NOTE: The ap_ReferenceNumber is always empty for trial periods and therefore you ' should not use it. Else ' The is not a free trial and ap_TrialAmount contains some amount and the ' ap_ReferenceNumber contains a valid transaction reference number. End If End If Else ' Transaction cancelled means seller explicitely cancelled the subscription or AlertPay ' cancelled or it was cancelled since buyer didnt have enough money after resheduling after two times. ' Take Action appropriately End If End If End If End If End If End Sub Private Sub setSecurityCodeVariable() ap_SecurityCode = Request.Form("ap_securitycode") End Sub Private Sub setCustomerInfoVariables() ap_CustFirstName = Request.Form("ap_custfirstname") ap_CustLastName = Request.Form("ap_custlastname") ap_CustAddress = Request.Form("ap_custaddress") ap_CustCity = Request.Form("ap_custcity") ap_CustCountry = Request.Form("ap_custcountry") ap_CustZip = Request.Form("ap_custzip") ap_CustEmailAddress = Request.Form("ap_custemailaddress") ap_PurchaseType = Request.Form("ap_purchasetype") ap_Merchant = Request.Form("ap_merchant") End Sub Private Sub setCommonTransactionVariables() ap_ItemName = Request.Form("ap_itemname") ap_Description = Request.Form("ap_description") ap_Quantity = Request.Form("ap_quantity") ap_Amount = Request.Form("ap_amount") ap_AdditionalCharges = Request.Form("ap_additionalcharges") ap_ShippingCharges = Request.Form("ap_shippingcharges") ap_TaxAmount = Request.Form("ap_taxamount") ap_DiscountAmount = Request.Form("ap_discountamount") ap_TotalAmount = Request.Form("ap_totalamount") ap_Currency = Request.Form("ap_currency") ap_ReferenceNumber = Request.Form("ap_referencenumber") ap_Status = Request.Form("ap_status") ap_ItemCode = Request.Form("ap_itemcode") ap_Test = Request.Form("ap_test") End Sub Private Sub setSubscriptionVariables() ap_SubscriptionReferenceNumber = Request.Form("ap_subscriptionreferencenumber") ap_TimeUnit = Request.Form("ap_timeunit") ap_PeriodLength = Request.Form("ap_periodlength") ap_PeriodCount = Request.Form("ap_periodcount") ap_NextRunDate = Request.Form("ap_nextrundate") ap_TrialTimeUnit = Request.Form("ap_trialtimeunit") ap_TrialPeriodLength = Request.Form("ap_trialperiodlength") ap_TrialAmount = Request.Form("ap_trialamount") End Sub Private Sub setCustomFields() ap_Apc_1 = Request.Form("apc_1") ap_Apc_2 = Request.Form("apc_2") ap_Apc_3 = Request.Form("apc_3") ap_Apc_4 = Request.Form("apc_4") ap_Apc_5 = Request.Form("apc_5") ap_Apc_6 = Request.Form("apc_6") End Sub End Class