Skip to main content

PayPal

This guide explains how to create and configure in-app purchases using PayPal payments.

info

Platforms having an own store do not allow PayPal payments for buying virtual goods as they want you to use their native billing system (e.g. Google Play or iTunes, so they can take their 30% cut). Because of this, you can basically only use PayPal when self-distributing the executable, or on Standalone and WebGL.

Prerequisites

warning

If you decide on accepting PayPal payments within your app, there are a few limitations and restrictions you need to be aware of!

  • You can only implement a third-party payment provider (like PayPal) when distributing your app by other means or on an App Store that do not have their own payment service. For example, Google Play and Apple have their own native billing service and by accepting their terms, you are forced into using that for in-app purchases.
  • PayPal does not offer its own user login and inventory service. This means: if users purchase products or subscriptions within your app using PayPal, they would lose access to them after switching devices or uninstalling the app. You are responsible for either providing a login and inventory system and storing purchases and updating subscription states on your server, or only offering one-time payments that do not need to be saved anywhere (e.g. consumables, donations).
  • If you are looking for PayPal payments including cloud save without the need of managing your own server, consider using IAPGUARD. IAPGUARD will validate your PayPal payments and stores them in the cloud, so you only have to implement a user login system yourself.

Register developer account

Create a PayPal merchant account or login using your existing merchant account on the developer dashboard: https://developer.paypal.com/

Create your app

Navigate to Apps & Credentials and either use the Default Application or create a new one. For this guide, I am using the system generated Default Application.

Copy your Sandbox Client ID and Secret values for this app. You will need them later.

PayPal-Native010

Switch to Production and use or create a Default Application there too. Copy your Production Client ID and Secret values for later.

PayPal-Native020

Test Accounts

Navigate to Testing Tools > Sandbox Accounts and create a Business Account and at least one Personal Account for testing. Their password can be displayed at any time, so there is no need to remember them.

PayPal-Native030

Subscriptions

Make sure that you meet the prerequisites mentioned above before adding subscriptions. Please note that subscription plans are not added in the Developer Dashboard, but on the Business Accounts directly.

Log into sandbox.paypal.com with your Sandbox Business Account and password created in the previous step. Then, navigate to Pay & Get Paid > Accept Payments > Subscriptions, Subscription plans tab. Create a plan with the same product identifier used in UniPay. The plan ID will be generated by PayPal.

PayPal-Native040

info

Now, do the same with your live Business Account on paypal.com !

Setup in Unity

Copy-paste the Client ID and Secret credentials for both Sandbox and Production into the UniPay Setup window. Unity IAP needs to be imported and enabled.

PayPal-Native050

You might wonder what the currency code and return URL is for. The Currency Code is a 3-character code for defining your receiving currency, e.g. USD or EUR. For other supported currency codes please refer to the official documentation.

The Return URL is the URL users get redirected to after payment. This could be a custom Thank you website, or a server page processing purchase information. Typically this is just a page on your website or domain.

Since when using subscriptions PayPal generated a cryptic product ID for you, it makes also sense to add a product ID override, so that this generic product ID is not displayed to the user anywhere.

PayPal-Native070

warning

UniPay does not support different product overrides for Sandbox and Production environments. If you are testing subscriptions on Sandbox, the product override ID needs to be your Sandbox plan ID (from sandbox.paypal.com)! When going live, do not forget to replace this with your Production plan ID (from paypal.com)!

Testing payments

If you've followed this guide until now, you have already created test accounts in a previous step, namely a Business Account and at least one Personal Account. A sandbox business account is a merchant account, where test payments are routed to. A sandbox personal account is a client account used to do a test purchase. Meaning, after logging in with the sandbox personal account for buying a product in your app, you will see the change in balance on the sandbox business account.

Before doing a test purchase, there is one additional step you definitely want to look into - in case you've read the PayPal documentation page above about currency codes, it is mentioned that by default, PayPal declines all payments in a different currency than specified on your PayPal account. You can change this behavior into accepting but converting all currencies, which I would recommend.

Log into your Sandbox Business Account on sandbox.paypal.com. Navigate to Account Settings > Payment preferences > Block Payments. Make sure that the first or third option is selected - otherwise, payments will never complete automatically.

PayPal-Native080

info

Do the same with your live Business Account on paypal.com !

Finally, launch your app and buy the product you've enabled PayPal for. Notice that by clicking the purchase button, an in-game popup opens, as well as a new browser page.

Feature-Windows022

On the PayPal payment page, enter the sandbox personal account credentials and complete the payment process.

PayPal-Native090

Back in Unity, wait for the CONFIRM button to appear and press it to confirm your transaction.

Feature-Windows021

If you wish to, you can also double check the completed transaction and shipping details by logging into the sandbox business account again.

By default, UniPay always connects to the PayPal Sandbox environment in the Unity Editor, or if you have Development Build enabled under File > Build Settings. If you wish to deploy to Production, check your production PayPal credentials in the Project Settings and disable Development Build.

info

Please note that in case of issues with this process, I am not able to guess or remotely debug the exact cause for you. Since a major part of this guide is not written for UniPay in particular, there is a high chance that your issue has been experienced by many, many other developers before and is covered somewhere already - debug your device, do a Google search for the error message and look out for popular PayPal developer threads!

tip

If you need help with the app setup, testing process or solving issues with your app's connection to PayPal, I am providing extended support for this via PREMIUM support. Contact me on the Unity Forum or on Discord to discuss your requirements.