The newPayment() method is called every time a user clicks the Buy Now button next to an item. As the name suggests, it initiates a new payment:
- We start by defining the method. The method takes index as a parameter, which basically refers to the shoe model, as shown here:
newPayment = (index) => { var mAddress; let app = this;
- Next, we define two asynchronous calls:
- The first asynchronous call is to our local API, getMAddress, which dynamically generates a new Merchant address for receiving payments for each payment request. We'll talk more on this API later. This newly generated address is then updated to the state along with the details of the item for which the payment is being processed, as shown here:
(async function ...