Comments (3)
This is my attempt of implementing your ANE in AS3..
I guess my main questions are about purchase flow, specifically the callback for sucessful and unsucesfull purchase, haven't been able to confirm ways to detect that purchase has failed, or has been canceled by user, or that user already owns the item etc.. after calling inApp.startPayment there doesn't seem to be a purchase specific error listener, and in SamsungIapPaymentEvent.PAYMENT event there also doesn't seem to be a "success" switch, or any error handling...
`package com.aadvarkstudios.babygames.inApp
{
import sk.krusty.ane.samsung.inapppurchase.item.;
import sk.krusty.ane.samsung.inapppurchase.;
import sk.krusty.ane.samsung.inapppurchase.event.*;
/**
* @author slav
*/
public class SamsungStore implements IStore
{
private var purchaseStatusCallback : Function;
private var onPurchaseSuccessCallback : Function;
private var onPurchaseCanceledCallback : Function;
private var unlockID : String;
private var trackEvent : Function;
private var alert : Function;
private var toggleLoadingModal : Function;
private var inApp : SamsungInAppPurchaseANE;
public function SamsungStore(unlockID : String, onPurchaseSuccessCallback:Function, purchaseStatusCallback : Function, onPurchaseCanceledCallback : Function, trackEvent : Function, alert : Function, toggleLoadingModal : Function)
{
this.unlockID = unlockID;
this.purchaseStatusCallback = purchaseStatusCallback;
this.trackEvent = trackEvent;
this.alert = alert;
this.toggleLoadingModal = toggleLoadingModal;
this.onPurchaseSuccessCallback = onPurchaseSuccessCallback;
this.onPurchaseCanceledCallback = onPurchaseCanceledCallback;
init();
}
private function init() : void
{
inApp = new SamsungInAppPurchaseANE();
inApp.addEventListener(SamsungIapEvent.INITIALIZED, onInitialised);
var inAppMode : int = CONFIG::DEBUG ? SamsungIapMode.IAP_MODE_TEST_SUCCESS : SamsungIapMode.IAP_MODE_COMMERCIAL;
inApp.initialize(inAppMode);
}
private function onInitialised(event : SamsungIapEvent) : void
{
if (inApp.isInitialized)
{
inApp.addEventListener(SamsungIapItemsLoadedEvent.ITEMS_LOADED, onItemsLoaded);
inApp.getItemList(0, 1, SamsungIapProductType.ITEM_TYPE_NON_CONSUMABLE);
}
}
private function onItemsLoaded(event : SamsungIapItemsLoadedEvent) : void
{
var unlockBought : Boolean = false;
var items : Vector.<ItemVo> = event.items;
for (var i : int = 0; i < items.length; i++)
{
var item : ItemVo = items[i];
if (item.storeId == unlockID) unlockBought = true;
}
purchaseStatusCallback(unlockBought);
}
public function purchaseItem( fakePurchase : Boolean = false, fakePurchaseSuccess:Boolean = true) : void
{
trackEvent("InApp_samsung","purchase","initiated");
toggleLoadingModal(true);
inApp.addEventListener(SamsungIapPaymentEvent.PAYMENT, onPaymentResponse);
inApp.addEventListener(SamsungIapErrorEvent.ERROR, onPaymentError);
inApp.startPayment(unlockID);
}
private function onPaymentError(event : SamsungIapErrorEvent) : void
{
trace("ERROR: "+event.rawData);
purchaseStatusCallback(false);
}
private function onPaymentResponse(event : SamsungIapPaymentEvent) : void
{
var purchase : Purchase = event.purchase;
toggleLoadingModal(false);
if (purchase.storeId == unlockID)
{
onPurchaseSuccessCallback();
trackEvent("InApp_Samsung","purchase","succes");
}
else
{
trackEvent("InApp_Samsung","purchase","fail");
onPurchaseCanceledCallback();
}
}
//stub for ios
public function restoreTransactions() : void { }
}
}`
from ane-samsung-in-app-purchase.
please see: SamsungIapError.as
private function onPaymentError(event:SamsungIapErrorEvent):void
{
switch (event.error.errorID) {
case SamsungIapError.IAP_ERROR_NONE :
// ...
break;
default:
dispatchPurchaseFailed(event.error.message);
}
}
from ane-samsung-in-app-purchase.
Thanks for that..
ok, so there's a single error handling listener for all possible eventualities that needs to be attached to the SamsungInAppPurchaseANE instance...
i.e not specific to the functionality flow ...
gotcha..
from ane-samsung-in-app-purchase.
Related Issues (3)
- ANE HOT 3
- upgrade to v5 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ane-samsung-in-app-purchase.