Create Paypal Sandbox Account and Application



In this post I try to show how to create a sandbox account. Using this account how to create a payment gateway. I write the two type of code one is form post and another is server side post.

Create Account

1. Go to the site
2. Then click "Sign Up" for new account.
3. Select either the "Personal or Business radio button".
3.1 Email address: The email address doesn't need to be a real email address; the Sandbox doesn't send any email outside of the Sandbox environment. Email to Sandbox accounts, generated as a result of your test API requests, are listed on both the Notifications tab on the Developer site, as well as on the Sandbox test site. Use the assigned email value to reference this test account in your API calls, and to log in to the Sandbox site when you want to review the details associated with the account.
3.2 Password: The password must be 8-20 alpha-numeric characters in length. Use the password to log in to the Sandbox site as the test account.
3.3 First and Last name The optional name fields accept only alphabetical characters.
PayPal balance: While this field is optional, it's a good idea to create test accounts with positive bank balances. Enter an integer value between 1 and 10 Million.
Bank Verified Account: You should create both Verified and Unverified test accounts so you can fully test your application.
Select Payment Card:Test payments made with different payment cards by selecting either Discover or PayPal.(US Personal accounts only.)
Credit card type: Optionally, you can select a single credit card type for each test account. The Sandbox associates a mock credit card number with the account.
Notes: Add details specific to this test account.
4.Click "Create Account" after completing the account details.

Create New Sandbox Account

If you want to create new sandbox and show existing account Click here
1. Click "Create account"
2. Select "Account Details"
3. Select "Account Type (Personal or Business)"
4. After fill up all the details, click "Create Account" button
5. You can show new account in the list.

If you want to show your sandbox account details, then click on your "Account" then click "Profile".
A popup will be appear and you can show 4 tabs. Click on this to show you details, your bank details, credit card details. Also you can change the password by click Profile tab then click Change password link.

PayPal Payment Data Transfer (PDT) Settings

1. Log into your PayPal merchant account
2. Click "MyPayPal" button as show below
3. Click "Profile" on the top
4. Click "Profile and settings"
5. Click "My selling tools" --> "Selling online" --> "Website preferences" --> Click "Update" link
6. Set "Auto Return" On
7. Set "Return URL"
8. Set "Payment Data Transfer" On
9. Click "Save" button
10. Then click again "Website preferences" update to show the Identity token.

How To Change Business Name

1. Log into your PayPal merchant account
2. Click "MyPayPal" button as show below
3. Click "Profile" on the top
4. Click "Profile and settings"
Click "My business info" --> "Business information" --> Click "Update" link
In the "Business Contact Name" click "Change name" link
Check "Business Name Change (business name)" radio button and click "Continue"
Enter "New business name" --> "Continue" --> "Go to my account"
Your business name should be change.

Instant Payment Notification

Instant Payment Notification (IPN) notifies merchants almost instantly about transaction events, such as:
a) Payments received, including Express Checkout, and Adaptive Payments.
b) Credit card authorizations.
c) eCheck payments and related pending, completed, or denied status events.
d) Recurring payments and subscription actions.
e) Chargebacks, disputes, reversals, and refunds.

Enable Instant Payment Notification

1. Log into your PayPal merchant account
2. Click "MyPayPal" button as show below
3. Click "Profile" on the top
4. Click "My selling tools"
5. In the "Getting paid and managing my risk" section click "Update" link in "Instant payment notifications"
6. Click "Choose IPN Settings"
7. Specify the URL for your listener in the Notification URL field.
8. Click Receive IPN messages (Enabled) to enable your listener.
9. Click Save. The following screen appears:
10. Click Back to Profile Summary to return to the Profile after activating your listener. You also can click Edit settings to modify your notification URL or disable your listener. You can click Turn Off IPN to reset your IPN preferences.


Add inside the configuration in web.config
    <add key="PayPalUsername" value="" />
    <add key="PDTToken" value="lRrqzLMWpPZg7vYbITrui0N9vJz05iDsrO3xo9XB1xD8Vn59Cjn4fUNOkdG" />
    <add key="PayPalSubmitUrl" value="" />
    <add key="ReturnURL" value="http://[something]" />
    <add key="FailedURL" value="http://[something]" />
    <add key="NotificationURL" value="http://[something]" />
    <add key="cmdClick" value="_xclick" />
    <add key="cmdCart" value="_cart" />

View Code For Form POST

<div class="sty">
    <form action="@System.Configuration.ConfigurationManager.AppSettings["PayPalSubmitUrl"]" method="post">
        <input type="hidden" name="cmd" value="_xclick" />
        <input type="hidden" name="business" value="@System.Configuration.ConfigurationManager.AppSettings["PayPalUsername"]" />
        <input type="hidden" name="item_name" value="My painting" />
        <input type="hidden" name="amount" value="@ViewBag.amount" />
        <input type="hidden" name="return" value="@System.Configuration.ConfigurationManager.AppSettings["ReturnURL"]" />
        <input type="hidden" name="cbt" value="Click here to complete your purchase" />
        <input type="hidden" name="custom" value="Registration started: @DateTime.Now.ToString()" />
        <input type="hidden" name="rm" value="2" />
        <input type="submit" value="Payment" class="btn btn-default checkoutBT" />
        <br />
        <b>Use following credentials to pay:</b><br />
        <b>User: </b><br />
        <b>Password:</b> 123456789

Controller Code For Server Side POST

public ActionResult PaymentGateway()
    if (Session["UserID"] == null)
        return Redirect("/");
        int s = 1;
        string redirectitems = "";
        int quantity = 0;
        string cartItemName = "";
        var result = (dynamic)null;
        decimal total = 0;
        using (Entities db = new Entities())
            result = db.sp_getCartItem(Session["UserID"].ToString(), "UserID").ToList();
            foreach (var a in result)
                cartItemName += a.Title + ",";
                total += a.Price;
                redirectitems += "&item_name_" + s + "=" + a.Title + "&quantity_" + s + "=" + 1 + "&amount_" + s + "=" + a.Price;
            quantity = result.Count;
        return Redirect(RedirectToPaypal("", DateTime.Now.ToString(), "", "", redirectitems, total, quantity));

public string RedirectToPaypal(string invoiceNumber, string requestId, string userId, string customId, string itemName, decimal amount, Int32 quantity)
    string redirecturl = "";
    redirecturl += ConfigurationManager.AppSettings["PayPalSubmitUrl"].ToString() + "?cmd=" + ConfigurationManager.AppSettings["cmdCart"].ToString() + "&business=" + ConfigurationManager.AppSettings["PayPalUsername"].ToString();
    redirecturl += "&first_name=" + userId;
    redirecturl += "&upload=1";
    redirecturl += itemName;
    redirecturl += "&currency=SEK";
    redirecturl += "&invoice=" + invoiceNumber;
    redirecturl += "&custom=" + requestId;
    //redirecturl += "&on0=" + System.Web.HttpContext.Current.Request.UserHostAddress;
    redirecturl += "&return=" + ConfigurationManager.AppSettings["ReturnURL"].ToString() + "?tx=";
    redirecturl += "&cbt=Click here to complete your purchase";
    //redirecturl += "&rm=2";
    redirecturl += "&cancel_return=" + ConfigurationManager.AppSettings["FailedURL"].ToString();
    redirecturl += "&notify_url=" + ConfigurationManager.AppSettings["NotificationURL"].ToString();
    return redirecturl;

Paypal Payment Gateway View

After that it redirect to your return page.


I try to explain my best. If I missed anything please leave a comment.

You Might Also Like