-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
196 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# This GitHub Actions workflow was auto-generated by the `rdme` cli on 2023-10-29T20:17:21.215Z | ||
# You can view our full documentation here: https://docs.readme.com/docs/rdme | ||
name: ReadMe GitHub Action 🦉 | ||
|
||
on: | ||
push: | ||
branches: | ||
# This workflow will run every time you push code to the following branch: `master` | ||
# Check out GitHub's docs for more info on configuring this: | ||
# https://docs.github.com/actions/using-workflows/events-that-trigger-workflows | ||
- master | ||
|
||
jobs: | ||
rdme-docs: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repo 📚 | ||
uses: actions/checkout@v3 | ||
|
||
- name: Run `docs` command 🚀 | ||
uses: readmeio/rdme@v8 | ||
with: | ||
rdme: docs ./docs/purchaseConnectorUnity.md --key=${{ secrets.README_API_KEY }} --version=0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
--- | ||
title: Purchase Connector | ||
category: 5f9705393c689a065c409b23 | ||
parentDoc: 6370c9e2441a4504d6bca3bd | ||
order: 13 | ||
hidden: false | ||
--- | ||
|
||
## Prerequisites | ||
|
||
- iOS version 9 and higher. | ||
- Unity AppsFlyer plugin **6.12.2** and higher. | ||
- Unity version **2020.3** and higher. | ||
- Google Billing Play version **5.x.x**. | ||
|
||
To use the module with earlier Unity AppsFlyer plugin versions, check the previous versions of this module, for instance, **v1.0.0** supports versions **6.8.1** and higher. | ||
|
||
## Adding The Connector To Your Project | ||
|
||
1. Clone / download [Purchase Connector repository](https://github.com/AppsFlyerSDK/appsflyer-unity-purchase-connector). | ||
2. [Import](https://docs.unity3d.com/Manual/AssetPackages.html) appsflyer-unity-purchase-connector-x.x.x.unitypackage into your Unity project. | ||
- Go to Assets >> Import Package >> Custom Package | ||
- Select appsflyer-unity-adrepurchase-connector-x.x.x.unitypackage. | ||
|
||
**Note:** You must have the [AppsFlyer Unity plugin](https://github.com/AppsFlyerSDK/appsflyer-unity-plugin) already in your project. In addition, make sure to init AppsFlyer SDK before Purchase Connector. | ||
|
||
## ProGuard Rules | ||
|
||
*Android Only* - If you are using ProGuard, add the following keep rules to your `proguard-rules.pro` file: | ||
|
||
```groovy | ||
-keep class com.appsflyer.** { *; } | ||
-keep class kotlin.jvm.internal.Intrinsics{ *; } | ||
-keep class kotlin.collections.**{ *; } | ||
``` | ||
|
||
## Basic Integration | ||
|
||
> *Note: before the implementation of the Purchase connector, please make sure to set up AppsFlyer `appId` and `devKey`* | ||
### Set up Purchase Connector | ||
|
||
> Notes: | ||
> | ||
> - The **AppsFlyerPurchaseConnector.init** api initialized the connector for both iOS and Android. However, the store parameter is only for Android stores. | ||
> - You only need to call the API **AppsFlyerPurchaseConnector.init** once with the android store as parameter and it will work for both platforms. | ||
> - For now, the only Android store available is Google. | ||
```c# | ||
using AppsFlyerSDK; | ||
using AppsFlyerConnector; | ||
|
||
// Default SDK Implementation | ||
AppsFlyer.initSDK(devKey, appID, getConversionData ? this : null); | ||
|
||
// Purchase connector implementation | ||
AppsFlyerPurchaseConnector.init(this, AppsFlyerConnector.Store.GOOGLE); | ||
AppsFlyerPurchaseConnector.setIsSandbox(true); | ||
AppsFlyerPurchaseConnector.setAutoLogPurchaseRevenue(AppsFlyerAutoLogPurchaseRevenueOptions.AppsFlyerAutoLogPurchaseRevenueOptionsAutoRenewableSubscriptions, AppsFlyerAutoLogPurchaseRevenueOptions.AppsFlyerAutoLogPurchaseRevenueOptionsInAppPurchases); | ||
AppsFlyerPurchaseConnector.build(); | ||
|
||
``` | ||
|
||
### Log Auto-Renewable Subscriptions and In-App Purchases | ||
|
||
Enables automatic logging of In-App purchases and Auto-renewable subscriptions. | ||
|
||
```c# | ||
AppsFlyerPurchaseConnector.setAutoLogPurchaseRevenue(AppsFlyerAutoLogPurchaseRevenueOptions.AppsFlyerAutoLogPurchaseRevenueOptionsAutoRenewableSubscriptions, AppsFlyerAutoLogPurchaseRevenueOptions.AppsFlyerAutoLogPurchaseRevenueOptionsInAppPurchases); | ||
``` | ||
|
||
> *Note: if `autoLogPurchaseRevenue` has not been set, it is disabled by default. The value is an option set, so you can choose what kind of user purchases you want to observe.* | ||
### Get purchase validation callback | ||
|
||
- In order to receive purchase validation event callbacks, you should conform to the purchase validation listenner and implement the callback | ||
|
||
```c# | ||
AppsFlyerPurchaseConnector.setPurchaseRevenueValidationListeners(true); | ||
/* ... */ | ||
|
||
public void didReceivePurchaseRevenueValidationInfo(string validationInfo) | ||
{ | ||
AppsFlyer.AFLog("didReceivePurchaseRevenueValidationInfo", validationInfo); | ||
// deserialize the string as a dictionnary, easy to manipulate | ||
Dictionary<string, object> dictionary = AFMiniJSON.Json.Deserialize(validationInfo) as Dictionary<string, object>; | ||
|
||
// if the platform is Android, you can create an object from the dictionnary | ||
#if UNITY_ANDROID | ||
if (dictionary.ContainsKey("productPurchase") && dictionary["productPurchase"] != null) | ||
{ | ||
// Create an object from the JSON string. | ||
InAppPurchaseValidationResult iapObject = JsonUtility.FromJson<InAppPurchaseValidationResult>(validationInfo); | ||
} elif (dictionary.ContainsKey("subscriptionPurchase") && dictionary["subscriptionPurchase"] != null) { | ||
SubscriptionValidationResult iapObject = JsonUtility.FromJson<SubscriptionValidationResult>(validationInfo); | ||
#endif | ||
|
||
} | ||
``` | ||
|
||
### Start Observing Transactions | ||
|
||
`startObservingTransactions` should be called to start observing transactions. | ||
|
||
```c# | ||
AppsFlyerPurchaseConnector.startObservingTransactions(); | ||
``` | ||
|
||
### Stop Observing Transactions | ||
|
||
To stop observing transactions, you need to call `stopObservingTransactions`. | ||
|
||
```c# | ||
AppsFlyerPurchaseConnector.stopObservingTransactions(); | ||
``` | ||
|
||
> *Note: if you called `stopObservingTransactions` API, you should set `autoLogPurchaseRevenue` value before you call `startObservingTransactions` next time.* | ||
> *Note: The Purchase Connector for Unity currently does not support adding Custom Parameters to purchase events* | ||
|
||
## Testing the implementation in Sandbox | ||
|
||
To set the sandbox environnment, you need to set `isSandbox` to true. </br> | ||
For iOS, it will allow you to test in Xcode environment on a real device with TestFlight sandbox account. </br> | ||
And for Android, it should be used while testing your [Google Play Billing Library integration](https://developer.android.com/google/play/billing/test). | ||
```c# | ||
AppsFlyerPurchaseConnector.setIsSandbox(true); | ||
``` | ||
|
||
> *IMPORTANT NOTE: Before releasing your app to production please be sure to remove `isSandbox` or set it to `false`. If the production purchase event will be sent in sandbox mode, your event will not be validated properly! * | ||
|
||
*** | ||
|
||
## Full Code Example | ||
|
||
```c# | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using AppsFlyerSDK; | ||
using UnityEngine.UI; | ||
using AppsFlyerConnector; | ||
|
||
void Start() | ||
{ | ||
AppsFlyer.initSDK(devKey, appID, getConversionData ? this : null); | ||
AppsFlyer.setIsDebug(isDebug); | ||
AppsFlyerPurchaseConnector.init(this, AppsFlyerConnector.Store.GOOGLE); | ||
AppsFlyerPurchaseConnector.setIsSandbox(true); | ||
AppsFlyerPurchaseConnector.setAutoLogPurchaseRevenue(AppsFlyerAutoLogPurchaseRevenueOptions.AppsFlyerAutoLogPurchaseRevenueOptionsAutoRenewableSubscriptions, AppsFlyerAutoLogPurchaseRevenueOptions.AppsFlyerAutoLogPurchaseRevenueOptionsInAppPurchases); | ||
AppsFlyerPurchaseConnector.setPurchaseRevenueValidationListeners(true); | ||
AppsFlyerPurchaseConnector.build(); | ||
AppsFlyerPurchaseConnector.startObservingTransactions(); | ||
AppsFlyer.startSDK(); | ||
} | ||
|
||
public void didReceivePurchaseRevenueValidationInfo(string validationInfo) | ||
{ | ||
AppsFlyer.AFLog("didReceivePurchaseRevenueValidationInfo", validationInfo); | ||
} | ||
|
||
``` |