0

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:

  1. customer click to pay
  2. backend server send request to wallet provider like metamask for generate new address then create a invoice and hold both in database.
  3. lock generated address on database (prevent send to wrong customer)
  4. send address to ui (generate qr code)
  5. customer scan qr code then pay .
  6. backend listen to etherscan.io according to generated address
  7. 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?

1 Answer 1

0

IMHO simply because users act not as machines and they will be funding the address after their timeout has passed. Don't ask me how:)

And it's cheap to generate a private key & address. It's just running a function on the backend.

Collecting payments from an address does increase the cost of payments though. Well, you can stitch it into your service fee.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.