Skip to content

Repository files navigation

Appcharge Payment Links SDK (Unity)

A lightweight Unity SDK for integrating Appcharge Payment Links into your game. Use it to open a secure checkout, handle purchase callbacks, and fetch price points with minimal setup.

Features

  • 🔗 Open Appcharge checkout directly from your Unity game
  • 💳 Receive purchase success / failure callbacks
  • 💰 Fetch available price points
  • 🧩 Easy integration using ICheckoutPurchase
  • 📦 Distributed as a Unity Package Manager (UPM) package

Installation (UPM via Git URL)

  1. Open Unity
  2. Go to Window → Package Manager
  3. Click the + button → Add package from git URL…
  4. Enter your Git URL
  5. Click Add

Basic Usage

1. Import Required Namespaces

using Appcharge.PaymentLinks;
using Appcharge.PaymentLinks.Interfaces;
using Appcharge.PaymentLinks.Models;
using UnityEngine;

2. Implement ICheckoutPurchase

Create a MonoBehaviour that receives callbacks from the SDK:

    public class CheckoutSample : MonoBehaviour, ICheckoutPurchase
    {
        public AppchargeEnvironment Environment;
        public string CustomerId = "John Doe";
        // Initialize the SDK
        public void Init()
        {
            PaymentLinksController.Instance.Init(CustomerId, this);
        }
        // Backend returns checkout session → open checkout
        public void OnSessionSuccess(CheckoutResponse response)
        {
            PaymentLinksController.Instance.OpenCheckout(response.purchaseId, response.parsedUrl);
        }
        // Fetch price points
        public void GetPricePoints()
        {
            PaymentLinksController.Instance.GetPricePoints();
        }
        // --- ICheckoutPurchase callbacks ---
        public void OnPurchaseSuccess(OrderResponseModel order)
        {
            Debug.Log($"Purchase Success: OrderId={order.orderId}, PaymentMethod={order.paymentMethodName}");
        }
        public void OnPurchaseFailed(ErrorMessage error, OrderResponseModel order)
        {
            Debug.LogError($"Purchase Failed: Code={error.code}, Message={error.message}, OrderId={order?.orderId}");
        }
        public void OnInitialized()
        {
            Debug.Log("Payment Links SDK Initialized: " + PaymentLinksController.Instance.GetSdkVersion());
        }
        public void OnInitializeFailed(ErrorMessage error)
        {
            Debug.LogError($"Init Failed: Code={error.code}, Message={error.message}");
        }
        public void OnPricePointsSuccess(PricePointsModel pricePoints)
        {
            Debug.Log($"Price Points Success: {pricePoints.pricingPoints.Length} price points received");
        }
        public void OnPricePointsFail(ErrorMessage error)
        {
            Debug.LogError($"Price Points Fail: {error.message}");
        }
    }

Typical Integration Flow

1. Initialize the SDK

    PaymentLinksController.Instance.Init(CustomerId, this);

2. Create a checkout session (your backend)

Your backend returns the following:

  • purchaseId
  • parsedUrl (recommended), or url, checkoutSessionToken, and purchaseId

3. Open checkout

    PaymentLinksController.Instance.OpenCheckout(purchaseId, parsedUrl);
    // or (legacy):
    PaymentLinksController.Instance.OpenCheckout(url, checkoutSessionToken, purchaseId);

4. Handle purchase callbacks

  • OnPurchaseSuccess(OrderResponseModel order)
  • OnPurchaseFailed(ErrorMessage error, OrderResponseModel order)

5. Fetch price points

    PaymentLinksController.Instance.GetPricePoints();

Callbacks:

  • OnPricePointsSuccess(PricePointsModel pricePoints)
  • OnPricePointsFail(ErrorMessage error)

SDK API Overview

PaymentLinksController

  • Init(string customerId, ICheckoutPurchase callback)
  • Init(string checkoutToken, string environment, string customerId, ICheckoutPurchase callback)
  • OpenCheckout(string purchaseId, string parsedUrl)
  • OpenCheckout(string url, string checkoutSessionToken, string purchaseId)
  • GetPricePoints()
  • GetSdkVersion()

Models

  • CheckoutResponse
  • OrderResponseModel
  • PricePointsModel
  • ErrorMessage

Interface

  • ICheckoutPurchase

Support

For help or integration questions: Contact your Appcharge representative or open an issue in your repository.

About

unity-payment-links repository

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages