Building a payment request URI

First off, we define the testnet as the default network for our application and a merchant address. Simply put within the server's code the following lines:

bitcore_lib.Networks.defaultNetwork = bitcore_lib.Networks.testnet; // the project runs only on testnetvar Merchant_address = "mhc5YipxN6GhRRXtgakRBjrNUCbz6ypg66";

In this example, we used a static bitcoin address but in a real implementation, the merchant has to generate a unique payment address associated with the customer's order. Alternatively, you can generate a random address using the following:

var privateKey = bitcore_lib.PrivateKey(merchant_pkey); // we pass a specific private key as argumentvar publicKey = bitcore_lib.PublicKey(privateKey);bitcore_lib.Address(publicKey, ...

Get Blockchain By Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.