Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Contributor
Gustavo_Bocalandro
Posts: 25
Registered: ‎02-05-2013
My Device: none
My Carrier: Personal
Accepted Solution

Help please!

[ Edited ]

Guys... I am getting crazy, already...

I am still working on this payment service. I have submitted 2 digital goods for approval to BB (extra life and a bomb).

I created a XML file with the info for those DGs (that is imported into the package) I have ran and tried the tutorial (advanced app) and it worked... then I modified it a little bit and tried it again, with what I need but keeping the xml from the tutorial... it worked fine...

Now I do need help PLEASEEEEE to add my items instead of the tutorial XML file...

Currently I am receiving an: Unable to retrieve digital goods from the server. so the buttons are shown but the List is not, so, of course, if you click on the button it throws an error.

 

Here is all what I have: 

 

Payment.as

package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.MouseEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.text.TextField;
	
	import net.rim.blackberry.events.PaymentErrorEvent;
	import net.rim.blackberry.events.PaymentSuccessEvent;
	import net.rim.blackberry.payment.PaymentSystem;
	import net.rim.blackberry.payment.Price;
	import net.rim.blackberry.payment.Purchase;
	
	import qnx.fuse.ui.buttons.LabelButton;
	import qnx.fuse.ui.listClasses.List;
	import qnx.fuse.ui.listClasses.ListSelectionMode;
	import qnx.fuse.ui.text.Label;
	import qnx.ui.data.DataProvider;
	
	import DigitalGoodsInfo;
	
	[SWF(height="600", width="1024", frameRate="30", backgroundColor="#FFFFFF")]
	
	public class Payment extends Sprite
	{
		private var paymentSystem:PaymentSystem;
		private var buyList:List;
		
		private var loader:URLLoader;
		private var pastPurchases:Array = [];
		
		public function Payment()
		{
			paymentSystem = new PaymentSystem();
			
			paymentSystem.setConnectionMode(PaymentSystem.CONNECTION_MODE_LOCAL);
			
			paymentSystem.addEventListener(PaymentSuccessEvent.PURCHASE_SUCCESS,
				purchaseSuccessHandler);
			paymentSystem.addEventListener(PaymentErrorEvent.PURCHASE_ERROR,
				purchaseErrorHandler);
			
			paymentSystem.addEventListener(PaymentSuccessEvent.GET_PRICE_SUCCESS,
				getPriceSuccessHandler);
			paymentSystem.addEventListener(PaymentErrorEvent.GET_PRICE_ERROR,
				getPriceErrorHandler);
			
			initializeUI();
		}
		
		private function initializeUI():void
		{
			buyList = new List();
			buyList.setPosition(25,25);
			//buyList.setSize(360, 250);  // I had to avoid this, since setSize was not recognized
			buyList.columnWidth = 400;
			buyList.scrollable = true;
			buyList.allowDeselect = false;
			buyList.selectionMode = ListSelectionMode.SINGLE;
			addChild(buyList);
			
			var buyButton:LabelButton  = new LabelButton();
			buyButton.setPosition(400, 25);
			buyButton.label = "Buy";
			buyButton.addEventListener(MouseEvent.CLICK, purchaseHandler);
			addChild(buyButton);
			
			var priceButton:LabelButton = new LabelButton();
			priceButton.setPosition(400, 125);
			//priceButton.setSize(185, 45);
			priceButton.label = "Get Price";
			priceButton.addEventListener(MouseEvent.CLICK, priceHandler);
			addChild(priceButton);
			
			// this is what I have changed

			var loader:URLLoader = new URLLoader();
			loader.load(new URLRequest("digitalgoods.xml"));
			
			loader.addEventListener(IOErrorEvent.IO_ERROR, faultHandler);
			loader.addEventListener(Event.COMPLETE, resultHandler);
		}
		
		private function priceHandler(event:Event):void
		{
			var info:DigitalGoodsInfo = buyList.selectedItem as DigitalGoodsInfo;
			paymentSystem.getPrice(null, info.sku);
		}
		
		private function resultHandler(event:Event):void
		{
			var data:DataProvider = new DataProvider();
			var remoteData:XML = new XML();
			var dgObject:DigitalGoodsInfo;
			
			remoteData = XML(loader.data);
			
			for each(var obj:Object in remoteData.digitalgood)
			{
				dgObject = new DigitalGoodsInfo(obj.name, obj.sku);
				data.addItem(dgObject);
			}
			
			buyList.dataProvider = data;
			buyList.selectedIndex = 0;
		}
		
		private function faultHandler(event:Event):void
		{
			var fhtxt:TextField = new TextField();
			fhtxt.x = 400;
			fhtxt.y = 450;
			fhtxt.width = 200;
			fhtxt.height = 100;
			fhtxt.text = "Unable to retrieve digital goods from the server";
			addChild(fhtxt);
			trace("Unable to retrieve digital goods from the server.");
		}
		
		private function purchaseHandler(event:MouseEvent):void
		{
			var info:DigitalGoodsInfo = buyList.selectedItem as DigitalGoodsInfo;
			
			paymentSystem.purchase(null,info.sku,info.name,info.appName);
		}
		
		private function purchaseSuccessHandler(event:PaymentSuccessEvent):void
		{
			var purchase:Purchase = event.purchase;
			
			trace("Purchase Success - " + purchase.date
				+ " : " + purchase.digitalGoodID
				+ " : " + purchase.digitalGoodSKU
				+ " : " + purchase.licenseKey
				+ " : " + purchase.itemState
				+ " : " + purchase.startDate
				+ " : " + purchase.endDate
				+ " : " + purchase.intialPeriod
				+ " : " + purchase.purchaseID);
			
			pastPurchases.push(purchase);
		}
		
		private function purchaseErrorHandler(event:PaymentErrorEvent):void
		{
			var peh:String;
			peh = ("Purchase Error - " + event.errorID + " : " + event.text);
			var petxt:TextField = new TextField();
			petxt.x = 400;
			petxt.y = 450;
			petxt.width = 200;
			petxt.height = 100;
			petxt.text = peh;
			addChild(petxt);
			trace("Purchase Error - " + event.errorID + " : " + event.text);
		}
		
		private function getPriceSuccessHandler(event:PaymentSuccessEvent):void
		{
			var price:Price = event.price;
			var pevt:String;
			pevt = ("Get Price Success - " + price.price);
			var pricetxt:TextField = new TextField();
			pricetxt.x = 400;
			pricetxt.y = 450;
			pricetxt.width = 200;
			pricetxt.height = 100;
			pricetxt.text = pevt;
			addChild(pricetxt);
			trace("Get Price Success - " + price.price);
		}
		
		private function getPriceErrorHandler(event:PaymentErrorEvent):void
		{
			trace("Get Price Error - " + event.errorID + " : " + event.text);
		}
	}
}

 

DigitalGoodsInfo.as

 

package
{
	public class DigitalGoodsInfo
	{
		public var name:String;         
		public var label:String;         
		public var sku:String;          
		public var appName:String;
		
		public function DigitalGoodsInfo(name:String, sku:String)
		{
			trace("in DigitalGoodsInfo.");
			this.label = name;
			this.sku = sku;
			
			appName = "Payment";
		}
	}
}

 digitalgoods.xml

<?xml version="1.0" encoding="utf-8"?>
<digitalgoods>
    <digitalgood>
        <name>Extra Life</name>
        <sku>FFWextralife01</sku>
        <metadata></metadata>
    </digitalgood>
    <digitalgood>
        <name>Dynamite Bomb</name>
        <sku>FFWdynamite01</sku>
        <metadata></metadata>
    </digitalgood>
</digitalgoods>

 help...PLEASEEEEEE!!!

Please use plain text.
Contributor
Gustavo_Bocalandro
Posts: 25
Registered: ‎02-05-2013
My Device: none
My Carrier: Personal

Re: Help please!

I have everything working now :smileyhappy: ... now I gotta try it in my Flash pro app
Please use plain text.