Learn how to use the Web Payments SDK to accept Square gift card payments.
To make purchases, buyers submit Square gift cards by entering only a card number. Expiration dates, CVV numbers, and postal codes aren't used. Accordingly, the payment form for gift cards only has a card number field. The payment token generated from a gift card is used as the
.source_id value and a payment is created as though the source is any other payment card.
Did you know?
Gift cards are configured and sold by a seller using the Seller Dashboard. A gift card can only be used to pay for purchases from the seller who issued the gift card.
Some payment applications allow for multiple payments on a purchase while others don't. Gift card payments must take this into account. For example, an application might not allow a gift card payment if it cannot cover the entire purchase amount. An application can restrict gift card payment approvals based on the available balance of a gift card. The approval restriction is set on individual payment requests.
If an application allows multiple payments for a purchase, it should allow for partial authorization approval when the gift card balance is less than the total purchase amount. In this case, the full balance of the card is used in the purchase, leaving a remaining purchase amount. This approval is known as partial authorization.
For example, a buyer is purchasing a pair of running shoes for $200 USD and the gift card balance is $50 USD. In this case, the gift card payment is authorized for the full card balance. The remaining purchase amount of $150 USD is covered by another gift card or payment card, creating an additional
The calculation of the remaining purchase amount and linking of individual payments is handled by the payment application's backend and is normally done in the server session that manages the checkout experience.
A buyer might decide to cancel a purchase after a gift card payment is approved and before completing a checkout. Canceling a purchase with a gift card involves calling Payments.CancelPayment.
Approved gift card funds are held until the purchase is completed or canceled, or the approval times out in 7 days. Be sure to complete the payment cancellation flow if the buyer decides not to complete a purchase.
This call flow assumes that your backend provides checkout and payment pages. To accept a gift card, a payment page renders the payment form in a gift card mode that only has a gift card number input field. The payment page should also render a payment form in the payment card mode for accepting credit or debit card payments.
To support these payment methods, create the following:
- Client - A payment method application to render the gift card form, payment card form, and optional digital wallets.
- Server - An endpoint to create a
Paymentobject for each posted payment token. Optionally, the endpoint can request the
Orderobject created by the checkout for linking the payments and order completion.
Any combination of a gift card and payment card can be used to pay the total purchase amount. When a gift card balance isn't enough to complete a purchase, a buyer makes an additional payment to complete the purchase. The payment can be another gift card or a payment card.
This flow processes payment tokens individually and associates all payments with the
Order representing a purchase.
Did you know?
Order is used to associate multiple payments, a single transaction is shown in the Seller Dashboard with a payment for each card used by the buyer.
If more than one
Payment object is created without a parent
Order, the purchase can still be completed but the Seller Dashboard shows a separate transaction for each payment.
The following call flow supports a multiple payment purchase:
Client: The checkout page requests a new
Order for the purchase from the server.
Server: Calls the Orders API to create an order and respond to the client with the new
- The payment page gets the
.idfrom the checkout page.
- The buyer provides a payment in a gift card or payment card form to generate a payment token.
Client: POSTs the payment token and the
- Gets the unpaid balance of the order from the checkout service.
- Uses the payment token to create a
Paymentusing the unpaid balance and then POSTs the
- Sends a 200 response to the client with the
.id, the remaining order balance (which might be zero), and the payment status.
- If the response payment status is
APPROVEDand the remaining order amount is greater than zero, the client collects another payment (step 2).
- If the response payment status is
COMPLETED, the purchase gift card flow is complete.
The following diagram shows the flow when a buyer makes a purchase with a gift card and then pays the remaining balance with a payment card:
- Take a Gift Card Payment covers the client-side component that you create to present the gift card payment form.