Cron-Job Issue with double Proccesses - php

We have a business, where we send API request to generate digital products. We have 2 jobs, one order based and one cron-job to process open orders.
I don't know where i should search the Problem.
Problem is;
the Cronjob double processed now 3 times (on 3 different days) products.
Example: Our Shop asks with a simple JSON POST the other system to get the Products by API. This is initiated by the Cronjob. The other System always makes, what the request incoming want.
If the Shop asks for 1 product, the system ordered two. Two similar requests are made to the API.
I don't know if this Problem is coming from;
the store (where the Cron Job Script is started)
the System
somewhere else
It is suspicious, that not the whole Job is done twice, it was only for some orders and some products. And not always. Does any one had a some Problem or a probably solution for that?
We already have some Security checks to prevent that, but it looks like it doesn't help. (The double processing is very bad, the products are like money (giftcards), if a customer get's to much of the digital cards and he redeem it immediatly, the money is lost).

Related

How to add, reduced amount of item, to its table, when user close browser tab in payment gateway

I have a situation for shop market, when user wants to pay, first a factor will create then redirect him to the payment gateway.
In factor creation, number of items that user is selected, reduce from stock number count of existence items, so if user close the payment gateway browser's tab, wanted items are reduced from stock items count and never returns.
How manage this situation for payment??
My Solution
I think a lot on that and come with this solution that create a reserved factors table to store current factor that is going to pay and when back from payment gateway, simply delete it.
If browser's tab was close by user then calculate that if time of reserved factor is more than payment gateway the delete it from reserved table and add reduced items number to stock number count.
I add this code to my construct (because I think this is right place to check for all items in reserved factor right before show items to user. This helps for items that are not available, to be available now) but in another hand I think if number of reserved factors in database are big enough, it might have a huge effect of loading performance.
SO what is the right solution for situations like this?
Can I have something like a schedule plan in MySQL to delete those records? or even in PHP?
OR ANY IDEA...
EDIT:
I do want a code base solution if any exists.
Can I have something like a schedule plan in MySQL to delete those records? or even in PHP?
Usually this sort of thing is done using your server's "cron" feature (or "Scheduled Tasks" if your server is running Windows). You can write a PHP script that clears these abandoned carts when run, and configure your server to execute that PHP script at regular intervals.
MySQL also has an "Event Scheduler" feature; I don't think that gets used very often, but it is an option.
...so if user close the payment gateway browser's tab, wanted items are reduced from stock items count and never returns.
This is the wrong way to look at this problem. Consider these scenarios:
User accidentally closes their browser, re-opens it, and tries to finish purchasing
User loses internet access and cannot finish purchasing... browser isn't closed
While it is possible to use the Beacon API in newer browsers to send an update when a browser is closed, for these reasons it's a bad idea.
You have two general options:
Option 1: Track the user/cart activity
Every time the user does something meaningful on the site, update their last active time on a record for their cart. If a user is still browsing the site and they have a product in their cart, keep it reserved there until the sale is complete or until they are no longer active for some period of time. For example, if they haven't been on the page in 15 minutes, release the reservation for the product. (Be prepared to reserve it again if they come back and the product is still available.)
Option 2: Don't reserve until purchase
Keep the item in-stock until it's actually bought. If at the time of purchase the product is no longer available, let the user know.
Which of these options you choose depends on your business conditions and the sort of stuff you're selling.

Check if Visitor paid a specific amount + if he used a specific "code" to access a special website/download

currently I'm working on my own, selfwritten Website (from scratch, without any CMS or sh**) and I want to implement a special system for the Commissions I make.
Some people are commissioning me to create 3D Models and other stuff.
Since sometimes my customers are from a different timezone (I'm from germany, most of my customers are from america) communicating over Discord sometimes fails because of that.
So I thought about creating a system to let the customers download their commissioned model as soon as I've uploaded it and sent them a Code to "unlock" the download to it.
I thought this probably could work using Paypal. They get the Code, enters them on my website and gets the information to pay a specific amount I've setup before. After they paid, the download is unlocked.
Any Idea how I could setup something like that?
Thank you in advance!

Run php script in background on nginx

I'm trying to develop a payment module for one shop cms.
Payment is based on acquiring in a Bank.
So firstly for each order creates (with curl) a "ticket" on bank side. Ater that client is forwarded on payment page on bank server with its ticket id. If customer pays and push button "go back to store" everything is fine.
But if customer pays and don't push this button i need to check the result (if he paid or not). It is also made by curl. I'm requesting info by ticket id and receive an array with parameters i need among them is result code i need to check.
So i need to check it automatically (for ex. 1 time each 5 mins during an hour).
Cron can't help me coz it is all dynamically processes.
I created a function that returns me the result. But how can i start it in background with any interval?
Using cron. PHP does not offer anything like scheduler because it is out of scope of the language. You may use DB to store some of parameters needed to the whole process.
I'll extend a little bit WebnetMobile answer on using cron for what you want.
Likely you have a table in your DB where you store are tickets you get from Bank and whenever they suceed or did not suceed as well the date the ticket was created.
Then, if what you want is to check every five minutes from bank ticket creation date whetever it suceed or not if unknown, you should run a cron each minute that will do the following:
Check if there are bank tickets without defined state (Suceed or Failed).
Check if time created (without seconds) minus current time (without seconds) MOD 5 == 0.
If true, means another 5 minutes period have passed from that ticket creation and should be checked, Else do nothing.
I think this will do what you want

Few problems with social game

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.

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