User:Kristy Fanshaw
Pay Script for Reseller vendor
Place this script in a Vendor Root prim.
What it does:
1) it asks the owner of the vendor to rezz the update box. 2) update box will define the URL from where it can aquire the email address of the vendor. (the webpage body should contain only pure address - no html code) 3) when the URL is set, it asks the owner of the vendor to grant debits. If the owner won't do so, the script resets. 4) When debits are granted the vendor will be active
Purchase:
1) buyer can pay only the amount of money that is set in "integer gCorrectAmount = price;"
<lsl>
integer gCorrectAmount = 10; //enter your price for fast pay
integer totalsold = 0;
integer totalamount = 0;
key OWNER;
key ID;
string url;
key http_request_id;
integer listen_handle;
integer back;
string mail;
default
{ changed(integer change) { if(change && CHANGED_OWNER) { llResetScript(); } } on_rez(integer start_param) { llResetScript(); } state_entry() { OWNER = llGetOwner(); llSetPayPrice(PAY_HIDE, [gCorrectAmount, PAY_HIDE, PAY_HIDE, PAY_HIDE]); // in llSetText describe the name of the "update box" object that should be rezzed llSetText("To start vendor, rezz 'update box name'.", <1.0, 1.0, 1.0>, 1.0); llSensorRepeat("update box name", NULL_KEY , SCRIPTED, 10 , PI, 10); } sensor (integer numberDetected) { state sens; } no_sensor () { llResetScript(); } }
state sens {
on_rez(integer start_param) { llResetScript(); } state_entry() { llSetText("Updating", <1.0, 1.0, 1.0>, 1.0); // set llShout channel to whatever negative channel you like, but remeber to define the same channel in update box llListen function llShout(-1234567,"update"); // set llListen channel to whatever negative channel you like, but remeber to define the same channel in update box llShout function listen_handle = llListen(-7654321,"update box name", NULL_KEY, ""); llSensorRepeat("update box name", NULL_KEY , SCRIPTED, 10 , PI, 5); } listen( integer channel, string name, key id, string message ) { url = message; llListenRemove(listen_handle); llOwnerSay("updated"); llShout(-1234567,"updated"); llListenRemove(listen_handle); } sensor (integer numberDetected) { llListenRemove(listen_handle); state sens; } no_sensor () { llSetText("Touch to grant debit permission.", <1.0, 1.0, 1.0>, 1.0); } touch_start(integer total_number) { llRequestPermissions(llGetOwner(), PERMISSION_DEBIT); } run_time_permissions(integer Permission) { if(Permission == PERMISSION_DEBIT) { llOwnerSay("Starting vendor."); llSetText("", <1.0, 1.0, 1.0>, 1.0); state Ready; } else { llOwnerSay ( "To share proceeds I must have give money(DEBIT) permissions"); llOwnerSay ( "Try again"); llResetScript(); } } }
state Ready
{ on_rez(integer start_param) { llResetScript(); } state_entry() { llSensorRepeat("update box name", NULL_KEY , SCRIPTED, 10 , PI,30); } sensor (integer numberDetected) { llSetText("Updating", <1.0, 1.0, 1.0>, 1.0); llShout(-1234567,"update"); listen_handle = llListen(-7654321,"update box name", NULL_KEY, ""); } listen( integer channel, string name, key id, string message ) { url = message; llListenRemove(listen_handle); llOwnerSay("updated"); llShout(-1234567,"updated"); llSetText("", <1.0, 1.0, 1.0>, 1.0); llListenRemove(listen_handle); } touch_start(integer total_number) { if (llDetectedOwner(0) == llGetOwner()) { llOwnerSay((string)totalsold +" units have been sold since object rez. "); } else { llInstantMessage(llDetectedKey(0), "Right-click and pay to purchase."); } } money(key id, integer amount) { ID =id; back = amount; { if (amount == gCorrectAmount) {// correct amount paid llInstantMessage(id, "Thank you " + llKey2Name(id) + " for your purchase."); llInstantMessage(id,"Server initialises your request ....."); http_request_id = llHTTPRequest(url, [], ""); } else if (amount < gCorrectAmount) { llInstantMessage(llDetectedKey(0),"You didn't pay enough, " + llKey2Name(id) + ". Refunding your payment of L$" + (string)amount + "."); llGiveMoney(id, amount); state Ready; } else { integer refund = amount - gCorrectAmount; llInstantMessage(llDetectedKey(0),"You paid too much, " + llKey2Name(id) + ". Your change is L$" + (string)refund + "."); llGiveMoney(id, refund); llInstantMessage(id, "Thank you " + llKey2Name(id) + " for your purchase."); llInstantMessage(id,"Server initialises your request ....."); http_request_id = llHTTPRequest(url, [], ""); } } } http_response(key request_id, integer status, list metadata, string body) { { mail =body; if (request_id == http_request_id) { if(llGetSubString(body, -19, -1) == "@lsl.secondlife.com") { llInstantMessage(ID,"Request initialised."); llInstantMessage(ID,"Sending your requested items ....."); llSetText("Purchase in progress...\n\nPlease Wait...", <1.0, 1.0, 1.0>, 1.0); llSetPayPrice(PAY_HIDE,[ PAY_HIDE, PAY_HIDE, PAY_HIDE, PAY_HIDE]); llEmail( body, ID, (string)llGetKey()+"@lsl.secondlife.com" ); llSetTimerEvent(5); llGetNextEmail("", ""); llGiveMoney(ID, back); llInstantMessage(ID, "Vendor is outdated"); llInstantMessage(llGetOwner(), "Your Vendor in " + llGetRegionName() + " sim can't deliver items. Please update your Vendor."); llResetScript(); } else { llGiveMoney(ID, back); llInstantMessage(ID, "Vendor is outdated"); llInstantMessage(llGetOwner(), "Your Vendor in " + llGetRegionName() + " sim can't deliver items. Please update your Vendor."); llResetScript(); } } } } email( string time, string address, string subj, string message, integer num_left ) { if (subj == "delivered") { key creator = llGetCreator(); float calc = back + 0.0; float a = calc * 0.6; // Define here how much you'll recieve from the sale: 1 = 100 % (in this case here you'll get 60% from the sale and vendor owner gets 40%) float b = back - a; llGiveMoney( creator, (integer)a ); llInstantMessage(ID,"Accept your purchased items"); totalsold = totalsold + 1; totalamount = back * totalsold; llInstantMessage(llGetOwner(), (string)llKey2Name(ID) + " has paid " + (string)back + "L$ in "+ llGetRegionName() + " and you have recived " + (string)llRound(b) + "L$ from this sale"); llInstantMessage(creator, (string)llKey2Name(ID) + " has paid " + (string)back + "L$ in "+ llGetRegionName() + " and you have recived " + (string)llRound(a) + "L$ from this sale"); llSetPayPrice(PAY_HIDE,[gCorrectAmount, PAY_HIDE, PAY_HIDE, PAY_HIDE]); llSetText("", <1.0, 1.0, 1.0>, 1.0); llSetTimerEvent(0); state Ready; } } timer() { llGiveMoney(ID, back); llInstantMessage(ID, "Vendor couldn't deliver items ... your money is refunded"); llInstantMessage(llGetOwner(), "Your Vendor in " + llGetRegionName() + " sim can't deliver items. Please update your Vendor."); llSetPayPrice(PAY_HIDE,[gCorrectAmount, PAY_HIDE, PAY_HIDE, PAY_HIDE]); llSetText("", <1.0, 1.0, 1.0>, 1.0); llSetTimerEvent(0); state default; }
}