Blockchain Address gap limit solution I want to use blockchain API for my store but the wallet only monitoring last 20 generated address.

Quote from https://blockchain.info/api/api_receive:


  As defined in BIP 44, wallet software will not scan past 20 unused
  addresses. Given enough requests from this API that don't have a
  matching payment, you could generate addresses past this horizon,
  which would make spending funds paid to those addresses quite
  difficult. For this reason, this API will return an error and refuse
  to generate new addresses if it detects it would create a gap of over
  20 unused addresses. If you encounter this error, you will either need
  to switch to a new xPub (within the same wallet is fine), or receive a
  payment to one of the previous 20 created addresses


I googled about this problem and found some solutions such as:

Solutions that I found


Check gap with blockchain checkgap API and don't generate new address until they have been paid.
Increase gap limit on the receive api.
Send money to the last unused address.


Problems with these Solutions


If I have 20 unpaid address and they never been paid, solution #1 can not solve the problem. it just say I have 20 unpaid address.
Solution #2 can not solve the main problem. Even I set the gap limit to the 100, How about the time that 101 curious users only want to see the checkout page and close it. I will get 100 unused address again.
Solution #3 is not a nice solution to me. It seems like a bad practice to me and this is a solution that solved by spending money.


My Solution

If I get it right, when Blockchain generating the address, It will be there until it's getting paid. Correct me if I'm wrong, Blockchain will not callback until the user pay the amount. so I do this to solve the problem:


Check the gap by API. If gap>19 goto #3 else #2.
Generate the address and store it inside unpaid_address table based on the "index number" that blockchain returns with address. set expiration time for 30 minutes and go to the #4.
Get the first expired unpaid address from unpaid_address table. If there isn't anything, show sorry server is busy, else goto #4.
show the address to the user and say you have 15 minutes to pay to this address. (15 minutes less than expire time to avoid problems).
If blockchain callback my URL and It has been paid before the expire time, I remove the address from unpaid_address else the address has been there for the next request by other user. I will give that address to the next user for paying.


Question

This solution give me the ability to never exceed gap limit. But I don't know if it's safe to give the address to a user and if he didn't pay on 30 minutes, give it to another user.

What do you think? Is it safe? or is there better solution?

About giving the address to multiple users


First user see the checkout page in 8:20AM and send the amount to the address. but there is no confirmation in 15 minutes. the confirmation come in 11:00AM.
Second user see the checkout page in 9:00AM and send the amount to the same address. there is confirmation in 9:10AM so I will return callback result as paid.


What about the first user confirmation on 11:00AM?
Blockchian.info is not really qualified to provide Bitcoin API's for business, 20 empty addresses are really cool and enough as a personal wallet but for business, it's not. 

I suggest you find an alternative or use some payment gateways, or you can do the following but it's not really recommended. 


Increase 20 address limit by getting more than blockchain wallet, When some user create an address check gap if it's over 18 change the xPub to the next xpub and go on. 
15 min time limit, if the user didn't pay within 15 min, give it to another user. Note: You don't have to wait for confirmations. Once you receive a transaction mark those addresses so you don't give them to another user.
Before you reach address number 20, pay a small amount automatically to that address so you get another 20 address. 


UPDATE: 

You can't create an xpub Programmatically (using blockchain.info api), but a new wallet

https://blockchain.info/api/create_wallet

You don't really want to do that, you can create like 5 xpub's keys and store them in your database, and just sweep between them.



Settings --> Addresses --> + ADD. Click To create a new xpub key.

Manage --> Show xPub. To get your extended public key (xpub).