Few problems with social game - php

I'm developing one social game which is similar to friends for sale game.
In the game user buys and sells friends.
Buyer of the user becomes owner of that user.
I developed logic and it works perfect as per calculation.
But when we have many number of users there is problem with this action of buy button.
E.g. 5 users are on same profile i.e. UserXYZ. Now 2 of them clicks on buy button at the same time, same second.
Amount of cash is being loose from both the accounts but only one becomes owner.
I want to stop this cash losing problem.
This problem occurs because script executes at the same time for both the users but only one of them becomes owner.
I have no idea how to stop this over sale clicks. Website is in PHP/MySQL.
Any help will really be appreciated.

without seeing any of your code, i can't really give a code answer, but, in theory i would fix this like so:
when your sending your ajax "buy friend" request, send the current owner id along with it.
In your php, check if the friend that is getting bought has the same owner, if it does, do the sale, if not, reply a friendly message saying "sorry, someone else bought them"

Instead of subtracting the money from the front-end, subtract the money from the backend after the user has been successfully added to that owner. That way you avoid the problem. Make sure you pass the ownerid to the backend, which you should be doing already.

Related

How to track users cross domain for a purchase

I'm creating a kind of affiliate marketing website with products I've scraped from partner websites. The user clicks on the Buy link and is re-directed to the partner site to complete the purchase. If the user buys the product, I should get a percentage of the sales. So far this model is a pretty common approach.
However the element that I don't yet understand is, what technology or script do other affiliate sites use to track to see if the user, once they've let the main site, does purchase the product or not? How do I track my user's purchase or actions once they've left my site?
I know that cookies can store brief user information but I don't think that's enough. I need to then store this information in a database. Should I use php sessions for this?
Any tips or suggestions is really appreciated.
Cheers
What technology or script do other affiliate sites use to track to see if the user, once they've let the main site, does purchase the product or not?
Javascript. Affiliate Softwares usually have click tracking code which is placed on the landing pages. Once a vsitor comes to landing page through an affiliate website, a random visitor id along with affiliate id mapping is created which gets stored in the database. At this same time, a cookie gets created with the visitor id, affiliate id info etc. When the user finishes a purchase, there is a sales tracking code javascript code which is placed on the purchase page that gets trigerred. You can use create this code and insert the visitor's id along with affiliate id in the database.
How do I track my user's purchase or actions once they've left my site?
I have answered this partly in the above question. But once the user comes back again, it is going to recognise this user based on cookie and preferably you can store the session value in the cookie itself rather than the database, because the sale entry will get created in the database once the user has completed his purchase, if you have placed your sale tracking code at the end of purchase page.

Pixel+Cookie Conversion Tracking From Tracker's Point of View

Just trying to make a conversion tracking system (pixel+cookie) with PHP for study purpose. Just need some ideas and guides regarding this from tracker point of view.
I have basic understanding on how it works. Basically there are 4 parties involved: merchant, tracker, promoter and user. Merchant places iframe based pixel (from tracker) on their thank you (last check out) page.
User surfs the web, finds an ad/offer and clicks
It directs to tracker. Then tracker puts cookie on user's computer and redirects to merchant's landing page
User likes the product during this first visit. He/she adds to cart, checkouts and make a payment. Thank you page shows up and fires the pixel.
Tracker get necessary parameters and checks for cookie in user's computer, records the sales and gives credit to the promoter.
Well, all this works if there is only one tracker, merchant, promoter.
My questions are:
(a) How to correctly identify sales when multiple parties are involved?
(b) Also user may not buy the product on the same day. Instead he/she might come back directly and buy the product after a week or two.
(a) Scenario
M- Merchant
T1,T2,T3 - trackers (supposing we are T1)
U - user
In this case merchant may join force with all three trackers and put pixel from each on their thank you page.
User may have landed on particular merchants page from all the tracker links including us. In this case user's computer contains all three cookies from three different trackers.
When user buys the product and reaches Thank you page pixel will fire up for all three tracker. Each tracker will check for cookie and finds their cookie present and might confirm sales.
In this case, there is a possibility of 3 recorded sales where in fact is just one sale.
So the question is how each tracker will know, whether this sales is theirs or not and avoid that as they cannot access cookies of other trackers?
(b) Scenario
Same goes for after click tracking.
Supposing cookie duration is 30 days. (i) User buys product after 15 days after clicking the ad. (ii) Multiple cookie must have already been present in user's computer.
So from particular tracker's point of view, how do we identify the sale correctly?
First, it depends on what you mean by "tracker." A tracker usually is a 3rd party affiliate network that uses a tracking solution. They pair up a merchant (who is selling the product) with a publisher (who advertises and displays the link).
So to answer to question A:
I think it would be unlikely for a merchant to have 3 different "trackers" sending them visitors. Typically, if you were the merchant, you sign up with one affiliate network, then recruit publishers within that network. It wouldn't be smart to sign up with more than one, probably for this very reason.
If more than one cookie was set (within the one affiliate network), the affiliate network would typically use the rule of "last cookie," which means the last ad that was clicked before the purchase is the one that the sale goes to.
Take a look at this similar Quora question: http://www.quora.com/Should-merchants-use-multiple-affiliate-networks-to-sell-their-product-Why-or-why-not
In answer to Question B:
If cookie duration is 30 days, and a user comes back in 15, there should be no problem. If the buyer goes directly to the merchant's site, buys the product, and see's the "thank you" page where the tracking pixel (or whatever tracking solution they use) is, that pixel will fire. The pixel calls a server-side script, like PHP, that will test whether the user has the particular cookie. So it doesn't matter whether the user comes back directly, or when they come back to buy the product. As long as they still have that cookie (within the 30 day limit), the sale will be registered.

PHP user management with user profiles, credit system for user group to view profiles

I've been asked to do a project for someone and they are on a low budget, so I was hoping to maybe find a script online that I can work with, but not being able to so I thought I'd ask around. This is what it is needs to do in a but shell:
Will have user profile pages for customers
User group for agent login whom can credit account for credits, and those credits can be used to view details from a specied user profile
Guess need to set packages for credits, such as $150 for 100 credits, cost to view profile information will cost 1 credit and when runs out they have to top up
Something along those lines...
Is there something that can do that? Of course, it will need an administration area to manage it.
If possible, PHP and MySQL based.
One place you could start is http://www.webintersect.com/. It's under the GNU GPL. It might give you an idea of where to begin.

How to know when a user to a referred site signs up with or purchases from them?

I am in the process of developing a PHP application that awards users for supporting indie games. Once my website confirms an indie purchase, it will unlock certain VIP areas of my site.
For example, I would have a link on my website to Minecraft's registration page. Once my referred user signs up and pays for his copy of Minecraft, is there any way for my site to instantly be updated that the user successfully bought a copy?
This isn't specific to Minecraft either. I would need to include many links to other indie developers' purchase pages.
I'm at a loss to where to begin on this, nor even sure if it's technically possible.
One way of doing this is via an API whereby the purchase is made on your site and you communicate with Minecraft on the backend.
Alternatively, affiliate networks like Commission Junction do the hard work of checking where the user came from and whether or not they buy the product.
However, it doesn't look like Minecraft offer either solution, so your only other option is contacting them directly and asking them if they want some kind of marketing partnership with you.
Yes, just ask the user. "Did you buy Minecraft? [yes] [no]"
Isn't it obvious that you need to get a response from the minecraft site to acknowledge a purchase?

Dealing with two people buying a unique item in an online shop at the same time

I'm creating a simple online shop with PHP integrated with PayPal that sells unique items. What I'm wondering is how other shops deal with multiple people attempting to go through the payment process with the same item.
This is my current draft strategy:
Items have three status types: available, on hold & sold.
As a user moves to the PayPal payment page it checks the status of all the items in the cart to ensure they're available. It also sets the item's status to "on hold" until they either come back after payment is confirmed or it times out (10 minutes? Not sure what this should be).
Is this standard practice or is there a more practical way I should be going about this?
Thanks in advance!
Have a look at Dell's UK outlet. When someone adds a system to their shopping basket it is held and not available to other customers. If it isn't purchased, the item is removed from the basket after 15mins of inactivity and is then available to other customers.
I would say the first part of your strategy is correct - as you move to the payment page, flag all the products as 'on hold'
When the user has finished the payment, you will get a postback from Paypal which lets you know if the authorisation was successful or not (and possibly also allows you to check the CSC/CVV2 result), and at that point you have the option of either accepting the payment, or rejecting it.
On receipt of the postback you should also check whether the items are still on hold. If they have timed out you can reject the payment and display a message 'sorry - timeout exceeded' or somesuch.
This method also allows you to work out an ideal timeout period if you keep track of how often customers run into the timeout, so you can extend the timeout from (eg) 5 to 10 minutes if too many are timing out, or shorten it if none are timing out.
This is a fairly common issue with fixed inventory systems such as venue, transport/airline tix etc.
I like the airline model where once you get the itinery you want and click select, you get a page with passenger info with a message saying, seats on hold and you now have xx(10/15) minutes to complete the purchase. Everything becomes explicit at that time. For other unique/one of a kind item, I'd think a message on any page, that the user clicks on, saying you have xx(mins) remaining to complete the purchase would be a big motivator for "on the edge" buyers !
woot.com is notorious for this problem but their solution works well. After payment information is verified the user is brought to a page with a small amount of text saying something like "your order is in, we are verifying inventory".
It looks like the paypal API has a "RefundTransaction" message so something like that might not be possible. But the user experience could be awkward if your going to the paypal website then coming back to your site.
This is much like booking theatre tickets or similar online and yes the way you describe is generally the way it works. At some point the item is "reserved" in the system and either the customer completes the transaction or the item is released after some time for others to buy.
Of course at what point you reserve the item (when it's added to the cart, at the point you send them off to pay etc) is up to you. I would expect putting it in the cart would be the best choice as it makes it less likely someone will build up a basket of stuff only to find half of it is no longer available at the checkout.

Categories