[ Web Proxy ]
URL:
Viewing: https://developer.squareup.com/reference/sdks/web/payments/objects/GiftCard [Back]  [Original]

GiftCard Object - Square Web Payments SDK Reference

#
GiftCard

An object with the methods to create and set up a Gift Cards payment.

Created by calling the payments.giftCard() method.

Methods

#
addEventListener ( ... ) void

Adds an event listener to the GiftCard instance. Provides specific typings related to giftCard element events.

#
attach ( ... ) Promise<void>

Attaches the GiftCard form to the page.

#
clear ( ) Promise<boolean>

Clears the gift card fields and removes error messages

#
configure ( ... ) Promise<void>

Configures the GiftCard payment method with visual and behavior options.

#
destroy ( ) Promise<boolean>

Destroys the payment method. The attached element is emptied and all event listeners are removed.

#
detach ( ) Promise<boolean>

Detach the gift card payment object. The attached element is emptied but event listeners on the gift card remain. This is different from Destroy as this method only removes the gift card element and allows the developer to re-attach it to the page when they want to display it again.

#
focus ( ... ) Promise<boolean>

Sets the DOM focus of one of the input fields within the GiftCard form.

#
removeEventListener ( ... ) void

Removes an event listener from the GiftCard instance. Provides specific typings related to Gift Cards element events.

#
setError ( ... ) Promise<boolean>
#
tokenize ( ) Promise<SuccessfulTokenResult | ErrorTokenResult | OtherTokenResult>

Tokenizes a GiftCard payment method instance.

giftCard.js
JS
JavaScript
Copy

const payments = Square.payments(appId, locationId);

const giftCard = await payments.giftCard();

await giftCard.attach('#gift-card');

const form = document.querySelector('#gift-card-payment');

form.addEventListener('submit', async (event) => {

   event.preventDefault();

   const result = await giftCard.tokenize(); // the gift card nonce

});

Web Proxy Viewer  |  New URL  |  Original Page