Can Customer Payment Methods ever return an empty array

Solved

Can Customer Payment Methods ever return an empty array

fwallace
Shopify Partner
37 0 4

I have an app that will (via private proxy app using the shopify rails app) send an email to the logged in customer to update the customers payment method (useful for customers who have had their card change, roll over or have new expiration date). It works.

 

However, can the response sometimes include an empty array for payment methods (looking to exception handle)::

 

"paymentMethods"=>{"edges"=>[{"node"=>{"id"=>"gid://shopify/CustomerPaymentMethod/abcde123etc"}}]}}}

 

If I need to exception handle that's fine, I can't see any info where the payment method could be an empty array if say the card was declined repeatedly, or if the card was canceled, etc. Just trying to cover the bases here as this is a background job.

Accepted Solution (1)

ShopifyDevSup
Shopify Staff
1451 238 497

This is an accepted solution.

Hi @fwallace,

 

The Customer.paymentMethods connection returns a non-nullable array, which would be expected to be empty if the customer has no associated CustomerPaymentMethods.

 

If you are querying every customer as they log in then I would definitely recommend handling empty arrays. 

 

Hope that helps!

 

- James

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Reply 1 (1)

ShopifyDevSup
Shopify Staff
1451 238 497

This is an accepted solution.

Hi @fwallace,

 

The Customer.paymentMethods connection returns a non-nullable array, which would be expected to be empty if the customer has no associated CustomerPaymentMethods.

 

If you are querying every customer as they log in then I would definitely recommend handling empty arrays. 

 

Hope that helps!

 

- James

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog