GIft Card Id as source_id for Payment fails in Sandbox

I’m having difficulty paying for an order using the gift card’s Id as the source_id for a Payment in the Sandbox environment. I am attempting to use the PaymentsApi to create the Payments in question.

I have tried 2 different approaches.

Approach 1
Creating and activating my own gift card. I am able to retrieve the gift card using the RetrieveGiftCardFromGAN end point in the GiftCardsApi. I have verified that it is Active and has a balance. However, when using that gift card’s Id as a payment source for a different Order, I get the following error from Square:

Detail: Invalid card number.

Order Details for Creating and Activating Gift Card

OrderId: wJG45GoV5AxSgkomWiqgIYgrnZ4F
LineItem UId: rY24lmjoawYs1r3j11wPPD
GAN: 7783320005727177
Gift Card Id: gftc:0647a1bb3aa74182b7cf3230ae57a273

Order Details for Separate Order - Paying using above Gift Card

OrderId: w9ilBx9nfbNB2thNAHY1Rd72Ca4F
Gift Card Id: gftc:0647a1bb3aa74182b7cf3230ae57a273

Does anyone have an idea why would I not be able to use that as a payment source?

Approach 2
When I attempt to retrieve the test gift card found here using the RetrieveGiftCardFromGAN end point, so I could attempt to pay using that gift card’s Id, I get a different error:

Detail: No gift card found with that GAN.

We’re trying to allow our customers to use gift cards to pay for current and future orders, but I cannot seem to get anything but a single use nonce to work with gift cards.

Where am I going wrong?

Hi Jason, thanks for reaching out!

I was able to reproduce this issue, and believe it is a limitation of the current sandbox environment (for which Gift Cards API is in Beta). When using the Payments API in Sandbox, it accepts a very limited number of payment nonces for source_id that each have hard-coded responses. For your Approach #2, there is not an actual gift card in the Sandbox with that GAN, it is just a series of numbers that will produce a valid ‘gift card’ payment nonce when entered on a payment form.

For your Approach #1, the process you have described will work if done in the Production environment. Gift Card functionality is actually one of the easier things to test in Production with no consequences, as you can easily activate a Gift Card specifying the amount_money and with a buyer_payment_instrument_ids: 'cash' to load balances without having to complete a real transaction.

I would recommend retrying your process in Production and seeing if you are still having issues. I will check with our teams to see if the inability to create specific gift cards and then charge them in Sandbox was by design or is an oversight/bug.

@Max-Square thanks for the reply. I look forward to hearing the response RE inability to create gift cards, then charge them in the sandbox.

Hi Jason, I received confirmation that the only gift card source_id that works for the Sandbox Payments API is the test token cnon:gift-card-nonce-ok, and this is by design. I do think there could be value in changing this so that the full gift card feature set can be explored in a test environment. I will submit a feature request to our teams!

Thanks @Max-Square I appreciate it.

For what it’s worth, nuances like this might be worth including in documentation as well, as I’ve been pulling my hair out trying to figure out why gift card api calls haven’t been working.