Skip to content

Commit

Permalink
Adjust docs to readme.io
Browse files Browse the repository at this point in the history
  • Loading branch information
liaz-af committed Oct 29, 2023
1 parent c5ba6e7 commit 6e34040
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 169 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/purchase-connector-unity-rdme.yml
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
180 changes: 11 additions & 169 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,174 +10,16 @@

> *When submitting an issue please specify your AppsFlyer sign-up (account) email , your app ID , production steps, logs, code snippets and any additional relevant information.*

## Table Of Content
* [This Plugin is Built for](#plugin-build-for)
* [Adding The Connector To Your Project](#install-connector)
* [ProGuard Rules](#proguard-rules)
* [Basic Integration Of The Connector](#basic-integration)
+ [Set up Purchase Connector](#create-instance)
+ [Log Auto-Renewable Subscriptions and In-App Purchases](#log-subscriptions)
+ [Conform to Purchase Connector Data Source and Delegate protocols](#conforming)
+ [Start Observing Transactions](#start)
+ [Stop Observing Transactions](#stop)
* [Testing the implementation in Sandbox](#testing)
* [Full Code Examples](#example)


## <a id="plugin-build-for"> This Module is Built for
- 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.

## <a id="install-connector"> Adding The Connector To Your Project:

1. Clone / download this repository.
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.

## <a id="proguard-rules"> 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.**{ *; }
```

## <a id="basic-integration"> Basic Integration Of The Connector
> *Note: before the implementation of the Purchase connector, please make sure to set up AppsFlyer `appId` and `devKey`*
### <a id="create-instance"> 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();

```


### <a id="log-subscriptions"> 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.*
### <a id="conforming"> 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

}
```


### <a id="start"> Start Observing Transactions

`startObservingTransactions` should be called to start observing transactions.

```c#
AppsFlyerPurchaseConnector.startObservingTransactions();
```


### <a id="stop"> 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*

## <a id="testing"> 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! *

***

## <a id="example"> Full Code Example

### 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);
}

```
- [This Plugin is Built for](./docs/purchaseConnectorUnity.md#prerequisites)
- [Adding The Connector To Your Project](./docs/purchaseConnectorUnity.md#adding-the-connector-to-your-project)
- [ProGuard Rules](./docs/purchaseConnectorUnity.md#proguard-rules)
- [Basic Integration Of The Connector](./docs/purchaseConnectorUnity.md#basic-integration)
- [Set up Purchase Connector](./docs/purchaseConnectorUnity.md#set-up-purchase-connector)
- [Log Auto-Renewable Subscriptions and In-App Purchases](./docs/purchaseConnectorUnity.md#log-auto-renewable-subscriptions-and-in-app-purchases)
- [Conform to Purchase Connector Data Source and Delegate protocols](./docs/purchaseConnectorUnity.md#get-purchase-validation-callback)
- [Start Observing Transactions](./docs/purchaseConnectorUnity.md#start-observing-transactions)
- [Stop Observing Transactions](./docs/purchaseConnectorUnity.md#stop-observing-transactions)
- [Testing the implementation in Sandbox](./docs/purchaseConnectorUnity.md#testing-the-implementation-in-sandbox)
- [Full Code Examples](./docs/purchaseConnectorUnity.md#full-code-example)
162 changes: 162 additions & 0 deletions docs/purchaseConnectorUnity.md
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);
}

```

0 comments on commit 6e34040

Please sign in to comment.