Click here to Skip to main content
12,290,716 members (30,012 online)
Click here to Skip to main content

Stats

1.3M views
33.6K downloads
594 bookmarked
Posted

Introduction to PayPal for C# - ASP.NET developers

, 24 Mar 2015 CPOL
An overview that presents all PayPal integration options, targeted especially at C# developers.
LepiPele.PayPal
API
App_Data
IPN
Messages
PDT
Properties
Web References
com.paypal.sandbox.www
AddressVerifyResponseType.datasource
BAUpdateResponseType.datasource
BillOutstandingAmountResponseType.datasource
BillUserResponseType.datasource
BMButtonSearchResponseType.datasource
BMCreateButtonResponseType.datasource
BMGetButtonDetailsResponseType.datasource
BMGetInventoryResponseType.datasource
BMManageButtonStatusResponseType.datasource
BMSetInventoryResponseType.datasource
BMUpdateButtonResponseType.datasource
CreateBillingAgreementResponseType.datasource
CreateMobilePaymentResponseType.datasource
CreateRecurringPaymentsProfileResponseType.datasource
DoAuthorizationResponseType.datasource
DoCaptureResponseType.datasource
DoDirectPaymentResponseType.datasource
DoExpressCheckoutPaymentResponseType.datasource
DoMobileCheckoutPaymentResponseType.datasource
DoNonReferencedCreditResponseType.datasource
DoReauthorizationResponseType.datasource
DoReferenceTransactionResponseType.datasource
DoUATPAuthorizationResponseType.datasource
DoUATPExpressCheckoutPaymentResponseType.datasource
DoVoidResponseType.datasource
EnterBoardingResponseType.datasource
GetAccessPermissionDetailsResponseType.datasource
GetAuthDetailsResponseType.datasource
GetBalanceResponseType.datasource
GetBillingAgreementCustomerDetailsResponseType.datasource
GetBoardingDetailsResponseType.datasource
GetExpressCheckoutDetailsResponseType.datasource
GetMobileStatusResponseType.datasource
GetPalDetailsResponseType.datasource
GetRecurringPaymentsProfileDetailsResponseType.datasource
GetTransactionDetailsResponseType.datasource
ManagePendingTransactionStatusResponseType.datasource
ManageRecurringPaymentsProfileStatusResponseType.datasource
MassPayResponseType.datasource
PayPalSvc.wsdl
Reference.map
RefundTransactionResponseType.datasource
SetAccessPermissionsResponseType.datasource
SetAuthFlowParamResponseType.datasource
SetCustomerBillingAgreementResponseType.datasource
SetExpressCheckoutResponseType.datasource
SetMobileCheckoutResponseType.datasource
TransactionSearchResponseType.datasource
UpdateAccessPermissionsResponseType.datasource
UpdateRecurringPaymentsProfileResponseType.datasource
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace LepiPele.PayPal.PDT
{
    public class PDTHolder
    {
        public double GrossTotal { get; set; }
        public int InvoiceNumber { get; set; }
        public string PaymentStatus { get; set; }
        public string PayerFirstName { get; set; }
        public double PaymentFee { get; set; }
        public string BusinessEmail { get; set; }
        public string PayerEmail { get; set; }
        public string TxToken { get; set; }
        public string PayerLastName { get; set; }
        public string ReceiverEmail { get; set; }
        public string ItemName { get; set; }
        public string Currency { get; set; }
        public string TransactionId { get; set; }
        public string SubscriberId { get; set; }
        public string Custom { get; set; }

        public static PDTHolder Parse(string postData)
        {
            String sKey, sValue;
            PDTHolder ph = new PDTHolder();

            try
            {
                //split response into string array using whitespace delimeter
                String[] StringArray = postData.Split('\n');

                // NOTE:
                /*
                * loop is set to start at 1 rather than 0 because first
                string in array will be single word SUCCESS or FAIL
                Only used to verify post data
                */

                // use split to split array we already have using "=" as delimiter
                int i;
                for (i = 1; i < StringArray.Length - 1; i++)
                {
                    String[] StringArray1 = StringArray[i].Split('=');

                    sKey = StringArray1[0];
                    sValue = HttpUtility.UrlDecode(StringArray1[1]);

                    // set string vars to hold variable names using a switch
                    switch (sKey)
                    {
                        case "mc_gross":
                            ph.GrossTotal = Convert.ToDouble(sValue);
                            break;

                        case "invoice":
                            ph.InvoiceNumber = Convert.ToInt32(sValue);
                            break;

                        case "payment_status":
                            ph.PaymentStatus = Convert.ToString(sValue);
                            break;

                        case "first_name":
                            ph.PayerFirstName = Convert.ToString(sValue);
                            break;

                        case "mc_fee":
                            ph.PaymentFee = Convert.ToDouble(sValue);
                            break;

                        case "business":
                            ph.BusinessEmail = Convert.ToString(sValue);
                            break;

                        case "payer_email":
                            ph.PayerEmail = Convert.ToString(sValue);
                            break;

                        case "Tx Token":
                            ph.TxToken = Convert.ToString(sValue);
                            break;

                        case "last_name":
                            ph.PayerLastName = Convert.ToString(sValue);
                            break;

                        case "receiver_email":
                            ph.ReceiverEmail = Convert.ToString(sValue);
                            break;

                        case "item_name":
                            ph.ItemName = Convert.ToString(sValue);
                            break;

                        case "mc_currency":
                            ph.Currency = Convert.ToString(sValue);
                            break;

                        case "txn_id":
                            ph.TransactionId = Convert.ToString(sValue);
                            break;

                        case "custom":
                            ph.Custom = Convert.ToString(sValue);
                            break;

                        case "subscr_id":
                            ph.SubscriberId = Convert.ToString(sValue);
                            break;
                    }
                }

                return ph;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

lepipele
Chief Technology Officer
United States United States
If you liked this article, consider reading other articles by me. For republishing article on other websites, please contact me by leaving a comment.

Bitcoin wallet:
1ARXmh58S6aRiZPCbneDCzrB1HUU6PLmDQ

Blogs I enjoy:
http://blog.codinghorror.com/

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160518.1 | Last Updated 25 Mar 2015
Article Copyright 2009 by lepipele
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid