Currently I have a script which processes orders after someone is directed to a payment processor.
The payment processor will occasionally send two (or more) responses to my site (usually within a minute of the first response).
I have contacted the payment processor about the issue; they don't see this as an issue with their system and say my script should take into account any extra responses and only listen to the last one sent.
On multiple response orders, the first response is successful, and so the order is processed when this response comes in.
If a 2nd response comes, its usually about 30 seconds later with an error response and I cancel the order.
The problem is that I have already sent out a "thank you for your order" email to the customer from the first response, which obviously isn't ideal.
Is there a way to trigger a separate script to run a few minutes after the order is processed? i.e to check if the order is still valid a couple of minutes after the original order and send the email out
I was thinking a cron job which runs every minute, but surely this would be overkill since the script only needs to run if an order has been placed?
You can start background job using shell_exec("/usr/bin/php /path/to/test.php ".($orderId)." &"); with 3 minute delay at the start (sleep(180)); and then execute code to check status of the order. $argv[2] should contain your orderId number.
Heres what you can do
after the first response is recieved, make your script wait for some time, say 1 minute using the sleep() function
http://php.net/manual/en/function.sleep.php
Why can't you change you message and notify a person with an email after second request came from your payment processor?
As I understand - your processor is already calling some URL on your site while sending second response. So that is a trigger you need. If they have no such callback functionality - you may just install some cron to which will go through not completely processed orders and check payment statuses for such orders and notify customer with another email.
Related
I'm working on a PHP website where when user selects city and submits the form, it will get the users phone numbers from the database for that particular city and sends SMS to them.
I have used cURL functions within a while loop to execute this and it is working fine.
NOTE: My sms gateway provider's API only support one number at a time per http request.
Now my question is if the number of user in the selected city is more than 10000 or 50000, then using cURL method will take much time to execute since it's in the loop? But the user wont like wait for the completion of loop. Is there any better way than doing this, like when user submits the request, something in backend (like job) will execute the function and even if the user closes the page, that job will execute till it completes the loop.
my solution was this:
--page /sendsms/?phone_nr=1122 sends one sms to phone nr 1122
--page /sendbulk has a loop which calls in php the page /sendsms/?phone_nr=1122 with file function file('http://www.domain.com//sendsms/?phone_nr=' . $phone_nr[$i]);
--the client on submit will call with ajax(no return needed) the page /sendbulk
This way even if the client closes the connection the server will continue to run /sendbulk in background and will send all messages
You can store detail of sms and city in another table, than set one Cron that take the all Number from the basis of City detail and Send To Sms Gateway , set that row as sent..
We have an eCommerce site that is using Authorize.net as a payment gateway.
We have recently run into the issue of people submitting a payment confirmation, and then clicking submit again later on. This is resulting in a double-product situation, and/or double payment.
Some things to consider:
The payment confirmation page is a result of a PRG (Post-Redirect-Get) which is loaded before the user submits their payment
We have functionality in place that will actually act on each part of the request (see below for description of this)
This situation will only apply when Authorize.net transactions take longer than normal.
This is NOT in production yet, we are merely looking for a way to test this new functionality to prevent this behavior.
The Prevention Piece
We have a multi-step checkout form that follows the following process:
Product selection
Payment entry
Confirm Order / Submit Payment
Receipt
Each step of the process executes a call to a service that checks to see if the user has a current 'order' that has one of several statuses: started, processing or complete.
If the order is started, it will redirect them to the first page of the checkout flow.
If the order is processing, it will redirect them to a placeholder page that executes an ajax request every 2 seconds to check the status of the order. When the order is complete, they are redirected to the receipt page.
If the order is complete, they are redirected to the receipt page immediately.
The Problem
Since this functionality is really only valid when the processing transactions take a bit longer, it gives us problems testing it - for a few reasons:
Our dev server is slow, and it is more likely than not that Authorize.net will respond to our request before the page is even rendered by the application.
If we dummy the response up by using the PHP function sleep(), it blocks the thread and nothing runs, and we are in the same boat as [1].
What we hope
I do not know if there is a way to make Authorize.net respond to requests in a slower manner via some parameter, or if there is another way to accomplish this. I welcome ANY and ALL ideas!
You shouldn't be testing directly against Authnet for this. Make your own Authnet "server" and have it delay its response to you. For unit test I wrote for my Authnet library I created my own fake server which sends back the appropriate response I need to test. You can do the same and have the "server" wait as long as you need to before sending back a response. The response doesn't have to be real for you to test a delay.
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
My situation is that i have a page and the seller is going to take the order of a client, after the client orders, the seller hits the confirm button and awaits for the client to pass his identification card, wich i do with a ajax request and pop up a dialog with the list of products, a message and a cancel button.
After my ajax is sended in the server side, i'm doing a 'for' with a 'sleep' to check if the user has passed his card and then if he has, i put the items into his bill (persist into the database). The problem is, if that the user decides to cancel de proccess, i can't get the cancel ajax request to work because its busy with the first request on the server side and waiting its return.
Anyone have nay suggestions on that? I really wanted that the workflow of the site works like this:
Client orders -> Seller add the items and hits confirm -> Client passes confirmation or Seller can Cancel -> End of procces
Even if there was a simple way to do it the way you are going about it, this process would quickly overwhelm the server after more than a handful of connections.
I would store the customer's order to the database before requiring his identification, with a status field on the order set to "Awaiting Identification", or something to that effect. Then you can proceed with the identification flow without having to hold the PHP script waiting, and conserving a lot of resources.
If the client inadvertedly disconnects, you will still have saved her order and can allow her to complete identification at a later time.
Finally, when the client successfully completes identification, you can simply update the order 's status field to "authenticated" to indicate it's ready for processing.
EDIT: To address your particular problem, consider the following flow:
You save the order as "pending identification" and display the "Waiting..." dialog.
You perform a really simple request every few seconds asking whether the status of the order has changed, to know when the dialog needs closing.
At some point, the identification device sends a confirmation request upon which you retrieve the order and change its status. Then the periodic call you implemented in step 2 will kick in and hide the dialog.
The session is not a good location as a temporary storage medium, but a Redis, Memcached or similar service could help you simplify that process, given that the device and the site can in some way share information.
I have to connect api that states:
Our system sends events to your application, it does
so in a manner that it expects an immediate reply but does not wait
for all processing to take place. When an event is received, an
immediate reply is made back to our system to say the message was
received. The acknowledge event call follows to state that the event
has been processed by the third party. Our system has to
process millions of events daily and awaiting for the third party to
finish processing an event while distributing events would cause
unnecessary delay.
Now i am in a problem because i dont understand how can i immediately respond to their server that i have get their data if i used the return keyword in 1st line then it will not execute the code after it and in other cases they have to wait for my process to finish.
I have tried with echo 1. but it does not work.
Note: for successfull response i have to send 1 as integer to let them know that i have get their data
<?php
header('This');
header('That');
echo 1;
flush();
//all your other code....
?>