You can easily convert PayPal IPN messages into XML with just a few lines of code.
The following example shows how to implement an IPN listerner and write the IPN to an XML file on the local drive.
-
Create Xml.aspx
CopyC#using System; using System.IO; using System.Web.UI; using System.Xml.Serialization; namespace IpnEasyDemo { public partial class Xml : Page { private Rolosoft.IpnEasy.Net.Ipn _ipnEasy; protected void Page_Load(object sender, EventArgs e) { _ipnEasy = new Rolosoft.IpnEasy.Net.Ipn(); _ipnEasy.TransactionReceived += IpnEasyTransactionReceived; _ipnEasy.Validate(); } private static void IpnEasyTransactionReceived(object sender,Rolosoft.IpnEasy.Net.PayPal.TransactionEventArgs e) { //Serialize and save the IPN to local disk. //Note: You will need to give write permission to the IIS process (e.g. NETWORK SERVICE) to write the file to local disk var ser = new XmlSerializer(typeof(Rolosoft.IpnEasy.Net.PayPal.Transaction)); using (var fs = new FileStream(String.Concat(@"c:\", e.Transaction.TransactionAndNotification.TxnId, ".xml"), FileMode.CreateNew)) { ser.Serialize(fs, e.Transaction); fs.Close(); } } } }
CopyVB.NETImports System.IO Imports System.Web.UI Imports System.Xml.Serialization Namespace IpnEasyDemo Public Partial Class Xml Inherits Page Private _ipnEasy As Rolosoft.IpnEasy.Net.Ipn Protected Sub Page_Load(sender As Object, e As EventArgs) _ipnEasy = New Rolosoft.IpnEasy.Net.Ipn() AddHandler _ipnEasy.TransactionReceived, AddressOf IpnEasyTransactionReceived _ipnEasy.Validate() End Sub Private Shared Sub IpnEasyTransactionReceived(sender As Object, e As Rolosoft.IpnEasy.Net.PayPal.TransactionEventArgs) 'Serialize and save the IPN to local disk. 'Note: You will need to give write permission to the IIS process (e.g. NETWORK SERVICE) to write the file to local disk Dim ser = New XmlSerializer(GetType(Rolosoft.IpnEasy.Net.PayPal.Transaction)) Using fs = New FileStream([String].Concat("c:\", e.Transaction.TransactionAndNotification.TxnId, ".xml"), FileMode.CreateNew) ser.Serialize(fs, e.Transaction) fs.Close() End Using End Sub End Class End Namespace
-
Using the PayPal developer sandbox IPN test tool, post an IPN to your test page.
Note:
If you are using the PayPal developer sandbox IPN test tool, your IPN listener must be visible from the internet.
It may be possible to configure your router to use NAT port redirection to allow you to use the PayPal sandbox IPN test tool to send IPN messages to your local development machine. If you need assistance with this, please consult your network administrator.
-
The saved XML file can be found in the root of C:\ drive and saved with the file name {TxnId}.xml where TxnId is the PayPal transaction Id.
CopyXML<?xml version="1.0"?> <Transaction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <TransactionAndNotification> <Business>paypal@emailaddress.com</Business> <Custom>test custom data</Custom> <NotifyVersion>2.4</NotifyVersion> <ReceiverId>5HRS8SCK9NSJ2</ReceiverId> <TxnId>023456823</TxnId> <TxnType>None</TxnType> <VerifySign>AlUbUcinRR5pIo2KwP4xjo9OxxHMAi6.s6AES.4Z6C65yv1Ob2eNqrHm</VerifySign> </TransactionAndNotification> <BuyerInformation> <AddressCountry>United States</AddressCountry> <AddressCity>Los Angeles</AddressCity> <AddressName>Jason Anderson</AddressName> <AddressState>CA</AddressState> <AddressStatus>confirmed</AddressStatus> <AddressStreet>1234 Rock Road</AddressStreet> <AddressZip>12345</AddressZip> <FirstName>Jason</FirstName> <LastName>Anderson</LastName> <PayerEmail>test@domain.com</PayerEmail> <PayerId>FW5W7ZUC3T4KL</PayerId> </BuyerInformation> <PaymentInformation> <AuthAmount>0</AuthAmount> <AuthExpiry xsi:nil="true" /> <AuthStatus>None</AuthStatus> <Invoice>123456</Invoice> <Items> <Item> <PayPalBasketItemNumber>1</PayPalBasketItemNumber> <Name>Rubber+clog</Name> <Qty>1</Qty> <Shipping>0.00</Shipping> <Sku>6</Sku> <Tax>0.00</Tax> <UnitPrice>0.01</UnitPrice> </Item> <Item> <PayPalBasketItemNumber>2</PayPalBasketItemNumber> <Name>Roman sandal</Name> <Qty>1</Qty> <Shipping>0.00</Shipping> <Sku>4</Sku> <Tax>0.00</Tax> <UnitPrice>0.01</UnitPrice> </Item> </Items> <MCCurrency>USD</MCCurrency> <MCFee>0.02</MCFee> <MCGross>500.00</MCGross> <MCHandling>0.00</MCHandling> <MCShipping>0.00</MCShipping> <NumCartItems>2</NumCartItems> <PayerStatus>verified</PayerStatus> <PaymentDate>2009-05-13T02:00:05</PaymentDate> <PaymentGross>0.02</PaymentGross> <PaymentStatus>Completed</PaymentStatus> <PaymentType>instant</PaymentType> <PendingReason>None</PendingReason> <SellerProtectionEligibilityCode>None</SellerProtectionEligibilityCode> <ReasonCode>None</ReasonCode> <RemainingSettle>0</RemainingSettle> <SettleAmount>0</SettleAmount> <SettleCurrency>None</SettleCurrency> <Shipping>0</Shipping> <Tax>0.00</Tax> <TransactionEntity>None</TransactionEntity> </PaymentInformation> <Verification>INVALID</Verification> </Transaction>
