square / connect-csharp-sdk

C# client library for the Square Connect APIs
https://docs.connect.squareup.com/
Apache License 2.0
27 stars 25 forks source link

RetrievePayment() fails because invalid Tender.Type has invalid CardBrandEnum value #54

Closed sheam closed 5 years ago

sheam commented 6 years ago

I am retrieving payments sing

                Configuration.Default.AccessToken = tenant.AccessToken;
                var v1TranApi = new V1TransactionsApi();
                var apiPayment = v1TranApi.RetrievePayment(locationId, paymentId);

However they are failing because the the apiPayment.Tender.Type is INTERAC which does not existing in the Square.Connect.Model.V1Tender.CardBrandEnum.

ZyuDev commented 5 years ago

I got the same problem today.

Exception when calling V1TransactionsApi.ListPayments: Error converting value "MASTER_CARD" to type 'System.Nullable1[Square.Connect.Model.V1Tender+CardBrandEnum]'. Path '[6].tender[0].card_brand', line 1, position 17442.`

To overcome the problem, I added new value to CardBrandEnum. But I think it is not very good solution: change enum every time then we got unknown value. It would be better if unknown values parse as OTHER_BRAND, for example. And don't cause exception during API call.

ssung88 commented 5 years ago

ZyuDev, there is a MASTERCARD enum for CardBrand. It looks like you are getting MASTER_CARD instead and it throws an exception?

ZyuDev commented 5 years ago

shaofu88, Yes, you are right. There is MASTER_CARD value in data i retrieve from Square account. And this value throws an exception.

SeanoNET commented 5 years ago

I am also experiencing this issue.

Error converting value "MASTER_CARD" to type 'System.Nullable`1[Square.Connect.Model.V1Tender+CardBrandEnum]'. Path '[0].tender[0].card_brand', line 1, position 1453.

Why would the Square API be returning MASTER_CARD instead of MASTERCARD? Are card brands configurable in Square?

EDIT: This issue has been fixed in version 2.17.1

ssung88 commented 5 years ago

SeanoNET. Connect V1 is currently in maintenance, so we only resolve outstanding bugs, but we are not currently updating or changing the behavior due to us moving to V2 for all of our future APIs. Thank you for the question and using our SDK :)

This issue has been fixed in version 2.17.1.

sheam commented 5 years ago

But V2 doesn't support fetching payment information from webhooks.

StephenJosey commented 5 years ago

You can get to a V2 transaction from a webhook. Webhooks return the entity_id which is equivalent to payment_id in V1, which is equivalent to tender_id in V2. You can also get the V2 transaction from the V1 Payment object field payment_url. The ending of it is currently always the V2 transaction_id. In this payment_url example, "XYZ" would be the V2 transaction_id:

https://squareup.com/dashboard/sales/transactions/XYZ

Note, there are currently no plans to deprecate V1, but we are actively working on V2 for future features and implementations.