4.0.4 • Published 5 days ago

com.taptap.tds.payments.global.v2 v4.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
5 days ago

Environment Requirements

  • Supports Unity 2019.4 or higher.

Getting Ready

  • Refer to Before You Start to create an app, enable app configuration, and bind API domains;
  • Refer to TapSDK Quickstart to configure package name and signature certificate;

Getting the SDK

External Dependency Manager for Unity(EDM4U)

Tap payment depends on EDM4U to handle android dependency.

install via OpenUPM

EDM4U is available via OpenUPM, you can add it via Edit -> Project Settings -> Package Manager

alt text

local UPM Package

You can also download UPM version from Google APIs for Unity. And install as a local file

TapPayment SDK

Payment SDK is available via NPMJS, you can add it via Edit -> Project Settings -> Package Manager

alt text Then you will be able to install Taptap Payment Global V2 from Window -> Package Manager

alt text

Android Dependency

EDM4U will automatically monitor Android dependency introduced by TapPayment SDK, but under some circumstances the auto resolve can fail. You can always go to Assets -> External Dependency Manager -> Android Resolver -> Force Resolve to force resolving dependencies. Please make sure com.taptap.android.payment:unity is successfully added as dependency to mainTemplate.gradle, if this is not done by the EDM4U you can also add this manually.

SDK Guide

We provide a new store implementation for the Unity IAP flow, which requires minmal changes if your game already have an IAP flow with Google Play or App Store. If you are implementing IAP for the first time, we will briefly cover the IAP flow and you can always find more details on Unity Documentation

Initialize Unity Gaming Services

Call UnityServices.InitializeAsync() to initialize all Unity Gaming Services at once. It returns a Task that enables you to monitor the initialization's progression.

using System;
using Unity.Services.Core;
using Unity.Services.Core.Environments;
using UnityEngine;

public class InitializeUnityServices : MonoBehaviour
{
    public string environment = "production";

    async void Start()
    {
        try
        {
            var options = new InitializationOptions()
                .SetEnvironmentName(environment);

            await UnityServices.InitializeAsync(options);
        }
        catch (Exception exception)
        {
            // An error occurred during services initialization.
        }
    }
}

Initialize IAP

Make sure you add TapPurchasingModule and set the correct clientId and clientToken in the config.

using UnityEngine;
using UnityEngine.Purchasing;
using TapTap.Payments.Global.V2;

public class MyIAPManager : IStoreListener {

    private IStoreController controller;
    private IExtensionProvider extensions;

    public MyIAPManager () {
        var builder = ConfigurationBuilder.Instance(
            TapPurchasingModule.Instance, 
            StandardPurchasingModule.Instance);
        builder.Configure<ITapConfiguration>().SetClientId("Your Client ID Here");
        builder.Configure<ITapConfiguration>().SetClientToken("Your Client Token Here");
        builder.AddProduct("100_gold_coins", ProductType.Consumable, new IDs
        {
            {"100_gold_coins_google", GooglePlay.Name},
            {"100_gold_coins_mac", MacAppStore.Name}
        });

        UnityPurchasing.Initialize (this, builder);
    }

    /// <summary>
    /// Called when Unity IAP is ready to make purchases.
    /// </summary>
    public void OnInitialized (IStoreController controller, IExtensionProvider extensions)
    {
        this.controller = controller;
        this.extensions = extensions;
    }

    /// <summary>
    /// Called when Unity IAP encounters an unrecoverable initialization error.
    ///
    /// Note that this will not be called if Internet is unavailable; Unity IAP
    /// will attempt initialization until it becomes available.
    /// </summary>
    public void OnInitializeFailed (InitializationFailureReason error)
    {
    }

    /// <summary>
    /// Called when a purchase completes.
    ///
    /// May be called at any time after OnInitialized().
    /// </summary>
    public PurchaseProcessingResult ProcessPurchase (PurchaseEventArgs e)
    {
        return PurchaseProcessingResult.Complete;
    }

    /// <summary>
    /// Called when a purchase fails.
    /// </summary>
    public void OnPurchaseFailed (Product i, PurchaseFailureReason p)
    {
    }
}

Launch Purchase Flow

Once IAP is successfully initialized, you can now start purchase flow using IStoreController.InitiatePurchase

// Example method called when the user presses a 'buy' button
// to start the purchase process.
public void OnPurchaseClicked(string productId) {
    controller.InitiatePurchase(productId);
}

Processing Purchases

The ProcessPurchase function of your store listener is called when a purchase completes. Your application should fulfil whatever the user has bought; for example, unlocking local content or sending purchase receipts to a server to update a server-side game model.

A result is returned to indicate whether or not your Application has finished processing the purchase:

Note that ProcessPurchase may be called at any point following a successful initialization. If your application crashes during execution of the ProcessPurchase handler, then it is invoked again the next time Unity IAP initializes, so you may wish to implement your own additional de-duplication.

Reliability

Unity IAP requires explicit acknowledgement of purchases to ensure that purchases are reliably fulfilled in the event of network outages or application crashes. Any purchases that complete while the application is offline will be sent to the application on next initialization.

Completing purchases immediately

When PurchaseProcessingResult.Complete is returned, Unity IAP finishes the transaction immediately (as shown in the diagram below).

You must not return PurchaseProcessingResult.Complete if you are selling consumable products and fulfilling them from a server (for example, providing currency in an online game).

If you do, there is a risk that consumable purchases will be lost if your Application is uninstalled before the cloud save takes place.

alt text

Saving purchases to the cloud

If you are saving consumable purchases to the cloud, you must return PurchaseProcessingResult.Pending and call ConfirmPendingPurchase only when you have successfully persisted the purchase.

When returning Pending, Unity IAP keeps transactions open on the underlying store until confirmed as processed, ensuring consumable purchases are not lost even if a user reinstalls your application while a consumable is in this state.

alt text

4.0.4

5 days ago

4.0.2

10 days ago

1.0.9

1 month ago

1.0.7

1 month ago

1.0.4

2 months ago

1.0.2

2 months ago

1.0.3

2 months ago

1.0.1

2 months ago

0.1.7

2 months ago

0.1.6

2 months ago

0.1.5

2 months ago

0.1.2

2 months ago

0.1.4

2 months ago

0.1.3

2 months ago

0.1.1

2 months ago

0.1.0

2 months ago