Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Use new Stripe payment gateway #1057

Merged
merged 10 commits into from
Jul 14, 2021
Merged

Use new Stripe payment gateway #1057

merged 10 commits into from
Jul 14, 2021

Conversation

orzechdev
Copy link
Contributor

@orzechdev orzechdev commented Jun 17, 2021

I want to merge this change because... it adds new Stripe payment gateway with 3DS support.

Backend: saleor/saleor#7452

Screenshots

Pull Request Checklist

  1. All visible strings are translated with proper context.
  2. All data-formatting is locale-aware (dates, numbers, and so on).
  3. The changes are tested.
  4. The code is documented (docstrings, project documentation).
  5. Changes are mentioned in the changelog.

Test Environment Config

API_URI=https://feature-stripe.api.saleor.rocks/graphql/

@patrys
Copy link
Member

patrys commented Jun 17, 2021

@orzechdev orzechdev changed the title Add 3DS support to Stripe Use new Stripe payment gateway Jun 23, 2021
@orzechdev orzechdev marked this pull request as ready for review June 29, 2021 09:04
@orzechdev orzechdev requested review from a team, kamilpastuszka, SektorDV and eCzerniak and removed request for a team June 29, 2021 09:05
@orzechdev
Copy link
Contributor Author

Need to be merged together with saleor/saleor#7452

confirmationData: any;
confirmationNeeded: boolean;
}) => Promise<any>;
submitPayment: (data?: object) => Promise<any>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't there a specific type we could use for the returned Promise?

Copy link
Contributor

@kamilpastuszka kamilpastuszka Jul 5, 2021

Choose a reason for hiding this comment

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

Types for data and promise can be more specific

Copy link
Member

Choose a reason for hiding this comment

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

And if there isn't, it should be of type unknown, not any.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

import { IFormError } from "@types";

import { StripeCreditCardForm } from "../StripeCreditCardForm";
import { IProps } from "./types";

const messageDescription = "Stripe payment gateway error";

export const stripeErrorMessages = defineMessages({
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this stuff could go into intl.ts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, moved to separate intl.ts file for Stripe

]);
return;
}
let confirmation;
Copy link
Contributor

Choose a reason for hiding this comment

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

This could probably be done via const inside the try/catch block, followed by optional chaining wherever a potentially undefined key of this variable is accessed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if I understand correctly, const or let are scoped variables, so cannot be accessed outside of try/catch. Nevertheless, I have extracted these try/catch to the separate functions with immediate value return and I have added early return instead of if/else in this function, so I hope it is a little bit cleaner now.

),
]);
} else {
let paymentAction;
Copy link
Contributor

Choose a reason for hiding this comment

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

This could probably be done via const inside the try/catch block, followed by optional chaining wherever a potentially undefined key of this variable is accessed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same here

/**
* Method to call on gateway payment submission.
*/
submitPayment: (data?: object) => Promise<any>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as earlier, would it be possible to be more specific about the Promise return type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor

@kamilpastuszka kamilpastuszka left a comment

Choose a reason for hiding this comment

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

Generally, control flow in StripePaymentGateway.tsx can be potentially improved.

confirmationData: any;
confirmationNeeded: boolean;
}) => Promise<any>;
submitPayment: (data: object) => Promise<any>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Types for data and promise can be more specific

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Data type cannot be easily guessed due to the unknown Adyen gateway object, which will be returned, so I would rather stay with an object for now and also this object is simply passed to the backend where it is processed. Promise type is fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

As I can see, the overall structure of the object (all possible properties) is known, so even if objects in use may differ on case-by-case basis, there is still some room to apply type constraints. Something that can be considered in future, if not now.

confirmationData: any;
confirmationNeeded: boolean;
}) => Promise<any>;
submitPayment: (data?: object) => Promise<any>;
Copy link
Contributor

@kamilpastuszka kamilpastuszka Jul 5, 2021

Choose a reason for hiding this comment

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

Types for data and promise can be more specific

Comment on lines 19 to 38
export const stripeErrorMessages = defineMessages({
gatewayMisconfigured: {
defaultMessage: "Stripe gateway misconfigured. Api key not provided.",
description: messageDescription,
},
paymentSubmissionError: {
defaultMessage:
"Payment submission error. Stripe gateway returned no payment method in payload.",
description: messageDescription,
},
geytwayDisplayError: {
defaultMessage:
"Stripe payment gateway couldn't be displayed. Stripe elements were not provided.",
description: messageDescription,
},
paymentMethodNotCreated: {
defaultMessage: "Payment method has not been created.",
description: messageDescription,
},
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe worth using shorthand notation for description property?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@eCzerniak eCzerniak self-requested a review July 12, 2021 09:41
Copy link

@eCzerniak eCzerniak left a comment

Choose a reason for hiding this comment

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

404 is shown to user at the end of checkout process.

@jwm0 jwm0 merged commit 5bc3aef into master Jul 14, 2021
@jwm0 jwm0 deleted the SALEOR-3141-stripe-3ds-support branch July 14, 2021 13:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants