mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-11-30 02:01:46 +00:00
* Removed StripeProps and use stripe.Stripe from @types/stripe-v3.
* Add `props.stripe` to StripeProviderProps * Updated tests.
This commit is contained in:
+3
-11
@@ -3,6 +3,7 @@
|
||||
// Definitions by: dan-j <https://github.com/dan-j>
|
||||
// Santiago Doldan <https://github.com/santiagodoldan>
|
||||
// sonnysangha <https://github.com/sonnysangha>
|
||||
// Andrew Goh Yisheng <https://github.com/9y5>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.6
|
||||
|
||||
@@ -23,23 +24,14 @@ export namespace ReactStripeElements {
|
||||
error?: { decline_code?: string };
|
||||
};
|
||||
|
||||
interface StripeProviderProps {
|
||||
apiKey: string;
|
||||
}
|
||||
|
||||
interface StripeProps {
|
||||
// I'm not sure what the definition for this is
|
||||
createSource(): void;
|
||||
|
||||
createToken(options?: TokenOptions): Promise<PatchedTokenResponse>;
|
||||
}
|
||||
type StripeProviderProps = { apiKey: string; stripe?: never; } | { apiKey?: never; stripe: stripe.Stripe; };
|
||||
|
||||
interface InjectOptions {
|
||||
withRef?: boolean;
|
||||
}
|
||||
|
||||
interface InjectedStripeProps {
|
||||
stripe?: StripeProps;
|
||||
stripe?: stripe.Stripe;
|
||||
}
|
||||
|
||||
interface ElementProps extends ElementsOptions {
|
||||
|
||||
@@ -107,18 +107,26 @@ interface ComponentProps {
|
||||
tokenCallback(token: PatchedTokenResponse): void;
|
||||
}
|
||||
|
||||
class WrappedComponent extends React.Component<ComponentProps & InjectedStripeProps> {
|
||||
class WrappedComponent extends React.Component<
|
||||
ComponentProps & InjectedStripeProps
|
||||
> {
|
||||
onSubmit = () => {
|
||||
this.props.stripe!.createToken({
|
||||
name: '',
|
||||
address_line1: '',
|
||||
address_line2: '',
|
||||
address_city: '',
|
||||
address_state: '',
|
||||
address_zip: '',
|
||||
address_country: '',
|
||||
currency: '',
|
||||
}).then((response: PatchedTokenResponse) => this.props.tokenCallback(response));
|
||||
const elements = this.props.stripe!.elements();
|
||||
const card = elements.create('card', { hidePostalCode: true });
|
||||
this.props.stripe!
|
||||
.createToken(card, {
|
||||
name: '',
|
||||
address_line1: '',
|
||||
address_line2: '',
|
||||
address_city: '',
|
||||
address_state: '',
|
||||
address_zip: '',
|
||||
address_country: '',
|
||||
currency: '',
|
||||
})
|
||||
.then((response: PatchedTokenResponse) =>
|
||||
this.props.tokenCallback(response)
|
||||
);
|
||||
}
|
||||
|
||||
isFormValid = () => {
|
||||
@@ -170,3 +178,13 @@ const ElementsDefaultPropsTest: React.SFC = () => (
|
||||
<PostalCodeElement />
|
||||
</div>
|
||||
);
|
||||
|
||||
/**
|
||||
* StripeProvider should either receive `apiKey` or `stripe`, but not both.
|
||||
* See: https://github.com/stripe/react-stripe-elements/blob/d30b32b6b8df282dd8880a3521667c371e90083f/src/components/Provider.js#L83-L86
|
||||
*/
|
||||
const TestStripeProviderProps1: React.SFC = () => <StripeProvider apiKey="" />;
|
||||
|
||||
const TestStripeProviderProps2: React.SFC<{
|
||||
stripe: stripe.Stripe;
|
||||
}> = props => <StripeProvider stripe={props.stripe} />;
|
||||
|
||||
Reference in New Issue
Block a user