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

Use sdk_uuid for payment and setup intents #551

Merged
merged 12 commits into from
Oct 16, 2023
Merged

Use sdk_uuid for payment and setup intents #551

merged 12 commits into from
Oct 16, 2023

Conversation

nazli-stripe
Copy link
Collaborator

@nazli-stripe nazli-stripe commented Oct 3, 2023

Summary

Updates PaymentIntent and SetupIntent methods to take the whole model and identify the PI based on a newly generated UUID.

Motivation

Offline mode prep

Testing

  • I tested this manually
  • I added automated tests

Documentation

Select one:

  • I have added relevant documentation for my changes.
  • This PR does not result in any developer-facing changes.

@ianlin-bbpos ianlin-bbpos marked this pull request as ready for review October 10, 2023 02:10
src/functions.ts Outdated
): Promise<SetupIntentResultType> {
return Logger.traceSdkMethod(async (innerSetupIntentId) => {
return Logger.traceSdkMethod(async (innerSetupInten) => {
Copy link
Collaborator Author

@nazli-stripe nazli-stripe Oct 10, 2023

Choose a reason for hiding this comment

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

typo, should be innerSetupIntent

Comment on lines -84 to +93
paymentIntentId: string
paymentIntentJson: PaymentIntent.Type
): Promise<PaymentIntentResultType>;
// Create Setup Intent
createSetupIntent(
params: CreateSetupIntentParams
): Promise<SetupIntentResultType>;
// Cancel Payment Intent
cancelPaymentIntent(
paymentIntentId: string
paymentIntent: PaymentIntent.Type
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we need these updates for cancelSetupIntent and confirmSetupIntent as well

@@ -108,11 +108,15 @@ export interface StripeTerminalSdkType {
clearReaderDisplay(): Promise<ClearReaderDisplayResultType>;
retrieveSetupIntent(clientSecret: string): Promise<SetupIntentResultType>;
// Cancel Setup Intent
cancelSetupIntent(paymentIntentId: string): Promise<SetupIntentResultType>;
cancelSetupIntent(
paymentIntent: PaymentIntent.Type
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this should be setupIntent: SetupIntent.Type

// List of locations belonging to the merchant
getLocations(params: GetLocationsParams): Promise<GetLocationsResultType>;
// Confirm Setup Intent
confirmSetupIntent(paymentIntentId: string): Promise<SetupIntentResultType>;
confirmSetupIntent(
paymentIntent: PaymentIntent.Type
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

same here

bric-stripe
bric-stripe previously approved these changes Oct 13, 2023
Copy link
Collaborator

@bric-stripe bric-stripe left a comment

Choose a reason for hiding this comment

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

iOS changes LGTM aside from a non-blocking request to improve the error messaging on the UUID checks to make those a little friendlier since the UUID is an internal detail

Comment on lines 482 to 487
guard let uuid = paymentIntentJSON["sdk_uuid"] as? String else {
resolve(Errors.createError(code: CommonErrorType.InvalidRequiredParameter, message: "You must provide sdk_uuid."))
return
}
guard let paymentIntent = self.paymentIntents[Optional(id)] else {
resolve(Errors.createError(code: CommonErrorType.InvalidRequiredParameter, message: "There is no associated paymentIntent with id \(id)"))
guard let paymentIntent = self.paymentIntents[uuid] else {
resolve(Errors.createError(code: CommonErrorType.InvalidRequiredParameter, message: "There is no associated paymentIntent with uuid \(uuid)"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit-ish: We should probably improve the error messaging here since the UUID is an internal detail that a user wouldn't know how to debug without digging in to the SDK more.

suggestion for if no UUID in the dictionary:

Unexpected PaymentIntent. collectPaymentMethod requires you to use the PaymentIntent that was returned from either createPaymentIntent or retrievePaymentIntent.

suggestion for if it has a UUID but we don't have a matching entry:

Unexpected PaymentIntent. The PaymentIntent provided must be re-retrieved with retrievePaymentIntent or a new PaymentIntent must be created with createPaymentIntent. This can happen if the reader disconnected, another PaymentIntent was confirmed, or the PaymentIntent was canceled.

^ got there from reviewing when we clear out self.paymentIntents and disconnect, post confirm, and cancel are the when we do that. So if someone

  1. created a PI A
  2. created a PI B
  3. collected and confirmed PI A
  4. attempted to collect PI B the SDK would error with the miss on paymentIntents[uuid] and they'd get this second error message telling to re-retrieve or create a new PI. (if I understand correctly this shouldn't be a new problem...before they would have gotten the "There is no associated paymentIntent with id (id)" error)

(and if we do improve the error messages we should do the same in the android layer too)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

even though it's an internal detail I feel like it is good for users to know exactly what is wrong with the PI they provided. We often get user inquiries on parameters due to vague error messages that don't tell which param or field caused the issue.

The PaymentIntent is missing sdk_uuid field.

No PaymentIntent was found with the sdk_uuid {some_uuid}. The PaymentIntent provided must be re-retrieved with retrievePaymentIntent or a new PaymentIntent must be created with createPaymentIntent.

would you be okay if we changed it to this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yep, sounds good to me

Comment on lines 589 to 594
guard let uuid = paymentIntentJson["sdk_uuid"] as? String else {
resolve(Errors.createError(code: CommonErrorType.InvalidRequiredParameter, message: "You must provide sdk_uuid."))
return
}

guard let paymentIntent = paymentIntents[Optional(id)] else {
resolve(Errors.createError(code: CommonErrorType.InvalidRequiredParameter, message: "There is no associated paymentIntent with id \(id)"))
guard let paymentIntent = self.paymentIntents[uuid] else {
resolve(Errors.createError(code: CommonErrorType.InvalidRequiredParameter, message: "There is no associated paymentIntent with uuid \(uuid)"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

similar request for improved error messaging here

Comment on lines 649 to 654
guard let uuid = paymentIntentJson["sdk_uuid"] as? String else {
resolve(Errors.createError(code: CommonErrorType.InvalidRequiredParameter, message: "You must provide sdk_uuid."))
return
}
guard let paymentIntent = paymentIntents[Optional(id)] else {
resolve(Errors.createError(code: CommonErrorType.InvalidRequiredParameter, message: "There is no associated paymentIntent with id \(id)"))
guard let paymentIntent = self.paymentIntents[uuid] else {
resolve(Errors.createError(code: CommonErrorType.InvalidRequiredParameter, message: "There is no associated paymentIntent with uuid \(uuid)"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

here too

Comment on lines 725 to 730
guard let uuid = setupIntentJson["sdk_uuid"] as? String else {
resolve(Errors.createError(code: CommonErrorType.InvalidRequiredParameter, message: "You must provide sdk_uuid."))
return
}
guard let setupIntent = setupIntents[id] else {
resolve(Errors.createError(code: CommonErrorType.InvalidRequiredParameter, message: "There is no associated setupIntentId with id \(id)"))
guard let setupIntent = self.setupIntents[uuid] else {
resolve(Errors.createError(code: CommonErrorType.InvalidRequiredParameter, message: "There is no associated setupIntentId with id \(uuid)"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

and for the 3 SetupIntent ones too

Copy link
Collaborator

@bric-stripe bric-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, thanks for the updates!

@nazli-stripe nazli-stripe merged commit f9aeda5 into main Oct 16, 2023
1 check passed
@nazli-stripe nazli-stripe deleted the nazli/pi-id branch September 7, 2024 17:13
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.

4 participants