Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid JSON error when deleting Card from Customer #992

Merged
merged 3 commits into from
Jul 13, 2018

Conversation

danj-stripe
Copy link
Contributor

Summary

We use the same code path to delete/detach Card + Source + any STPSourceProtocol from
a Customer. Depending on the type of the object, the response varies, but the only field
that the response always has is id.

This updates the private STPAPI deleteSource:fromCustomerUsingKey:completion: method
to use a new class, STPGenericStripeObject, as the deserializer. Now the SDK doesn't
incorrectly report failures.

Motivation

IOS-798

Testing

Minor updates to the tests, but this was best tested manually in the Standard Integration.

  1. In CheckoutViewController.init, change config.createCardSources to false.
  2. In [STPPaymentMethodsInternalViewController tableView:commitEditingStyle:forRowAtIndexPath:],
    add a completion block to the [self.apiAdapter detachSourceFromCustomer:completion:] call.
    I chose to log the error, but you could also set a breakpoint and inspect it.
  3. Run standard integration
  4. Add two cards in the payment information
  5. Delete the non-default card.

We don't have an automated way to create customers & attach sources, because that requires
a secret key.

We also don't have an existing test pattern to mock network responses to STPAPIClient.

This did not have a functional impact on the testing, but it sure was misleading
while reading through the code.
Some of the Stripe APIs, notably https://stripe.com/docs/api#delete_card return an
almost empty object. The parsing code needs to be able to parse an object out of the
response, otherwise it considers it failed.

This is an object that should be parseable from any successful response. It's pretty
useless otherwise.
…rUsingKey:completion:`

When deleting a `Card`, the returned JSON does not have all the required fields for a
`STPCard` - it only has `id` and `deleted`.
When deleting/detaching a `Source`, the returned JSON *is* a decodable `Source` (and does
not have a `deleted` field).

Using `STPGenericStripeObject` as the deserializer, because it's the only thing that'll
work for this method. We cannot use multiple deserializers, because the parsing code relies
on the `object` field to pick the correct deserializer, and deleted Cards don't have an
`object`.

Since the `STPGenericStripeObject` is *not* interesting (the caller already has the id, it
was the first argument to this method), just using `STPErrorBlock` as the completion.
@danj-stripe
Copy link
Contributor Author

cc @bg-stripe: thanks for chatting about this.

@danj-stripe danj-stripe merged commit 892421f into master Jul 13, 2018
@danj-stripe danj-stripe deleted the danj/bugfix/deleting-cards branch July 13, 2018 17:41
csabol-stripe pushed a commit that referenced this pull request Apr 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants