On many occasions, it is necessary to store IPN's for subsequent audit and / or order fulfilment
IPN Easy for .NET makes this simple and effective by using .NET and SQL Server. (Note: SQL Server Express can be used).
-
Create the database.
CopySQL/* ***************************************************************** *File: PayPalIpn.sql * *Copyright: Rolosoft.com * *Current Version: 1.0.0.1 * *Current Version Date: 13 April 2010 * *Current Version Notes: * -Updated to include user instance local DB creation * -New field (XML) on Log table * * ******************************************************************/ use [master]; go if DB_ID(N'PayPalIpn') is not null drop database PayPalIpn; go create database PayPalIpn; go ALTER DATABASE PayPalIpn SET READ_COMMITTED_SNAPSHOT ON; use [PayPalIpn]; go create table dbo.TransactionAndNotification ( TransactionAndNotificationId int not null primary key identity(1,1), Business varchar(127) null, Charset varchar(50) not null, Custom varchar(255) null, NotifyVersion varchar(10) not null, ParentTxnId varchar(19) null, ReceiverEmail varchar(127) not null, ReceiverId varchar(13) null, ResidenceCountry varchar(2) not null, TestIpn varchar(1) null, TxnId varchar(30) null, TxnType varchar(50) not null, VerifySign varchar(255) not null ) go create table dbo.[Log] ( LogId int not null primary key identity(1,1), TransactionAndNotificationId int not null, HttpHeaders varchar(max) not null, RawData varchar(max) not null, Received datetime not null, RequestIP varchar(200) not null, VerificationTimer bigint not null, Xml nvarchar(max) not null ) go ALTER TABLE dbo.[Log] ADD CONSTRAINT FK_Log_TxnNotiId__1 FOREIGN KEY (TransactionAndNotificationId) REFERENCES dbo.TransactionAndNotification(TransactionAndNotificationId) go create table dbo.BuyerInformation ( BuyerInformationId int not null primary key identity(1,1), TransactionAndNotificationId int not null, AddressCity varchar(40) null, AddressCountry varchar(64) null, AddressCountryCode varchar(2) null, AddressName varchar(128) null, AddressState varchar(40) null, AddressStatus varchar(12) null, AddressStreet varchar(200) null, AddressZip varchar(20) null, ContactPhone varchar(20) null, FirstName varchar(64) null, LastName varchar(64) null, PayerEmail varchar(127) null, PayerId varchar(13) not null ) go ALTER TABLE dbo.BuyerInformation ADD CONSTRAINT FK_Buyer_TxnNotiId__1 FOREIGN KEY (TransactionAndNotificationId) REFERENCES dbo.TransactionAndNotification(TransactionAndNotificationId) go create table dbo.PaymentInformation ( PaymentInformationId int not null primary key identity(1,1), TransactionAndNotificationId int not null, AuthAmount money not null, AuthExpiry datetime null, AuthId varchar(19) null, AuthStatus varchar(10) not null, ExchangeRate varchar(255) null, Invoice varchar(255) null, MCCurrency varchar(5) not null, MCFee money not null, MCGross money not null, MCHandling money not null, MCShipping money not null, Memo varchar(255) null, NumCartItems int not null, OptionName1 varchar(64) null, OptionName2 varchar(64) null, OptionSelection1 varchar(200) null, OptionSelection2 varchar(200) null, PayerStatus varchar(10) not null, PaymentDate datetime null, PaymentGross money not null, PaymentStatus varchar(20) not null, PaymentType varchar(7) not null, PendingReason varchar(20) not null, ReasonCode varchar(50) not null, RemainingSettle money not null, SellerProtectionEligibilityCode varchar(30) not null, SettleAmount money not null, SettleCurrency varchar(5) not null, Shipping money not null, ShippingMethod varchar(255) null, Tax money not null, TransactionEntity varchar(10) not null ) go ALTER TABLE dbo.PaymentInformation ADD CONSTRAINT FK_Payment_TxnNotiId__1 FOREIGN KEY (TransactionAndNotificationId) REFERENCES dbo.TransactionAndNotification(TransactionAndNotificationId) go create table dbo.Item ( ItemId int not null primary key identity(1,1), PaymentInformationId int not null, Name varchar(255) null, PayPalBasketItemNumber int not null, MCGross money not null, MCShipping money not null, Qty int not null, Sku varchar(255) null, Tax money not null, UnitAmount money not null ) ALTER TABLE dbo.Item ADD CONSTRAINT FK_Item_PaymentInfoId__1 FOREIGN KEY (PaymentInformationId) REFERENCES dbo.PaymentInformation(PaymentInformationId) go create table dbo.Auction ( AuctionId int not null primary key identity(1,1), TransactionAndNotificationId int not null, BuyerID varchar(64) null, ClosingDate datetime null, ForAuction varchar(255) null, MultiItem int not null ) go ALTER TABLE dbo.Auction ADD CONSTRAINT FK_Auction_PaymentInfoId__1 FOREIGN KEY (TransactionAndNotificationId) REFERENCES dbo.TransactionAndNotification(TransactionAndNotificationId) go create table dbo.DisputeResolution ( DisputeResolutionId int not null primary key identity(1,1), TransactionAndNotificationId int not null, CaseCreationDate datetime null, CaseId varchar(255) not null, CaseType varchar(20) not null, ReasonCode varchar(25) not null ) go ALTER TABLE dbo.DisputeResolution ADD CONSTRAINT FK_DisputeResolution_PaymentInfoId__1 FOREIGN KEY (TransactionAndNotificationId) REFERENCES dbo.TransactionAndNotification(TransactionAndNotificationId) go create table dbo.FraudManagementPendingFilter ( FraudManagementPendingFilterId int not null primary key identity(1,1), TransactionAndNotificationId int not null, PayPalFraudManagementFilterNumber int not null, [Status] varchar(50) not null ) go ALTER TABLE dbo.FraudManagementPendingFilter ADD CONSTRAINT FK_FraudManagementPendingFilter_PaymentInfoId__1 FOREIGN KEY (TransactionAndNotificationId) REFERENCES dbo.TransactionAndNotification(TransactionAndNotificationId) go create table dbo.MassPay ( MassPayId int not null primary key identity(1,1), TransactionAndNotificationId int not null, PaymentDate datetime null, PaymentStatus varchar(20) not null, ReasonCode varchar(50) not null, ) go ALTER TABLE dbo.MassPay ADD CONSTRAINT FK_MassPay_PaymentInfoId__1 FOREIGN KEY (TransactionAndNotificationId) REFERENCES dbo.TransactionAndNotification(TransactionAndNotificationId) go create table dbo.MassPayItem ( MassPayItemId int not null primary key identity(1,1), MassPayId int not null, MassPayItemNumber int not null, MCCurrency varchar(5) not null, MCFee money not null, MCGross money not null, MCHandling money not null, PaymentDate datetime null, PaymentStatus varchar(20) not null, ReasonCode varchar(50) not null, ReceiverEmail varchar(127) not null, [Status] varchar(20) not null, TxnId varchar(19) not null, UniqueId varchar(13) null ) go ALTER TABLE dbo.MassPayItem ADD CONSTRAINT FK_MassPayItem_MassPayId__1 FOREIGN KEY (MassPayId) REFERENCES dbo.MassPay(MassPayId) go create table dbo.RecurringPayment ( RecurringPaymentId int not null primary key identity(1,1), TransactionAndNotificationId int not null, Amount money not null, AmountPerCylcle money not null, InitialPaymentAmount money not null, InvoiceId varchar(127) null, NextPaymentDate datetime null, OutstandingBalance money not null, PaymentCycle varchar(255) null, PeriodType varchar(255) null, ProductName varchar(255) null, ProductType varchar(255) null, ProfileStatus varchar(255) null, PayPalRecurringPaymentId varchar(255) not null, TimeCreated datetime null ) go ALTER TABLE dbo.RecurringPayment ADD CONSTRAINT FK_RecurringPayment_PaymentInfoId__1 FOREIGN KEY (TransactionAndNotificationId) REFERENCES dbo.TransactionAndNotification(TransactionAndNotificationId) go create table dbo.Subscription ( SubscriptionId int not null primary key identity(1,1), TransactionAndNotificationId int not null, Amount1 money not null, Amount2 money not null, Amount3 money not null, MCAmount1 money not null, MCAmount2 money not null, MCAmount3 money not null, [Password] varchar(255) null, Period1 varchar(255) null, Period2 varchar(255) null, Period3 varchar(255) null, Reattempt varchar(1) null, Recurring varchar(1) null, RecurTimes varchar(10) null, RetryAt datetime null, SubscrDate datetime null, SubscrEffective datetime null, SubscrId varchar(19) not null, UserName varchar(255) null ) go ALTER TABLE dbo.Subscription ADD CONSTRAINT FK_Subscription_PaymentInfoId__1 FOREIGN KEY (TransactionAndNotificationId) REFERENCES dbo.TransactionAndNotification(TransactionAndNotificationId) go
-
Create a LINQ class to access the database.
All editions of Visual Studio 2008 or higher allow easy creation of LINQ classes using built in Visual Studio graphical tools. Just drag and drop the tables onto the design surface and save / compile.
-
Hook up IPN Easy for .NET to the LINQ classes that you created above.
CopyC#-#region Usings using System; using System.Globalization; using System.IO; using System.Linq; using System.Web.UI; using System.Xml.Serialization; using Rolosoft.IpnEasy.Net; using Rolosoft.IpnEasy.Net.PayPal; #endregion namespace IpnEasyDemo { public partial class Database : Page { private readonly Ipn _ipnEasy; protected Database() { _ipnEasy = new Ipn(); _ipnEasy.TransactionReceived += IpnEasyTransactionReceived; } protected override void OnInit(EventArgs e) { if (Request.HttpMethod == "POST") { MaintainDb(); _ipnEasy.Validate(); } base.OnInit(e); } protected void Page_Load(object sender, EventArgs e) { } private static void IpnEasyTransactionReceived(object sender, TransactionEventArgs e) { var payPalTransaction = e.Transaction; var log = e.Log; using (var context = new Code.Data.PayPalIpnDbDataContext()) { var newTransactionAndNotification = new Code.Data.TransactionAndNotification { Business = payPalTransaction.TransactionAndNotification.Business, Charset = payPalTransaction.TransactionAndNotification.Charset, Custom = payPalTransaction.TransactionAndNotification.Custom, NotifyVersion = payPalTransaction.TransactionAndNotification. NotifyVersion, ParentTxnId = payPalTransaction.TransactionAndNotification.ParentTxnId, ReceiverEmail = payPalTransaction.TransactionAndNotification. ReceiverEmail, ReceiverId = payPalTransaction.TransactionAndNotification.ReceiverId, ResidenceCountry = payPalTransaction.TransactionAndNotification. ResidenceCountry, TxnId = payPalTransaction.TransactionAndNotification.TxnId, TxnType = payPalTransaction.TransactionAndNotification.TxnType. ToString(), VerifySign = payPalTransaction.TransactionAndNotification.VerifySign }; if (!String.IsNullOrEmpty(payPalTransaction.TransactionAndNotification.TestIpn)) newTransactionAndNotification.TestIpn = payPalTransaction.TransactionAndNotification. TestIpn.First(); if (payPalTransaction.Auction != null) newTransactionAndNotification.Auctions.Add(new Code.Data.Auction { BuyerID = payPalTransaction.Auction.BuyerId, ClosingDate = payPalTransaction.Auction.ClosingDate, ForAuction = payPalTransaction.Auction.ForAuction, MultiItem = payPalTransaction.Auction.MultiItem }); if (payPalTransaction.BuyerInformation != null) newTransactionAndNotification.BuyerInformations.Add( new Code.Data.BuyerInformation { AddressCity = payPalTransaction.BuyerInformation.AddressCity, AddressCountry = payPalTransaction.BuyerInformation.AddressCountry, AddressCountryCode = payPalTransaction.BuyerInformation.AddressCountryCode, AddressName = payPalTransaction.BuyerInformation.AddressName, AddressState = payPalTransaction.BuyerInformation.AddressState, AddressStatus = payPalTransaction.BuyerInformation.AddressStatus.ToString(), AddressStreet = payPalTransaction.BuyerInformation.AddressStreet, AddressZip = payPalTransaction.BuyerInformation.AddressZip, ContactPhone = payPalTransaction.BuyerInformation.ContactPhone, FirstName = payPalTransaction.BuyerInformation.FirstName, LastName = payPalTransaction.BuyerInformation.LastName, PayerEmail = payPalTransaction.BuyerInformation.PayerEmail, PayerId = payPalTransaction.BuyerInformation.PayerId }); if (payPalTransaction.DisputeResolution != null) newTransactionAndNotification.DisputeResolutions.Add( new Code.Data.DisputeResolution { CaseCreationDate = payPalTransaction.DisputeResolution.CaseCreationDate, CaseId = payPalTransaction.DisputeResolution.CaseId, CaseType = payPalTransaction.DisputeResolution.CaseType.ToString(), ReasonCode = payPalTransaction.DisputeResolution.ReasonCode.ToString() }); if (payPalTransaction.PaymentInformation != null) { var newPaymentInfo = new Code.Data.PaymentInformation { AuthAmount = payPalTransaction.PaymentInformation.AuthAmount, AuthExpiry = payPalTransaction.PaymentInformation.AuthExpiry, AuthId = payPalTransaction.PaymentInformation.AuthId, AuthStatus = payPalTransaction.PaymentInformation.AuthStatus.ToString(), ExchangeRate = payPalTransaction.PaymentInformation.ExchangeRate, Invoice = payPalTransaction.PaymentInformation.Invoice, MCCurrency = payPalTransaction.PaymentInformation.MCCurrency.ToString(), MCFee = payPalTransaction.PaymentInformation.MCFee, MCGross = payPalTransaction.PaymentInformation.MCGross, MCHandling = payPalTransaction.PaymentInformation.MCHandling, MCShipping = payPalTransaction.PaymentInformation.MCShipping, Memo = payPalTransaction.PaymentInformation.Memo, NumCartItems = payPalTransaction.PaymentInformation.NumCartItems, OptionName1 = payPalTransaction.PaymentInformation.OptionName1, OptionName2 = payPalTransaction.PaymentInformation.OptionName2, OptionSelection1 = payPalTransaction.PaymentInformation.OptionSelection1, OptionSelection2 = payPalTransaction.PaymentInformation.OptionSelection2, PayerStatus = payPalTransaction.PaymentInformation.PayerStatus.ToString(), PaymentDate = payPalTransaction.PaymentInformation.PaymentDate, PaymentGross = payPalTransaction.PaymentInformation.PaymentGross, PaymentStatus = payPalTransaction.PaymentInformation.PaymentStatus.ToString(), PaymentType = payPalTransaction.PaymentInformation.PaymentType.ToString(), PendingReason = payPalTransaction.PaymentInformation.PendingReason.ToString(), ReasonCode = payPalTransaction.PaymentInformation.ReasonCode.ToString(), RemainingSettle = payPalTransaction.PaymentInformation.RemainingSettle, SellerProtectionEligibilityCode = payPalTransaction.PaymentInformation.SellerProtectionEligibilityCode.ToString(), SettleAmount = payPalTransaction.PaymentInformation.SettleAmount, SettleCurrency = payPalTransaction.PaymentInformation.SettleCurrency.ToString(), Shipping = payPalTransaction.PaymentInformation.Shipping, ShippingMethod = payPalTransaction.PaymentInformation.ShippingMethod, Tax = payPalTransaction.PaymentInformation.Tax, TransactionEntity = payPalTransaction.PaymentInformation.TransactionEntity.ToString() }; if (payPalTransaction.PaymentInformation.Items != null) foreach (var data in payPalTransaction.PaymentInformation.Items) newPaymentInfo.Items.Add( new Code.Data.Item { Name = data.Name, PayPalBasketItemNumber = data.PayPalBasketItemNumber, Qty = data.Qty, MCShipping = data.MCShipping, Sku = data.Sku, Tax = data.Tax, MCGross = data.MCGross, UnitAmount = data.UnitAmount }); newTransactionAndNotification.PaymentInformations.Add(newPaymentInfo); } if (payPalTransaction.MassPay != null) { var massPay = new Code.Data.MassPay { PaymentDate = payPalTransaction.MassPay.PaymentDate, PaymentStatus = payPalTransaction.MassPay.PaymentStatus.ToString(), ReasonCode = payPalTransaction.MassPay.ReasonCode.ToString(), }; if (payPalTransaction.MassPay.Items != null) foreach (var data in payPalTransaction.MassPay.Items) massPay.MassPayItems.Add( new Code.Data.MassPayItem { MassPayItemNumber = data.MassPayItemNumber, MCCurrency = data.MCCurrency.ToString(), MCFee = data.MCFee, MCGross = data.MCGross, MCHandling = data.MCHandling, PaymentDate = data.PaymentDate, PaymentStatus = data.PaymentStatus.ToString(), ReasonCode = data.ReasonCode.ToString(), ReceiverEmail = data.ReceiverEmail, Status = data.Status.ToString(), TxnId = data.TxnId, UniqueId = data.UniqueId }); newTransactionAndNotification.MassPays.Add(massPay); } if (payPalTransaction.RecurringPayment != null) newTransactionAndNotification.RecurringPayments.Add( new Code.Data.RecurringPayment { Amount = payPalTransaction.RecurringPayment.Amount, AmountPerCylcle = payPalTransaction.RecurringPayment.AmountPerCylcle, InitialPaymentAmount = payPalTransaction.RecurringPayment.InitialPaymentAmount, InvoiceId = payPalTransaction.RecurringPayment.InvoiceId, NextPaymentDate = payPalTransaction.RecurringPayment.NextPaymentDate, OutstandingBalance = payPalTransaction.RecurringPayment.OutstandingBalance, PaymentCycle = payPalTransaction.RecurringPayment.PaymentCycle, PeriodType = payPalTransaction.RecurringPayment.PeriodType, ProductName = payPalTransaction.RecurringPayment.ProductName, ProductType = payPalTransaction.RecurringPayment.ProductType, ProfileStatus = payPalTransaction.RecurringPayment.ProfileStatus, PayPalRecurringPaymentId = payPalTransaction.RecurringPayment.RecurringPaymentId, TimeCreated = payPalTransaction.RecurringPayment.TimeCreated }); if (payPalTransaction.Subscription != null) { var newSubscription = new Code.Data.Subscription { Amount1 = payPalTransaction.Subscription.Amount1, Amount2 = payPalTransaction.Subscription.Amount2, Amount3 = payPalTransaction.Subscription.Amount3, MCAmount1 = payPalTransaction.Subscription.MCAmount1, MCAmount2 = payPalTransaction.Subscription.MCAmount2, MCAmount3 = payPalTransaction.Subscription.MCAmount3, Password = payPalTransaction.Subscription.Password, Period1 = payPalTransaction.Subscription.Period1, Period2 = payPalTransaction.Subscription.Period2, Period3 = payPalTransaction.Subscription.Period3, RecurTimes = payPalTransaction.Subscription.RecurTimes, RetryAt = payPalTransaction.Subscription.RetryAt, SubscrDate = payPalTransaction.Subscription.SubscrDate, SubscrEffective = payPalTransaction.Subscription.SubscrEffective, SubscrId = payPalTransaction.Subscription.SubscrId, UserName = payPalTransaction.Subscription.UserName }; if (payPalTransaction.Subscription.Reattempt != null) newSubscription.Reattempt = payPalTransaction.Subscription.Reattempt.First(); if (payPalTransaction.Subscription.Recurring != null) newSubscription.Recurring = payPalTransaction.Subscription.Recurring.First(); newTransactionAndNotification.Subscriptions.Add(newSubscription); } if (log != null) { var ser = new XmlSerializer(typeof (Transaction)); string serializeXml; using (var sw = new StringWriter(CultureInfo.InvariantCulture)) { ser.Serialize(sw, payPalTransaction); serializeXml = sw.ToString(); sw.Close(); } newTransactionAndNotification.Logs.Add( new Code.Data.Log { HttpHeaders = log.HttpHeaders, RawData = log.RawData, Received = log.Received, RequestIP = log.RequestIP, VerificationTimer = log.VerificationTimer.Ticks, Xml = serializeXml }); } context.TransactionAndNotifications.InsertOnSubmit(newTransactionAndNotification); context.SubmitChanges(); } } /// <summary> /// Maintains the database to avoid filling up etc. /// </summary> private static void MaintainDb() { using(var context = new Code.Data.PayPalIpnDbDataContext()) { var countItems = context.TransactionAndNotifications.Count(); if (countItems < Global.ThisSettings.MaxLogStorage) return; var itemIdToDelete = (context.TransactionAndNotifications.OrderBy( oldestItem => oldestItem.TransactionAndNotificationId)).FirstOrDefault(); if(null!=itemIdToDelete) Code.Data.Maintain.Delete(itemIdToDelete.TransactionAndNotificationId); } } } }
CopyVB.NET-#Region "Usings" Imports System.Globalization Imports System.IO Imports System.Linq Imports System.Web.UI Imports System.Xml.Serialization Imports Rolosoft.IpnEasy.Net Imports Rolosoft.IpnEasy.Net.PayPal #End Region Namespace IpnEasyDemo Public Partial Class Database Inherits Page Private ReadOnly _ipnEasy As Ipn Protected Sub New() _ipnEasy = New Ipn() AddHandler _ipnEasy.TransactionReceived, AddressOf IpnEasyTransactionReceived End Sub Protected Overrides Sub OnInit(e As EventArgs) If Request.HttpMethod = "POST" Then MaintainDb() _ipnEasy.Validate() End If MyBase.OnInit(e) End Sub Protected Sub Page_Load(sender As Object, e As EventArgs) End Sub Private Shared Sub IpnEasyTransactionReceived(sender As Object, e As TransactionEventArgs) Dim payPalTransaction = e.Transaction Dim log = e.Log Using context = New Code.Data.PayPalIpnDbDataContext() Dim newTransactionAndNotification = New Code.Data.TransactionAndNotification() With { _ Key .Business = payPalTransaction.TransactionAndNotification.Business, _ Key .Charset = payPalTransaction.TransactionAndNotification.Charset, _ Key .[Custom] = payPalTransaction.TransactionAndNotification.[Custom], _ Key .NotifyVersion = payPalTransaction.TransactionAndNotification.NotifyVersion, _ Key .ParentTxnId = payPalTransaction.TransactionAndNotification.ParentTxnId, _ Key .ReceiverEmail = payPalTransaction.TransactionAndNotification.ReceiverEmail, _ Key .ReceiverId = payPalTransaction.TransactionAndNotification.ReceiverId, _ Key .ResidenceCountry = payPalTransaction.TransactionAndNotification.ResidenceCountry, _ Key .TxnId = payPalTransaction.TransactionAndNotification.TxnId, _ Key .TxnType = payPalTransaction.TransactionAndNotification.TxnType.ToString(), _ Key .VerifySign = payPalTransaction.TransactionAndNotification.VerifySign _ } If Not [String].IsNullOrEmpty(payPalTransaction.TransactionAndNotification.TestIpn) Then newTransactionAndNotification.TestIpn = payPalTransaction.TransactionAndNotification.TestIpn.First() End If If payPalTransaction.Auction IsNot Nothing Then newTransactionAndNotification.Auctions.Add(New Code.Data.Auction() With { _ Key .BuyerID = payPalTransaction.Auction.BuyerId, _ Key .ClosingDate = payPalTransaction.Auction.ClosingDate, _ Key .ForAuction = payPalTransaction.Auction.ForAuction, _ Key .MultiItem = payPalTransaction.Auction.MultiItem _ }) End If If payPalTransaction.BuyerInformation IsNot Nothing Then newTransactionAndNotification.BuyerInformations.Add(New Code.Data.BuyerInformation() With { _ Key .AddressCity = payPalTransaction.BuyerInformation.AddressCity, _ Key .AddressCountry = payPalTransaction.BuyerInformation.AddressCountry, _ Key .AddressCountryCode = payPalTransaction.BuyerInformation.AddressCountryCode, _ Key .AddressName = payPalTransaction.BuyerInformation.AddressName, _ Key .AddressState = payPalTransaction.BuyerInformation.AddressState, _ Key .AddressStatus = payPalTransaction.BuyerInformation.AddressStatus.ToString(), _ Key .AddressStreet = payPalTransaction.BuyerInformation.AddressStreet, _ Key .AddressZip = payPalTransaction.BuyerInformation.AddressZip, _ Key .ContactPhone = payPalTransaction.BuyerInformation.ContactPhone, _ Key .FirstName = payPalTransaction.BuyerInformation.FirstName, _ Key .LastName = payPalTransaction.BuyerInformation.LastName, _ Key .PayerEmail = payPalTransaction.BuyerInformation.PayerEmail, _ Key .PayerId = payPalTransaction.BuyerInformation.PayerId _ }) End If If payPalTransaction.DisputeResolution IsNot Nothing Then newTransactionAndNotification.DisputeResolutions.Add(New Code.Data.DisputeResolution() With { _ Key .CaseCreationDate = payPalTransaction.DisputeResolution.CaseCreationDate, _ Key .CaseId = payPalTransaction.DisputeResolution.CaseId, _ Key .CaseType = payPalTransaction.DisputeResolution.CaseType.ToString(), _ Key .ReasonCode = payPalTransaction.DisputeResolution.ReasonCode.ToString() _ }) End If If payPalTransaction.PaymentInformation IsNot Nothing Then Dim newPaymentInfo = New Code.Data.PaymentInformation() With { _ Key .AuthAmount = payPalTransaction.PaymentInformation.AuthAmount, _ Key .AuthExpiry = payPalTransaction.PaymentInformation.AuthExpiry, _ Key .AuthId = payPalTransaction.PaymentInformation.AuthId, _ Key .AuthStatus = payPalTransaction.PaymentInformation.AuthStatus.ToString(), _ Key .ExchangeRate = payPalTransaction.PaymentInformation.ExchangeRate, _ Key .Invoice = payPalTransaction.PaymentInformation.Invoice, _ Key .MCCurrency = payPalTransaction.PaymentInformation.MCCurrency.ToString(), _ Key .MCFee = payPalTransaction.PaymentInformation.MCFee, _ Key .MCGross = payPalTransaction.PaymentInformation.MCGross, _ Key .MCHandling = payPalTransaction.PaymentInformation.MCHandling, _ Key .MCShipping = payPalTransaction.PaymentInformation.MCShipping, _ Key .Memo = payPalTransaction.PaymentInformation.Memo, _ Key .NumCartItems = payPalTransaction.PaymentInformation.NumCartItems, _ Key .OptionName1 = payPalTransaction.PaymentInformation.OptionName1, _ Key .OptionName2 = payPalTransaction.PaymentInformation.OptionName2, _ Key .OptionSelection1 = payPalTransaction.PaymentInformation.OptionSelection1, _ Key .OptionSelection2 = payPalTransaction.PaymentInformation.OptionSelection2, _ Key .PayerStatus = payPalTransaction.PaymentInformation.PayerStatus.ToString(), _ Key .PaymentDate = payPalTransaction.PaymentInformation.PaymentDate, _ Key .PaymentGross = payPalTransaction.PaymentInformation.PaymentGross, _ Key .PaymentStatus = payPalTransaction.PaymentInformation.PaymentStatus.ToString(), _ Key .PaymentType = payPalTransaction.PaymentInformation.PaymentType.ToString(), _ Key .PendingReason = payPalTransaction.PaymentInformation.PendingReason.ToString(), _ Key .ReasonCode = payPalTransaction.PaymentInformation.ReasonCode.ToString(), _ Key .RemainingSettle = payPalTransaction.PaymentInformation.RemainingSettle, _ Key .SellerProtectionEligibilityCode = payPalTransaction.PaymentInformation.SellerProtectionEligibilityCode.ToString(), _ Key .SettleAmount = payPalTransaction.PaymentInformation.SettleAmount, _ Key .SettleCurrency = payPalTransaction.PaymentInformation.SettleCurrency.ToString(), _ Key .Shipping = payPalTransaction.PaymentInformation.Shipping, _ Key .ShippingMethod = payPalTransaction.PaymentInformation.ShippingMethod, _ Key .Tax = payPalTransaction.PaymentInformation.Tax, _ Key .TransactionEntity = payPalTransaction.PaymentInformation.TransactionEntity.ToString() _ } If payPalTransaction.PaymentInformation.Items IsNot Nothing Then For Each data As var In payPalTransaction.PaymentInformation.Items newPaymentInfo.Items.Add(New Code.Data.Item() With { _ Key .Name = data.Name, _ Key .PayPalBasketItemNumber = data.PayPalBasketItemNumber, _ Key .Qty = data.Qty, _ Key .MCShipping = data.MCShipping, _ Key .Sku = data.Sku, _ Key .Tax = data.Tax, _ Key .MCGross = data.MCGross, _ Key .UnitAmount = data.UnitAmount _ }) Next End If newTransactionAndNotification.PaymentInformations.Add(newPaymentInfo) End If If payPalTransaction.MassPay IsNot Nothing Then Dim massPay = New Code.Data.MassPay() With { _ Key .PaymentDate = payPalTransaction.MassPay.PaymentDate, _ Key .PaymentStatus = payPalTransaction.MassPay.PaymentStatus.ToString(), _ Key .ReasonCode = payPalTransaction.MassPay.ReasonCode.ToString() _ } If payPalTransaction.MassPay.Items IsNot Nothing Then For Each data As var In payPalTransaction.MassPay.Items massPay.MassPayItems.Add(New Code.Data.MassPayItem() With { _ Key .MassPayItemNumber = data.MassPayItemNumber, _ Key .MCCurrency = data.MCCurrency.ToString(), _ Key .MCFee = data.MCFee, _ Key .MCGross = data.MCGross, _ Key .MCHandling = data.MCHandling, _ Key .PaymentDate = data.PaymentDate, _ Key .PaymentStatus = data.PaymentStatus.ToString(), _ Key .ReasonCode = data.ReasonCode.ToString(), _ Key .ReceiverEmail = data.ReceiverEmail, _ Key .Status = data.Status.ToString(), _ Key .TxnId = data.TxnId, _ Key .UniqueId = data.UniqueId _ }) Next End If newTransactionAndNotification.MassPays.Add(massPay) End If If payPalTransaction.RecurringPayment IsNot Nothing Then newTransactionAndNotification.RecurringPayments.Add(New Code.Data.RecurringPayment() With { _ Key .Amount = payPalTransaction.RecurringPayment.Amount, _ Key .AmountPerCylcle = payPalTransaction.RecurringPayment.AmountPerCylcle, _ Key .InitialPaymentAmount = payPalTransaction.RecurringPayment.InitialPaymentAmount, _ Key .InvoiceId = payPalTransaction.RecurringPayment.InvoiceId, _ Key .NextPaymentDate = payPalTransaction.RecurringPayment.NextPaymentDate, _ Key .OutstandingBalance = payPalTransaction.RecurringPayment.OutstandingBalance, _ Key .PaymentCycle = payPalTransaction.RecurringPayment.PaymentCycle, _ Key .PeriodType = payPalTransaction.RecurringPayment.PeriodType, _ Key .ProductName = payPalTransaction.RecurringPayment.ProductName, _ Key .ProductType = payPalTransaction.RecurringPayment.ProductType, _ Key .ProfileStatus = payPalTransaction.RecurringPayment.ProfileStatus, _ Key .PayPalRecurringPaymentId = payPalTransaction.RecurringPayment.RecurringPaymentId, _ Key .TimeCreated = payPalTransaction.RecurringPayment.TimeCreated _ }) End If If payPalTransaction.Subscription IsNot Nothing Then Dim newSubscription = New Code.Data.Subscription() With { _ Key .Amount1 = payPalTransaction.Subscription.Amount1, _ Key .Amount2 = payPalTransaction.Subscription.Amount2, _ Key .Amount3 = payPalTransaction.Subscription.Amount3, _ Key .MCAmount1 = payPalTransaction.Subscription.MCAmount1, _ Key .MCAmount2 = payPalTransaction.Subscription.MCAmount2, _ Key .MCAmount3 = payPalTransaction.Subscription.MCAmount3, _ Key .Password = payPalTransaction.Subscription.Password, _ Key .Period1 = payPalTransaction.Subscription.Period1, _ Key .Period2 = payPalTransaction.Subscription.Period2, _ Key .Period3 = payPalTransaction.Subscription.Period3, _ Key .RecurTimes = payPalTransaction.Subscription.RecurTimes, _ Key .RetryAt = payPalTransaction.Subscription.RetryAt, _ Key .SubscrDate = payPalTransaction.Subscription.SubscrDate, _ Key .SubscrEffective = payPalTransaction.Subscription.SubscrEffective, _ Key .SubscrId = payPalTransaction.Subscription.SubscrId, _ Key .UserName = payPalTransaction.Subscription.UserName _ } If payPalTransaction.Subscription.Reattempt IsNot Nothing Then newSubscription.Reattempt = payPalTransaction.Subscription.Reattempt.First() End If If payPalTransaction.Subscription.Recurring IsNot Nothing Then newSubscription.Recurring = payPalTransaction.Subscription.Recurring.First() End If newTransactionAndNotification.Subscriptions.Add(newSubscription) End If If log IsNot Nothing Then Dim ser = New XmlSerializer(GetType(Transaction)) Dim serializeXml As String Using sw = New StringWriter(CultureInfo.InvariantCulture) ser.Serialize(sw, payPalTransaction) serializeXml = sw.ToString() sw.Close() End Using newTransactionAndNotification.Logs.Add(New Code.Data.Log() With { _ Key .HttpHeaders = log.HttpHeaders, _ Key .RawData = log.RawData, _ Key .Received = log.Received, _ Key .RequestIP = log.RequestIP, _ Key .VerificationTimer = log.VerificationTimer.Ticks, _ Key .Xml = serializeXml _ }) End If context.TransactionAndNotifications.InsertOnSubmit(newTransactionAndNotification) context.SubmitChanges() End Using End Sub ''' <summary> ''' Maintains the database to avoid filling up etc. ''' </summary> Private Shared Sub MaintainDb() Using context = New Code.Data.PayPalIpnDbDataContext() Dim countItems = context.TransactionAndNotifications.Count() If countItems < [Global].ThisSettings.MaxLogStorage Then Return End If Dim itemIdToDelete = (context.TransactionAndNotifications.OrderBy(Function(oldestItem) oldestItem.TransactionAndNotificationId)).FirstOrDefault() If itemIdToDelete IsNot Nothing Then Code.Data.Maintain.Delete(itemIdToDelete.TransactionAndNotificationId) End If End Using End Sub End Class End Namespace
With IPN Easy for .NET and the examples here, it should be possible for you to hook up IPNs to your database in just minutes.
