Paypal Integration in ASP.Net

Basic requirement to Integration PayPal payment in Asp.Net application:


1. Should have PayPal Sandbox account (URL: https://developer.paypal.com/ ) for developer testing code.

2. Should have one buyer (Personal Account) and one seller account (Business Account) PayPal account.

3. PayPal API token (Signature) key

4. PayPal business account email id

5. Integrate PayPal payment with Application

Now let’s start step by step work to integrate PayPal payment.

Create PayPal account on PayPal Sandbox:

Basically, PayPal provides an environment to developer that how they can integrate PayPal payment in their website. So just open URL: https://developer.paypal.com/ and click on SignUpoption.
















Fill all the required information and click on button ‘Agree and Submit’,




Now first step has been completed and I am moving on second step (Create buyer and seller or personal and business account). After logged in PayPal payment panel, there is a preconfigured account option visible through which you can complete second step.











Now check out these two account information by selecting Test Account option logged in panel.









Now you have been completed second step successfully. Now I’m moving on third step (Having a valid PayPal API Token Key).

Now select ‘API and Payment Card Credential’ option from PayPal home.





Here you’ve a valid email id too, so all of the necessary things are over related with PayPal Account and payment API. Now I’m moving on Integration step.

So just create your web application in which you’re going to integrate PayPal payment. Here I’m just creating an application which contains some product information such as Product description, product price, product name and user can purchase it, simply, by clicking on ‘BuyNow’ button.

Coding:

string redirecturl = "";
//Mention URL to redirect content to paypal site
redirecturl += "https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=" +
ConfigurationManager.AppSettings["paypalemail"].ToString();
//First name i assign static based on login details assign this value
redirecturl += "&first_name=" + name;
//City i assign static based on login user detail you change this value
redirecturl += "&city=" + address.DeliveryAddress_CityName;
//State i assign static based on login user detail you change this value
redirecturl += "&state="+address.DeliveryAddress_StateName;
//Product Name
// redirecturl += "&item_name=" + itemInfo;
//Product Name
redirecturl += "&amount=" +getprice1(Convert.ToDecimal(ShippingCostCalculation()),"INR");
//Phone No
redirecturl += "&night_phone_a=" + address.DeliveryAddress_ContactNo;
//Product Name
redirecturl += "&item_name=" + itemInfo;
//Address
redirecturl += "&address1=" + address.DeliveryAddress_EmailId;
//Business contact id
redirecturl += "&business=k.tapankumar@gmail.com";
//Shipping charges if any
redirecturl += "&shipping=0";
//Handling charges if any
redirecturl += "&handling=0";
//Tax amount if any
redirecturl += "&tax=0";
//Add quatity i added one only statically
redirecturl += "&quantity=" + CARTDTL.ToList().Count;
//Currency code
redirecturl += "&currency=" + "USD";
//Success return page url
redirecturl += "&return=" +
ConfigurationManager.AppSettings["SuccessURL"].ToString();
//Failed return page url
redirecturl += "&cancel_return=" +
ConfigurationManager.AppSettings["FailedURL"].ToString();
Response.Redirect(redirecturl);


Set token and paypal email id in web.config file. And also set the success and fail request redirect url. After success or failure payment request where you want to send, you have to give that url in web.config file.

Web.config:

<add key="token" value="token value"/>
<add key="paypalemail" value="paypal emailid"/>

<!--Here i used sandbox site url only if you hosted in live change sandbox to live paypal URL-->

<add key="PayPalSubmitUrl" value="https://www.paypal.com/cgi-bin/webscr"/>
<add key="FailedURL" value="http://www.domainname.com/PaymentGateway.aspx?payPal=Failed"/>
<add key="SuccessURL" value="http://www.domainname.com/PaymentGateway.aspx?payPal=Success"/>


Post a Comment

0 Comments