I want to implement payment mechanism on my web site .
after too many search on internet . i understood payment gateways like cryptomus
or bitpay
generate new address peer payment order . then never use that address again . (If i confused , please notice me)
My question is why should not use this address again ?!
what happened if i have a flow like this:
- customer click to pay
- backend server send request to wallet provider
like metamask
for generate new address then create a invoice and hold both in database. - lock generated address on database (prevent send to wrong customer)
- send address to ui (generate qr code)
- customer scan qr code then pay .
- backend listen to etherscan.io according to generated address
- if (paied) {unlock address (wait to next order)} elese {wait to timeout reached}
advantage:
- never generate million addresses on the fly !
- if another customer requested to pay:
we can search on db :- if any free address exists so used that .
- else request to wallet provider to generate new address .
Disadvantages :
- need more gas fee for collect from addresses to main business address.
- if customer send to previous wrong address (note: exists on my db), so we need tx id to approve that . (maybe manual operation)
Actually i am java developer .
this is my interface :
import java.util.List;
/**
* ERC20 Payment Interface
*/
public interface PaymentInterface {
/**
* Create new account on metamask wallet
*
* @return return payment account
*/
MetamaskAccount generateNewAccount();
/**
* store new account on database
* @param account new account generated on metamask
*/
void storeAccount(MetamaskAccount account);
/**
* @return List all metamask generated wallets
*/
List<MetamaskAccount> getAccounts();
/**
* @return list of metamask {@link MetamaskAccount lock} field is false
*/
List<MetamaskAccount> getFreeAccounts();
/**
* @param lock switch state of MetamaskAccount to lock or unlock
*/
void changeStatus(boolean lock);
}
and this is my simple model :
public class MetamaskAccount {
/**
* Metamask account private key.
* Note: public key generated from private key.
*/
private String privateKey;
/**
* Account address
*/
private String address ;
/**
* Lock wallet until :
* 1) transaction committed
* 2) transaction time out
*/
private boolean lock;
/**
* Account timeout (as seconds).
* this account locked if timeout reached
* Example : 1800 second (30 minutes to pay)
*/
private long timeout;
/**
* Start lock date & time
*/
private LocalDateTime lockTime;
// Getter && Setter
}
this solution only need a cron job executed every 1 minutes only for check timeouts .
Is there a problem that I have not noticed?