//=============================================================================== // 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.aspx.cs // Platform: ASP.NET 1.0 or above // Language: C# // 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. using System; using System.Data; using System.Configuration; using System.Web; using System.Web.UI; public class _Default : System.Web.UI.Page { // Security code variable private string ap_SecurityCode; // Customer info variables private string ap_CustFirstName, ap_CustLastName, ap_CustAddress, ap_CustCity; private string ap_CustCountry, ap_CustZip, ap_CustEmailAddress; // Common transaction variables private string ap_ReferenceNumber, ap_Status, ap_PurchaseType, ap_Merchant; private string ap_ItemName, ap_ItemCode, ap_Description, ap_Quantity, ap_Amount, ap_AdditionalCharges; private string ap_ShippingCharges, ap_TaxAmount, ap_DiscountAmount, ap_TotalAmount, ap_Currency; private string ap_Test; // Custom fields private string ap_Apc_1, ap_Apc_2, ap_Apc_3, ap_Apc_4, ap_Apc_5, ap_Apc_6; // Subscription variables private string ap_SubscriptionReferenceNumber, ap_TimeUnit, ap_PeriodLength, ap_PeriodCount, ap_NextRunDate; private string ap_TrialTimeUnit, ap_TrialPeriodLength, ap_TrialAmount; protected void Page_Load(object sender, EventArgs e) { setSecurityCodeVariable(); if (ap_SecurityCode != "W2cTGHv8v6ELEflpBndaQg") { // The Data is NOT sent by AlertPay. // Take appropriate action } else { if (ap_Test == "1") { // 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") { setSubscriptionVariables(); } if (ap_ReferenceNumber.Length == 0 && ap_TrialAmount != "0") { // 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") { // Transaction is complete. It means that the amount was paid successfully. // Process the order here. // Process non-subscription order. if (ap_PurchaseType != "Subscription") { // 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") { // 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. } } } 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 } } } } } private void setSecurityCodeVariable() { ap_SecurityCode = Request.Form["ap_securitycode"]; } private void 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"]; } private void 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"]; } private void 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"]; } private void 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"]; } }