Initialize the Square Payments object
Initialize the Square Payments object with your application ID and the ID of the seller location where the payment is taken.
const payments = Square.payments(APPLICATION_ID, LOCATION_ID);
Create a GiftCard object
const giftCard = await payments.giftCard();
This creates a new GiftCard instance with all of the behaviors and properties needed to take a Gift Card payment.
Attach the GiftCard object to your page
Attach the GiftCard object to an empty DOM element on your page. The Gift Card form renders into the empty element, turning it into a secure gift card form.
Get the one-time payment token from the GiftCard object
Get the payment token from the
GiftCardobject when the buyer completes the form by calling the tokenize method.
this.elements.token.value = await giftCard.tokenize();
If the Gift Card information is valid, it returns a one-time use token to make a call to the Payments API CreatePayment endpoint to charge a customer. Otherwise, it will return an error that you can present to the customer.