IAP Storefront for Atavism MMO Engine

In this detailed lesson, you will learn how to integrate PayPal payments into your Unity Web Store using both sandbox (test mode) and production (live mode). This process will ensure secure and reliable payment processing for your in-game store, making it easier for players to purchase items and manage transactions.

 


1. Sign Up for a PayPal Developer Account

Before you can integrate PayPal with your Unity Web Store, you’ll need to sign up for a PayPal Developer account. This account allows you to create both sandbox and live environments for testing and processing payments.

Steps to Create a PayPal Developer Account:

  • Go to the official PayPal Developer website.
  • Click on Sign Up to create an account. If you already have a PayPal business account, use the same credentials to log in.
  • Once logged in, you’ll be directed to the PayPal Developer Dashboard, where you can manage your API apps, sandbox accounts, and production settings.

By signing up, you gain access to PayPal’s developer tools, including sandbox testing and live payment processing, which are essential for smooth payment integration.


2. Create a PayPal App in Both Sandbox and Production Modes

With your PayPal Developer account set up, the next step is to create an app in both sandbox (testing environment) and production (live environment) modes. Each app will generate a unique Client ID and Client Secret, which will be used to authenticate your transactions between your Unity Web Store and PayPal.

Creating a PayPal App (Sandbox & Production):

  1. Navigate to the Dashboard on the PayPal Developer website.
  2. In the top menu, click on My Apps & Credentials.
  3. Scroll down to REST API apps and click on Create App.
  4. Name your app (e.g., “Unity Web Store Payment System”).
  5. Choose whether this app will be used in sandbox or production mode:
    • Sandbox: Choose this option if you want to create a testing app.
    • Production: Choose this option when you’re ready to process real payments.
  6. Once created, you will be provided with two key pieces of information:
    • Client ID: A public identifier for your app.
    • Client Secret: A private key used for authentication between your store and PayPal.

Create one app for Sandbox mode and one for Production mode. You will need both sets of credentials to toggle between testing and live payments.


3. Retrieve Client ID and Secret, and Store Them Correctly

Once you have your Client ID and Client Secret for both sandbox and production modes, the next step is to securely store these keys in your database. Your Unity Web Store plugin requires both sets of credentials to switch between testing and live modes.

Steps to Add Client ID and Secret to the Database:

  1. In your Store Settings page, locate the fields for PayPal Client ID and Client Secret.
  2. Add the Sandbox Client ID and Sandbox Client Secret to the appropriate fields. These will be used for testing your payment system.
  3. Similarly, add the Production Client ID and Production Client Secret to the corresponding fields for live payments.
  4. Make sure these keys are stored securely, as the Client Secret is sensitive information that should not be exposed publicly.

Note: Be careful not to mix up sandbox and production credentials, as this could cause errors during testing or live payments.


4. Testing in Sandbox Mode

It’s crucial to thoroughly test your payment system in sandbox mode before switching to live payments. PayPal’s sandbox environment allows you to simulate transactions without transferring real money, ensuring that your Unity Web Store functions correctly.

Steps to Test in Sandbox Mode:

  1. Toggle your store to sandbox mode by selecting the appropriate setting in your Store Settings. This ensures that the sandbox credentials (Client ID and Secret) are used for all transactions.
  2. Use a PayPal Sandbox Account to act as a buyer. You can create multiple test accounts (both buyer and seller) in the Sandbox Accounts section of your PayPal Developer Dashboard.
  3. Perform test transactions by adding items to your cart in the Unity Web Store and checking out using the sandbox PayPal credentials.
  4. Verify that:
    • Orders are created correctly.
    • Payments are processed without errors.
    • Notifications and email confirmations (if applicable) are sent to the buyer.
    • The store’s cart is cleared after a successful transaction.
  5. Use the PayPal Sandbox Dashboard to track test payments and ensure everything is working as expected.

Always complete several rounds of testing in sandbox mode, including edge cases like payment failures, cancellations, and retries.


5. Switching to Live Payments

Once you are confident that everything works perfectly in sandbox mode, you can switch to live payments by toggling your store’s payment mode to production.

How to Toggle Between Sandbox and Live Modes:

  1. In your store’s admin settings, you should find an option (paypal_sandbox) to switch between sandbox (testing) and production (live) modes.
  2. When you toggle to production mode, the store will automatically use the live Client ID and Client Secret stored in your database.
  3. The switch is seamless and does not require restarting your server or Unity client. Your store will instantly begin using the live PayPal environment for processing real payments.

Important:

  • Make sure to thoroughly test in sandbox mode before enabling live payments to avoid issues with real transactions.
  • Once in production mode, all payments are live, and real money will be transferred between accounts.

6. Best Practices for PayPal Integration

  • Test Frequently: Always use sandbox mode for any new feature or update to ensure everything works before going live.
  • Secure Your Keys: Never expose your PayPal credentials in client-side code or public repositories. Store them securely in your server configuration or database.
  • Monitor Transactions: Regularly check your PayPal account and logs to ensure transactions are processed correctly.
  • Toggle Mode with Ease: You can toggle between sandbox and live modes without restarting your service, making it easy to test new features or troubleshoot payment issues.

Final Thoughts:

By the end of this lesson, you should have a fully integrated PayPal payment system for your Unity Web Store, allowing users to securely purchase items using real or simulated transactions. Whether in sandbox mode or live production, you can confidently manage your store’s payment system with PayPal’s robust integration.