{"id":29572665,"url":"https://github.com/accelbyte/accelbyte-unity-sdk-apple","last_synced_at":"2025-07-19T05:10:48.637Z","repository":{"id":253884851,"uuid":"828816081","full_name":"AccelByte/accelbyte-unity-sdk-apple","owner":"AccelByte","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-17T08:28:34.000Z","size":31,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-17T09:33:38.271Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AccelByte.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-15T07:28:14.000Z","updated_at":"2025-03-17T08:28:29.000Z","dependencies_parsed_at":"2024-08-20T06:54:07.640Z","dependency_job_id":null,"html_url":"https://github.com/AccelByte/accelbyte-unity-sdk-apple","commit_stats":null,"previous_names":["accelbyte/accelbyte-unity-sdk-apple"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/AccelByte/accelbyte-unity-sdk-apple","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AccelByte%2Faccelbyte-unity-sdk-apple","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AccelByte%2Faccelbyte-unity-sdk-apple/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AccelByte%2Faccelbyte-unity-sdk-apple/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AccelByte%2Faccelbyte-unity-sdk-apple/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AccelByte","download_url":"https://codeload.github.com/AccelByte/accelbyte-unity-sdk-apple/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AccelByte%2Faccelbyte-unity-sdk-apple/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265892503,"owners_count":23845031,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-19T05:10:48.089Z","updated_at":"2025-07-19T05:10:48.626Z","avatar_url":"https://github.com/AccelByte.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AccelByte Unity SDK Apple #\n\nCopyright (c) 2024 AccelByte Inc. All Rights Reserved.\nThis is licensed software from AccelByte Inc, for limitations\nand restrictions contact your company contract manager.\n\n# Overview\nUnity SDK Apple is an extension package to enable Accelbyte SDK support for Apple. This plugin support the following features:\n\n## Prerequisiste ##\nRequire ([AccelByte Unity SDK](https://github.com/AccelByte/accelbyte-unity-sdk)) package. Minimum version: 17.5.1\n\nFor more information about configuring AccelByte Unity SDK, see [Install and configure the SDK](https://docs.accelbyte.io/gaming-services/getting-started/setup-game-sdk/unity-sdk/#install-and-configure).\n\n## How to Install ##\n1. Import \"Sign in with Apple Plugin for Unity\" from [Asset Store](https://assetstore.unity.com/packages/tools/integration/sign-in-with-apple-plugin-for-unity-152088)\n2. In your Unity project, go to `Window \u003e Package Manager`.\n3. Click the + icon on the Package Manager window and click `Add package from git URL...`\n4. Paste the following link into the URL field and click Add: `https://github.com/AccelByte/accelbyte-unity-sdk-apple.git`\n5. Install `AppleGamesPlugin-AccelByte.unitypackage` inside `_Install` directory.\n6. Add assembly reference of `Assets/AccelByteExtensions/Apple/com.AccelByte.AppleExtension` to your project.\n7. Access AccelByte Apple API from `AccelByte.ThirdParties.Apple.AccelByteApple`\n\n# Features Usage #\n\n## Sign In With Apple ##\n\nWe provide easier way to let the player perfrom Sign in With Apple platform.\nTherefore player doesn't need to register a new account to AGS to utilize the AGS features.\n\n### Code Implementation ###\n1. Header Initialization\n```csharp\nusing AccelByte.Core;\nusing AppleAuth;\nusing AppleAuth.Native;\nusing UnityEngine;\n```\n\n2. Get Apple Id Token\n```csharp\nprivate IAppleAuthManager appleAuthManager = null;\nprivate string appleIdToken = \"\";\n\nprivate void Start()\n{\n\tif (AppleAuthManager.IsCurrentPlatformSupported)\n\t{\n\t\tvar deserializer = new PayloadDeserializer();\n\t\tappleAuthManager = new AppleAuthManager(deserializer);\n\t}\n}\n\nprivate void Update()\n{\n    if (appleAuthManager != null)\n    {\n        appleAuthManager.Update();\n    }\n}\n\nprivate void GetAppleIdToken()\n{\n    AccelByte.ThirdParties.Apple.AccelByteApple.GetAppleSignInToken().OnSuccess(result =\u003e\n    {\n\t\tappleIdToken = result.AppleIdToken;\n        UnityEngine.Debug.Log(\"Obtain Apple Id Token Success\");\n    })\n    .OnFailed(result =\u003e\n    {\n        UnityEngine.Debug.LogWarning(\"Obtain Apple Id Token Failed\");\n    });\n}\n\n```\n\n3. Login to AGS\n```csharp\nprivate void AGSLogin()\n{\n    if (!string.IsNullOrEmpty(appleIdToken))\n    {\n        AccelByteSDK.GetClientRegistry().GetApi().GetUser().LoginWithOtherPlatformV4(\n            AccelByte.Models.PlatformType.Apple\n            , appleIdToken\n            , result =\u003e\n        {\n            if (result.IsError)\n            {\n                UnityEngine.Debug.LogError($\"Failed to Login with Apple Platfrom [{result.Error.error}]: {result.Error.error_description}\");\n                return;\n            }\n\n            UnityEngine.Debug.Log(\"Login with AccelByte IAM success\");\n        });\n    }\n}\n```\n\nThe full script on the package sample named \"Sign in with Apple\".\n\n## In-App Purchasing ##\n\n### Overview ###\n\nThere are three kind of `ProductType` based on [Unity Documentation](https://docs.unity3d.com/Manual/UnityIAPDefiningProducts.html). \nPreviously we support synchronize consumable, non-consumable entitlements with AccelByte server.\nAnd now also support subscription as well.\nHowever, it requires additional setup through admin portal to change the apple store integration configuration from `V1`(default) into `V2`.\n\n### Configure Your Game ###\n\n\u003e Please contact AccelByte support for guideline document\n\n### Prerequisite ###\n\nImport package [UnityPurchasing](https://docs.unity3d.com/Packages/com.unity.purchasing@4.8/manual/index.html) library to the project. \nThis plugin is tested using UnityPurchasing v4.8.0.\n\nPlease refers to official [Unity documentation](https://docs.unity3d.com/Manual/UnityIAPSettingUp.html) on how to install it.\n\n\u003e **Important** : Ensure that the player is already **Logged in** using AGS service before using this feature. You may check player's login status by using this snippet `bool isLoggedIn = AccelByteSDK.GetClientRegistry().GetApi().GetUser().Session.IsValid();` and `isLoggedIn` should return `true`.\n\n### Code Implementation ###\n1. Sign in With Apple, please refer to [previous part](https://github.com/AccelByte/accelbyte-unity-sdk-apple?tab=readme-ov-file#sign-in-with-apple)\n\n2. Please create `MonoBehavior` class implementing `IDetailedStoreListener`. Unity IAP will handle the purchase and trigger callbacks using this interface. Then prepare the following variables\n```csharp\nIStoreController storeController;\n\npublic Button BuyGoldButton;\npublic Button BuyWeaponButton;\npublic Button BuySeasonPassButton;\n\nprivate string goldProductId = \"item_gold\"; // assume that the registered consumable product id is named Item_gold\nprivate ProductType goldProductType = ProductType.Consumable;\nprivate string weaponProductId = \"item_weapon\"; // assume that the registered non-consumable product id is named item_weapon\nprivate ProductType weaponProductType = ProductType.NonConsumable;\nprivate string seasonPassProductId = \"item_season_pass\"; // assume that the registered subscription product id is named item_season_pass\nprivate ProductType seasonPassProductType = ProductType.Subscription;\n\nprivate AccelByte.Api.User user;\nprivate AccelByte.Api.Entitlement entitlement;\n```\n\n3. Prepare three [Buttons](https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/script-Button.html) to trigger the purchasing event. Using Unity Editor's inspector, attach those buttons into `public Button BuyGoldButton;`, `public Button BuyWeaponButton;`, and `public Button BuySeasonPassButton;`.\n\n4. Initialize Purchasing. \n```csharp\nvoid Start()\n{\n    InitializePurchasing();\n}\n\nvoid InitializePurchasing()\n{\n    var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());\n\n    //Add products that will be purchasable and indicate its type.\n    builder.AddProduct(goldProductId, goldProductType);\n    builder.AddProduct(weaponProductId, weaponProductType);\n    builder.AddProduct(seasonPassProductId, seasonPassProductType);\n    UnityPurchasing.Initialize(this, builder);\n\n    // Assign its ApplicationUsername\n    if (!string.IsNullOrEmpty(AccelByteSDK.GetClientRegistry().GetApi().GetUser().Session.UserId))\n    {\n        var uid = System.Guid.Parse(AccelByteSDK.GetClientRegistry().GetApi().GetUser().Session.UserId);\n        appleExtensions.SetApplicationUsername(uid.ToString());\n    }\n    else\n    {\n        Debug.LogError($\"Player is not Logged In. Several features may not work properly\");\n    }\n}\n\npublic void OnInitialized(IStoreController controller, IExtensionProvider extensions)\n{\n    Debug.Log(\"In-App Purchasing successfully initialized\");\n    storeController = controller;\n    appleExtensions = extensions.GetExtension\u003cIAppleExtensions\u003e();\n}\n```\n\n7. Prepare several functions that will be trigger the purchasing event\n```csharp\nprivate void BuyGold()\n{\n    storeController.InitiatePurchase(productId);\n}\n\nprivate void BuyWeapon()\n{\n    storeController.InitiatePurchase(weaponProductId);\n}\n\nprivate void BuySeasonPass()\n{\n    storeController.InitiatePurchase(seasonPassProductId);\n}\n```\n\n8. Assign each buttons\n```csharp\nvoid Start()\n{\n    ButtonAssigning();\n}\n\nvoid ButtonAssigning()\n{\n    BuyGoldButton.onClick.AddListener(BuyGold);\n    BuyWeaponButton.onClick.AddListener(BuyWeapon);\n    BuySeasonPassButton.onClick.AddListener(BuySeasonPass);\n}\n```\n\n9. Handle Process Purchase. Please note that it **must** return `PurchaseProcessingResult.Pending` because purchased item will be synchronized with AccelByte's Backend. [reference](https://docs.unity3d.com/2021.3/Documentation/Manual/UnityIAPProcessingPurchases.html). If client successfully purchase item from Apple, `ProcessPurchase` will be triggered, else `OnPurchaseFailed` will be triggered. Also **note** that subscription is treated differently with consumable and non-consumables.\n```csharp\npublic PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs purchaseEvent)\n{\n    var product = purchaseEvent.purchasedProduct;\n\n    Debug.Log($\"Purchase Complete - Product: {product.definition.id}\");\n    if (product.definition.type == ProductType.Subscription)\n    {\n        AGSSubscriptionEntitlementSync(product);\n    }\n    else\n    {\n        AGSEntitlementSync(product);\n    }\n    \n    return PurchaseProcessingResult.Pending;\n}\n\npublic void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)\n{\n    Debug.LogError($\"Purchase failed - Product: '{product.definition.id}', PurchaseFailureReason: {failureReason}\");\n}\n```\n\n10. Sync Purchased Product with AGS\n```csharp\nprivate void AGSEntitlementSync(Product purchasedProduct)\n{\n    // Please note that Sync will work after the player is logged in using AB service\n    try\n    {\n        string productId = purchasedProduct.definition.id;\n        string transactionId = purchasedProduct.appleOriginalTransactionID;\n        string receiptData = JObject.Parse(purchasedProduct.receipt)[\"Payload\"].ToString();\n\n        AccelByteSDK.GetClientRegistry().GetApi().GetEntitlement().SyncMobilePlatformPurchaseApple(productId\n            , transactionId\n            , receiptData\n            , result =\u003e\n            {\n                FinalizePurchase(purchasedProduct);\n                if (result.IsError)\n                {\n                    Debug.Log($\"{productId} failed to sync with AB [{result.Error.Code}]:{result.Error.Message}\");\n                    return;\n                }\n                Debug.Log($\"{productId} is synced with AB\");\n            });\n    }\n    catch (Exception e)\n    {\n        FinalizePurchase(purchasedProduct);\n        Debug.LogError($\"Failed to sync with AB {e.Message}\");\n    }\n}\n\nprivate void AGSSubscriptionEntitlementSync(Product purchasedSubscription)\n{\n    // Please note that Sync will work after the player is logged in using AB service\n    try\n    {\n        AccelByteSDK.GetClientRegistry().GetApi().GetEntitlement().SyncMobilePlatformSubscriptionApple(purchasedSubscription.appleOriginalTransactionID\n            , result =\u003e\n            {\n                FinalizePurchase(purchasedSubscription);\n                if (result.IsError)\n                {\n                    Debug.Log($\"{purchasedSubscription.definition.id} failed to sync with AB [{result.Error.Code}]:{result.Error.Message}\");\n                    return;\n                }\n                Debug.Log($\"{purchasedSubscription.definition.id} is synced with AB\");\n            });\n    }\n    catch (Exception e)\n    {                \n        FinalizePurchase(purchasedSubscription);\n        Debug.LogError($\"Failed to sync with AB {e.Message}\");\n    }\n}\n```\n\n11. Finalize Pending Purchase\n```csharp\nprivate void FinalizePurchase(Product purchasedProduct)\n{\n    Debug.Log($\"Confirm Pending Purchase for: {purchasedProduct.definition.id}\");\n    storeController.ConfirmPendingPurchase(purchasedProduct);\n}\n```\n\nThe full script on the package sample named \"In App Purchase\".","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faccelbyte%2Faccelbyte-unity-sdk-apple","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faccelbyte%2Faccelbyte-unity-sdk-apple","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faccelbyte%2Faccelbyte-unity-sdk-apple/lists"}