import com.pozirk.payment.android.InAppPurchase;
import com.pozirk.payment.android.InAppPurchaseEvent;
import com.pozirk.payment.android.InAppPurchaseDetails;
var _iap:InAppPurchase = null ;
var _producID:String = "premium" ;
function initInApp() {
_iap = new InAppPurchase();
//initialization of InAppPurchase
_iap.addEventListener(InAppPurchaseEvent.INIT_SUCCESS, onInitSuccess);
_iap.addEventListener(InAppPurchaseEvent.INIT_ERROR, onInitError);
// کلید RSA
_iap.init("HTUYULNCCFRDESYYG585JGDRHU-----");
}
function onInitSuccess(event:InAppPurchaseEvent):void
{
trace( "InAppBilling supported" );
_iap.addEventListener(InAppPurchaseEvent.PURCHASE_SUCCESS, onPurchaseSuccess);
_iap.addEventListener(InAppPurchaseEvent.PURCHASE_ERROR, onPurchaseError);
_iap.purchase(_producID, InAppPurchaseDetails.TYPE_INAPP);
}
function onInitError(event:InAppPurchaseEvent):void
{
trace( "InAppBilling not supported" );
trace(event.data); //trace error message
_iap.dispose();
trace("Dispose");
}
function onPurchaseSuccess(event:InAppPurchaseEvent):void
{
trace("Purchase Success");
trace(event.data); //product id
if(event.data == _producID ){
//در این قسمت پرداخت تایید شده و باید در اینجا قفل را باز کنیم و
// میشه با قرار دادن یه شیردآبجکت دفعات بعد تست کرد که آیا قفل باز شده یا نه
}
_iap.dispose();
trace("Dispose");
}
function onPurchaseError(event:InAppPurchaseEvent):void
{
trace(event.data); //trace error message
_iap.dispose();
trace("Dispose");
}
//====================================
bt1.addEventListener(MouseEvent.CLICK,funclick);
function funclick(evt:MouseEvent):void {
initInApp();
}