AghanimStore
Overview
AghanimStore
is an implementation of the IInAppStore interface that integrates with the Aghanim.
It provides purchasing functionality by creating payment orders on the Aghanim side and directing users to a web form for payment.
After completion, the SDK processes the order result and triggers corresponding events.
Events
OnProductFetched
event ProductFetchedDelegate OnProductFetched;
Triggered when a product has been successfully fetched and is ready for purchase.
OnProductFetchFailed
event ProductFetchFailedDelegate OnProductFetchFailed;
Triggered when a product could not be fetched or is unavailable in the store.
OnPurchaseFailed
event PurchaseFailedDelegate OnPurchaseFailed;
Triggered when a purchase fails due to user cancellation, network error, or any other issue.
OnPurchaseFinished
event PurchaseFinishedDelegate OnPurchaseFinished;
Triggered when a purchase is successfully completed and confirmed by Aghanim.
Properties
IsSandboxMode
bool IsSandboxMode { get; set; }
Determines whether the store operates in sandbox (test) mode for debugging and QA environments.
IsDisposed
bool IsDisposed { get; }
Indicates whether the store instance has been disposed and is no longer active.
Protected properties
PurchaseLinkHandler
IExternalLinkHandler PurchaseLinkHandler { get; }
Handles opening external purchase links provided by Aghanim.
Methods
IsProductReady
bool IsProductReady(ProductDef product)
Returns true if the specified product is associated with the Aghanim store and is ready to be purchased.
LoadProducts
void LoadProducts(IEnumerable<ProductDef> products)
Fetches and validates the provided product list.
Purchase
void Purchase(ProductDef product);
void Purchase(ProductDef product, CancellationToken cancellationToken);
This method must initiate purchasing logic.
RestorePurchases
UniTask RestorePurchases(CancellationToken cancellationToken)
Restores all previously purchased non-consumable products from the Aghanim server.
Triggers OnPurchaseFinished
for any unprocessed purchases.
Obsolete LoadSubscriptionInfo
[Obsolete]
SubscriptionInfo LoadSubscriptionInfo(string productId)
Subscriptions are not supported by Aghanim yet. Always returns null
.
Protected methods
Following methods might be overriden, but you should follow original logic.
PurchaseAsync
UniTaskVoid PurchaseAsync([NotNull] ProductDef product, CancellationToken cancellation)
Main method to process purchase:
- Issues an Aghanim order.
- Opens the returned order URL.
- Waits for the final order status.
- Calls
TryHandleOrder
based on the result.
TryHandleOrder
bool TryHandleOrder([NotNull] string productId, [NotNull] string orderId, AghanimOrderInfo orderInfo)
Handles the order result depending on its status:
- Paid → invokes
PurchaseFinished
; - Cancelled → invokes
PurchaseFailed
; - otherwise → returns
false
.
Handled order IDs are stored to avoid duplication.
PurchaseFailed
bool PurchaseFailed(string productId, ProductObtainFailReason reason)
Invokes OnPurchaseFailed
and logs any exceptions.
PurchaseFinished
bool PurchaseFinished(string productId, PurchaseInfo purchaseInfo)
Invokes OnPurchaseFinished
and logs any exceptions.