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

Adds verify source endpoint #359

Merged
merged 1 commit into from
Oct 10, 2017
Merged

Adds verify source endpoint #359

merged 1 commit into from
Oct 10, 2017

Conversation

ob-stripe
Copy link
Contributor

@ob-stripe ob-stripe commented Jan 18, 2017

r? @will-stripe
cc @stripe/api-libraries @stan-stripe @remi-stripe

This PR adds support for the /v1/sources/src_.../verify endpoint.

AFAIK, only ach_debit sources use this endpoint at the moment, so I hardcoded Values as [2]uint8. I guess that in the future, other source types might expect different types for the values parameter, and we might want to anticipate on that.

Putting the PR up for review, but I'll leave it to you to decide whether we should merge as-is or wait.

@ob-stripe ob-stripe force-pushed the ob-verify-sources branch 2 times, most recently from 5f1dbae to 3d396a7 Compare January 18, 2017 16:03
@ob-stripe
Copy link
Contributor Author

After discussing it with @remi-stripe, I updated the PR to use the existing Amounts parameter -- the library will send it to the API as values for sources.

This will avoid a breaking change if we eventually add a generic Values parameter in SourceVerifyParams.

@will-stripe
Copy link

LGTM
Alternatively we can use an array of strings. If we are worried about breaking changes, I would suggest we go in that direction if we can, but I'm not too concerned.

source.go Outdated
AttemptsRemaining uint64 `json:"attempts_remaining"`
Status RedirectFlowStatus `json:"status"`
AttemptsRemaining uint64 `json:"attempts_remaining"`
Status VerificationFlowStatus `json:"status"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this just a mistake from before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my assumption, yes. I should have mentioned it in the PR, sorry about that!

@remi-stripe
Copy link
Contributor

@ob-stripe do you know if this still needs to be merged?

@ob-stripe ob-stripe changed the title [WIP] Adds verify source endpoint Adds verify source endpoint Mar 27, 2017
@ob-stripe
Copy link
Contributor Author

Yes, this still needs to be merged -- I forgot to remove the "[WIP]" tag in the PR's title.

Assigning to you @brandur-stripe

err = s.B.Call("POST", fmt.Sprintf("/customers/%v/sources/%v/verify", params.Customer, id), s.Key, body, &params.Params, source)
} else {
err = errors.New("Only customer bank accounts can be verified in this manner.")
body.Add("values[]", strconv.Itoa(int(params.Amounts[0])))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in its most general form, code_verification expects strings. We assume here that they are always numbers, which is OK for ACH debits (on bank account or on /v1/sources) but is not general enough for /v1/sources in general?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stan-stripe You have lots of context on this, so would you mind pitching an alternative? Should we keep Amounts for customer-specific verification and add a Values here? Should we keep the two-element array?

Copy link
Contributor

@stan-stripe stan-stripe Mar 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at the signature of SourceVerifyParams[0], it was really built for bank account verification on customer attached bank account objects (despite the thoughtful intent of making it a generic name)

The right type for the payment agnostic /v1/sources/:id/verify endpoint[1] is:

type NewNameOrMaybeSameNameSourceVerifyParams struct {
  Values []string
}

Unclear to me if we should rename the old one, or rename the new one, but these are two different constructs in the API. Hope that helps?

[0]

type SourceVerifyParams struct {

[1] https://github.com/stripe-internal/pay-server/blob/master/api/lib/api_method/source_verify.rb#L13

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclear to me if we should rename the old one, or rename the new one, but these are two different constructs in the API. Hope that helps?

Yep, that clears things up. Thanks!

@ob-stripe I'd probably suggest introducing a new struct like the one Stan has above and renaming the old one. The breaking change sucks, but looking at Splunk, it doesn't seem to be too widely used from the Go language right now (< 10 calls in the last week).

@ob-stripe ob-stripe force-pushed the ob-verify-sources branch 3 times, most recently from e681731 to c4d9607 Compare March 28, 2017 22:35
@ob-stripe
Copy link
Contributor Author

ob-stripe commented Mar 28, 2017

I updated the PR to handle this with a non-breaking change: I added a Values strings array to the SourceVerifyParams struct but left the existing Amounts integer array.

If the Customer param is used, then we assume that the verification is for a bank account and use the Amounts array. Otherwise we assume that it's for a source and use the Values array.

@brandur-stripe @stan-stripe wdyt?

@@ -38,6 +38,7 @@ type SourceVerifyParams struct {
Params
Customer string
Amounts [2]uint8
Values []string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind commenting Amounts here to indicate that it's for bank accounts only and essentially deprecated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ach_debit sources are not live yet so I think it's a little bit early to flag bank accounts as deprecated.

That said, I can add the comment and we can wait to merge the PR -- it might be a good idea anyway as there might be other changes before release (e.g. the change from verification to code_verification).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Yeah I was just thinking that if you come into this with very little information, both Amounts and Values are extremely generic names so it's really not intuitive at all that one would be meant for bank accounts and the other sources. It might be helpful to try and annotate this for users in some way.

Copy link
Contributor

@brandur-stripe brandur-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

One thought: should we support both Values and Amount for bank account verification?

@ob-stripe
Copy link
Contributor Author

One thought: should we support both Values and Amount for bank account verification?

Personally, I'd say no: /v1/customers/cus_.../sources/ba_.../verify expects an amounts parameter, while /v1/sources/src_.../verify expects a values parameter, and I'd rather not have that sort of magic mapping from one parameter name to another.

@brandur-stripe
Copy link
Contributor

Personally, I'd say no: /v1/customers/cus_.../sources/ba_.../verify expects an amounts parameter, while /v1/sources/src_.../verify expects a values parameter, and I'd rather not have that sort of magic mapping from one parameter name to another.

Fair enough. +1.

@brandur-stripe
Copy link
Contributor

@ob-stripe Can we proceed on this one?

@remi-stripe
Copy link
Contributor

@ob-stripe could you have a look at this one again rebased on the latest master?

@ob-stripe ob-stripe force-pushed the ob-verify-sources branch 3 times, most recently from a5ccb81 to f855eb1 Compare October 7, 2017 15:01
@ob-stripe
Copy link
Contributor Author

Done.

@brandur-stripe ptal

paymentsource.go Outdated
Customer string `form:"-"` // Goes in the URL
Amounts [2]uint8 `form:"amounts"` // Amounts is used when verifying bank accounts
Customer string `form:"-"` // Goes in the URL
Values []string `form:"values"` // Values in used when verifying sources
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor typo here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

} else {
err = errors.New("Only customer bank accounts can be verified in this manner.")
} else if len(params.Values) > 0 {
err = s.B.Call("POST", fmt.Sprintf("/sources/%v/verify", id), s.Key, body, &params.Params, source)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're likely missing an else that raises an error no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Added an else clause. The error message is a bit vague, I'm open to suggestions if you can think of something better!

@brandur-stripe
Copy link
Contributor

AFAIK, only ach_debit sources use this endpoint at the moment, so I hardcoded Values as [2]uint8. I guess that in the future, other source types might expect different types for the values parameter, and we might want to anticipate on that.

Thanks for picking this back up again!

@ob-stripe @remi-stripe One another kinda nit: I think one of the things Remi's doing with his big refactoring project right now is to just make all our integers the same type (not sure which one, but probably either int or int64. Do you think we could replace the uint8 with either one of these? It's not like you're going to be saving that many system resources by using a smaller integer size on verification (it's an infrequent operation and our modern 64-bit platforms are probably often storing it in 64 bits anyway) so just trying to fall into a convention here is probably more valuable.

Maybe int64 would be a good choice. We're never going to be storing numbers that are big enough that we'll need uint64 over int64, and it's kind of nice that int64 is unambiguous 64-bit, although honestly int is probably fine too.

@ob-stripe ob-stripe force-pushed the ob-verify-sources branch 2 times, most recently from d44a7ac to 798b1ea Compare October 10, 2017 12:16
@ob-stripe
Copy link
Contributor Author

Rebased on master and updated to use int64 for Amounts.

@brandur-stripe
Copy link
Contributor

Nice! int64 is a good choice.

@brandur-stripe brandur-stripe merged commit 7d462bb into master Oct 10, 2017
@brandur-stripe brandur-stripe deleted the ob-verify-sources branch October 10, 2017 17:05
@brandur-stripe
Copy link
Contributor

Released as 28.3.0.

nadaismail-stripe pushed a commit that referenced this pull request Oct 18, 2024
Bumps [mocha](https://github.com/freerange/mocha) from 1.13.0 to 1.14.0.
- [Release notes](https://github.com/freerange/mocha/releases)
- [Changelog](https://github.com/freerange/mocha/blob/main/RELEASE.md)
- [Commits](freerange/mocha@v1.13.0...v1.14.0)

---
updated-dependencies:
- dependency-name: mocha
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants