PDA

View Full Version : Uploading multiple items to Paypal


chr15athome
12-18-2008, 10:21 AM
Hi All,

I have had some good help on here this week so I decided to give some back. I didn't find much help on google for uploading multiple items to Paypal in AS3 so incase anyone else is trying to achieve this here is my function for doing it.

function purchaseItem(event:MouseEvent){
//if you want the item to be added to the cart once only then move var ran to a frame that only gets read once, like frame 1
var ran:Boolean = false;
if(ran == false){
ran = true;
var url:String = 'https://www.paypal.com/cgi-bin/webscr';
var request:URLRequest = new URLRequest(url);
var paypalObj:URLVariables = new URLVariables();
var tempItem:int;
paypalObj.cmd = "_cart";
paypalObj['upload'] = 1;
paypalObj.business = "youremail@isp.com";

for(var itemNum = 0; itemNum < shop_cart.size();itemNum++)
{
//only need the line below if your flash cart is zero based, i.e. item no.1 is actually no. 0.
tempItem = itemNum + 1;
//the items here are gathered from a datagrid
paypalObj["item_name_"+tempItem] = dataGrid.getItemAt(itemNum).Description;
paypalObj["amount_"+tempItem] = dataGrid.getItemAt(itemNum).Price;
paypalObj["quantity_"+tempItem] = dataGrid.getItemAt(itemNum).Quantity;
}
paypalObj.shipping_2 = "1.99";
paypalObj.no_shipping = "0";
paypalObj.tax = "";
paypalObj.no_note = "1";
paypalObj.currency_code = "GBP";
paypalObj.lc = "UK";
paypalObj.bn = "PP-ShopCartBF";
paypalObj.target_winName = "paypal";
paypalObj.instanceName="checkout_btn";

request.data = paypalObj;
request.method = URLRequestMethod.POST;
navigateToURL(request, '_blank');

}

Hope this help someone and if I have forgotten to say thanks to anyone on here for advice recently, well thanks.

Chris