Author Topic: Guide: PayPal  (Read 1599 times)

Offline Baroni

  • Administrator
  • *****
  • Posts: 1399
    • View Profile
Guide: PayPal
« on: July 15, 2017, 11:19:05 pm »
This guide explains how to configure PayPal payments for use in Simple IAP System, viable on WebGL and Standalone platforms - note that 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). However, using PayPal on these platforms is allowed for selling physical goods too, such as t-shirts, stuffed animals and other merchandise, which the native stores do not support selling.

Table of Contents:
  • Prerequisites
  • Connecting PayPal with PlayFab
  • Adding PayPal account permissions
  • Shop setup in Unity
  • Testing PayPal payments



1.   Prerequisites

Needless to say, using PayPal payments requires having a PayPal account. The creation of a PayPal account is not something described here, so it is assumed that you already have a verified and registered PayPal account. It is recommended to use a PayPal business account, as that allows you to specify your company name on payments. If you have an existing personal account, you can also upgrade it to a business account in your profile settings.

Additionally, since PayPal payments are passed through the player's account on PlayFab, it is required that you've gone through our PlayFab integration guide (Full Suite) as well and understand all limitations implied by this dependency. Namely, your app needs an active internet connection at all times, in addition to providing a login system for restoring user purchases between sessions. This limitation could be lifted if you are only using PayPal for selling physical goods and do not need to maintain a consistent user inventory for these type of in-app purchases.



2.   Connecting PayPal with PlayFab

PayPal payments are a separate extension on your title's PlayFab page, which you can find in the Add-ons > Monetization tab. Click on the PayPal Add-on and enter the required details to enable it within PlayFab.

You can find your "PayPal Merchant ID" in your PayPal account, under Profile > Account settings > Merchant account ID, or just enter the email address you've registered with on PayPal. The "PayPal Return Link" is the page where users get redirected to after a complete or cancelled purchase. The order ID and token get attached to the url, so you could retrieve it for a custom action on your own server, for example. Otherwise, a simple public url would do, e.g. your game's support website, as the final transaction confirmation will happen in-game (more on this later).





3.   Adding PayPal account permissions

In the last chapter you've told PlayFab your PayPal credentials. But at this point, PlayFab still does not have the permission to execute anything on PayPal on your behalf. So in order to grant them access for handling your checkouts, you have to navigate to the following menu while logged in with your PayPal account: Tools > All Tools > API Access > Grant API permission, or click on this direct link for the third party permission page.

As the "Third Party Permission Username", enter billing_api1.playfab.com and press on "Lookup" to proceed to the permission administration page. The only permission you need to grant access to is the very first permission listed on the screenshot below - the permission for letting PlayFab do express checkouts for you. Check it and click on the "Add" button.





4.   Shop setup in Unity

You are probably familiar with how the default shop scene in Simple IAP System is built: the IAPManager prefab usually gets carried over from a different (the first) scene, but the shop scene contains the ShopManager prefab, and in its component inspector, references to a UI window for displaying success/error messages whenever users purchase a product.

Now with the PayPal integration, you might have noticed that there is an additional UI window, a confirmation window, in the scene that is also referenced on the ShopManager prefab.



This confirmation window is necessary for completing any open PayPal transaction in-game. As the PayPal payment does not happen in-game, but in the user's browser (for security reasons), your app cannot know when the transaction has gone through successfully. Because of that, the transaction needs to be refreshed in-game after payment, so that it can be completed by PlayFab. In turn, the user is granted the appropriate product he purchased. This also means that without refreshing the transaction in-game, no reward will be given as the payment has not been authorized on PayPal's side (and no funds will be deducted on the user's PayPal account).



The confirmation window is being shown automatically at the time a PayPal payment gets initiated. It has two hidden buttons though, which are not shown right at the beginning: the actual refresh and close button. These buttons will only show up after a certain amount of time has passed (20 seconds by default). This is to ensure that the user cannot refresh the transaction right away (which would return a failed transaction state), but has actually to pay for the product in the browser first. If the refresh button is pressed in-game while the PayPal payment is not finished yet, the refresh button gets hidden for another 10 seconds, whereafter the user can retry again. A successful refresh disables the confirmation window.



5.   Testing PayPal payments

Unfortunately, PlayFab does not support PayPal's sandbox environment. In order to test PayPal payments, you have to use a real PayPal account and pay real money. I would recommend setting up a product for $0.01 in Simple IAP System / PlayFab, so you are not losing that much money for testing per transaction. You also have to use two separate PayPal accounts for testing, as your PayPal (business) account cannot buy products from itself.

« Last Edit: July 16, 2017, 07:32:39 pm by Baroni »