2.7.103 • Published 16 days ago

@taktikorg/ad-id v2.7.103

Weekly downloads
-
License
MIT
Repository
github
Last release
16 days ago

React Stripe.js

React components for Stripe.js and Elements.

build status npm version

Requirements

The minimum supported version of React is v16.8. If you use an older version, upgrade React to use this library. If you prefer not to upgrade your React version, we recommend using legacy react-stripe-elements.

Getting started

Documentation

Minimal example

First, install React Stripe.js and Stripe.js.

npm install @taktikorg/ad-id @stripe/stripe-js

Using hooks

import React, {useState} from 'react';
import ReactDOM from 'react-dom';
import {loadStripe} from '@stripe/stripe-js';
import {
  PaymentElement,
  Elements,
  useStripe,
  useElements,
} from '@taktikorg/ad-id';

const CheckoutForm = () => {
  const stripe = useStripe();
  const elements = useElements();

  const [errorMessage, setErrorMessage] = useState(null);

  const handleSubmit = async (event) => {
    event.preventDefault();

    if (elements == null) {
      return;
    }

    // Trigger form validation and wallet collection
    const {error: submitError} = await elements.submit();
    if (submitError) {
      // Show error to your customer
      setErrorMessage(submitError.message);
      return;
    }

    // Create the PaymentIntent and obtain clientSecret from your server endpoint
    const res = await fetch('/create-intent', {
      method: 'POST',
    });

    const {client_secret: clientSecret} = await res.json();

    const {error} = await stripe.confirmPayment({
      //`Elements` instance that was used to create the Payment Element
      elements,
      clientSecret,
      confirmParams: {
        return_url: 'https://example.com/order/123/complete',
      },
    });

    if (error) {
      // This point will only be reached if there is an immediate error when
      // confirming the payment. Show error to your customer (for example, payment
      // details incomplete)
      setErrorMessage(error.message);
    } else {
      // Your customer will be redirected to your `return_url`. For some payment
      // methods like iDEAL, your customer will be redirected to an intermediate
      // site first to authorize the payment, then redirected to the `return_url`.
    }
  };

  return (
    <form onSubmit={handleSubmit}>
      <PaymentElement />
      <button type="submit" disabled={!stripe || !elements}>
        Pay
      </button>
      {/* Show error message to your customers */}
      {errorMessage && <div>{errorMessage}</div>}
    </form>
  );
};

const stripePromise = loadStripe('pk_test_6pRNASCoBOKtIshFeQd4XMUh');

const options = {
  mode: 'payment',
  amount: 1099,
  currency: 'usd',
  // Fully customizable with appearance API.
  appearance: {
    /*...*/
  },
};

const App = () => (
  <Elements stripe={stripePromise} options={options}>
    <CheckoutForm />
  </Elements>
);

ReactDOM.render(<App />, document.body);

Using class components

import React from 'react';
import ReactDOM from 'react-dom';
import {loadStripe} from '@stripe/stripe-js';
import {
  PaymentElement,
  Elements,
  ElementsConsumer,
} from '@taktikorg/ad-id';

class CheckoutForm extends React.Component {
  handleSubmit = async (event) => {
    event.preventDefault();
    const {stripe, elements} = this.props;

    if (elements == null) {
      return;
    }

    // Trigger form validation and wallet collection
    const {error: submitError} = await elements.submit();
    if (submitError) {
      // Show error to your customer
      return;
    }

    // Create the PaymentIntent and obtain clientSecret
    const res = await fetch('/create-intent', {
      method: 'POST',
    });

    const {client_secret: clientSecret} = await res.json();

    const {error} = await stripe.confirmPayment({
      //`Elements` instance that was used to create the Payment Element
      elements,
      clientSecret,
      confirmParams: {
        return_url: 'https://example.com/order/123/complete',
      },
    });

    if (error) {
      // This point will only be reached if there is an immediate error when
      // confirming the payment. Show error to your customer (for example, payment
      // details incomplete)
    } else {
      // Your customer will be redirected to your `return_url`. For some payment
      // methods like iDEAL, your customer will be redirected to an intermediate
      // site first to authorize the payment, then redirected to the `return_url`.
    }
  };

  render() {
    const {stripe} = this.props;
    return (
      <form onSubmit={this.handleSubmit}>
        <PaymentElement />
        <button type="submit" disabled={!stripe}>
          Pay
        </button>
      </form>
    );
  }
}

const InjectedCheckoutForm = () => (
  <ElementsConsumer>
    {({stripe, elements}) => (
      <CheckoutForm stripe={stripe} elements={elements} />
    )}
  </ElementsConsumer>
);

const stripePromise = loadStripe('pk_test_6pRNASCoBOKtIshFeQd4XMUh');

const options = {
  mode: 'payment',
  amount: 1099,
  currency: 'usd',
  // Fully customizable with appearance API.
  appearance: {
    /*...*/
  },
};

const App = () => (
  <Elements stripe={stripePromise} options={options}>
    <InjectedCheckoutForm />
  </Elements>
);

ReactDOM.render(<App />, document.body);

TypeScript support

React Stripe.js is packaged with TypeScript declarations. Some types are pulled from @stripe/stripe-js—be sure to add @stripe/stripe-js as a dependency to your project for full TypeScript support.

Typings in React Stripe.js follow the same versioning policy as @stripe/stripe-js.

Contributing

If you would like to contribute to React Stripe.js, please make sure to read our contributor guidelines.

hasOwnECMAScript 2016fullwidthgesturespathefficientUnderscorebrowserlisthelpersshrinkwrapArray.prototype.containsredux-toolkitesshellfastcopyparentsES8takeback-endnegativewarningrouteimmutablemetadataes-shimsRxpoint-freetypeerrorbyteSymbol.toStringTagexpresscolumnsbusydropECMAScript 3toArrayECMAScript 6CSSStyleDeclaration_.extendcloneReactiveXrmdirString.prototype.trimtelephonereversedbeanstalkWeakSetspeedcoloureslintconfigES7eslint-plugincloudsearchnpmignoretypeofcopyservertc39inferenceintrinsicenvironmentstypedarraysrulescloudformationhookformuninstallArrayBuffer.prototype.sliceviewprivatelanguagediffartresolvewhichStyleSheetxmlstyleguidecjkecmascriptUint16Arraycss-in-jstermsymbolfiltercssonceomitMaprapids3spawnawesomesaucescheme-validationconcatrestcharactertddwebserializeprefixlrues2016ObservablenpmjQuerytoSortedsomeeventDispatcherforkregularfindupmrues8cloudtrailes-shim APIfastincludesECMAScript 2023instrumentationspringflatassertiongetwaitcoercibleobjectURLerrorbuffersource mapregular-expressionroutingapollochrome256qssinatracore-js$.extendmkdirswgetastECMAScript 2021typanionECMAScript 2020Array.prototype.flattencolorsameValueZeroexeccensorfixed-widthpostcssclientRxJSchineseconsumedayjsreact-testing-libraryelectronStreamsconsolechromiumquotereadablestreamtoolsESnextshebangpurefpdirconstcall-bindreusefunction.lengthcurl.gitignoredeleteeslinttypedarraytext[[Prototype]]ES2018fetchrminternal slottrimRightcommanderobjec2route53private dataframerjapanesequerystringworkerworkflowuuidiereduxparentelbWebSocketglobalsnativegetoptmake dirinstallerenvObject.iscall-boundfront-endchannelsetmkdirptrimLeftinternalasyncUint8ArrayimmerFunction.prototype.namesubprocessfantasy-landBigUint64ArrayHyBisymlinksqueuedeepcopyrobustcachedescriptorsbddassertlookformattinges6byteLengthchildreverseparseendervarsjsonarraysbufferspositivesearchstoragegatewaydefinestylesiteratehardlinksponyfilllibphonenumberbinweaksettransformsesJSON-Schemadeepreadjsdiffamazonvalidbannerdebugimportrm -rfmatchAllshamargvObjectpatchiteratorhasOwnPropertynamehooksramdacommand-lineidletypesidentifiersreact-hook-formdynamodbprocessmockelasticacheweakmapagentjson-schema-validationautoscalingfindLastIndexpreprocessor6to5traverseletfast-clonelengtha11yrgbsqsutilitieswritableObject.getPrototypeOfpostcss-pluginbyteOffsetassertsmonoreponodejstaptostringtagfsReflect.getPrototypeOfmapsettingsfile systemurlrdsmodulesdataViewaccessorstringifierslicezxObject.valuesTypeBoxcontainssnscompilerwidthoptimizernodeES2021genericsenumerablepnpm9tslibstyled-components3dstreamconcatMapUint8ClampedArraylistenersdeterministicdependency managerzodteststartertimerequestkeysRegExp.prototype.flagsrangeerrortoStringTagvalidatordatecloudfrontreactjson-schemaisistanbulhandlerpropertycolorsqueueMicrotaskcollectionObject.assignprogressAsyncIterator-0vestsimpledbindicatorlocalgetPrototypeOfhashsharedarraybufferestreeflagsi18nIteratorchaicollection.es6syntaxcolumnutilsvarbundlingdataviewentriestranspileignorethreerestfullocationArray.prototype.includesformsyupfunctionalloggingObject.definePropertyendpointwritees2015RFC-6455cryptomergeES2020parservalidateObject.fromEntriesformES6expressiontestertypescriptschemaconfigurabletoobjectkoreanfeedairbnbregular expressionyamlinspectvpcRegExp#flagsglacierlockfiledatawafanimationeast-asian-widthzeroreact-hooksphonehas-ownbinaryides2018optimistavaESdeep-copynegative zerospinnerflattencoreredirectasterisksrandomspinnersmkdirjavascriptcallboundmomentclass-validatorgrouplinkarraybuffervariablescallbackreal-timecompareguid.envinfast-deep-clonepluginio-tsdescriptores2017kinesis0valuesfastcloneeslintpluginclassesjsdomgetintrinsicmakehtmlenvironmentschemecoveragemapreducepicomatchpushpolyfillrssMicrosoftformatforEachArrayInt16ArrayargsStreamSetmulti-packageservicepackagesextraECMAScript 2019superagentrecursive@@toStringTagflatMapworkspace:*classnameutilpruneutil.inspectawsprettyglobalcloudwatchArray.prototype.flatreact poserm -frnumberapihastranspilerObject.keysextendYAMLArray.prototype.filterInt8ArrayinvariantTypeScriptsymbolsxtermcallfast-copyreadablefpsUint32ArraytrimEndreducerECMAScript 2015pinostructuredCloneunicodeproxyappjsxFloat32ArrayPushdragfilepipeansifindposemanipulationwalkingES2019PromisefnmatchsortedfolderarraymanagerECMAScript 5minimalpyyamlECMAScript 2017emrECMAScript 2022prototypegroupByprotocol-buffersrouterhelperclitoReversedpackage managertsequalstreamsredactInt32Arrayes-abstractReactiveExtensionssharedcodesremoveboundautoprefixertransportl10nECMAScript 2018curriedES3browserpackageeveryinputiamwalkharmonyform-validationcode pointsObject.entriesjasminedotenvglobequalityuser-streamsatomupvalueArrayBuffereffect-tsES2015importexporttacitES2016moduledefinePropertyregexfunctionbrowserslistsidevalidationdomArray.prototype.findLastfastifyfromajvslotdescriptionwhatwggetOwnPropertyDescriptorespreebabelcheckpopmotionoutputgitignoresafelogmochajshintkarmasetImmediateasciijsonschemaURLSearchParamsstableacornsyntaxerrorfast-deep-copyserializeroffsetsetterebs__proto__superstructtapeES5stylerfc4122ES2017deepclonesetPrototypeOfqueryfindLastloadbalancingpromisestringifyserializationcharactersregexpreworkexecfilenamesbindisConcatSpreadableBigInt64ArrayWebSocketscreatelook-upargumentmatchconfigutilityreduceArray.prototype.findLastIndexdebuggerhttpcommandtrimStartttylintString.prototype.matchAllxhrtouchaccessibilityeventsSymbolemitmobilemovegdprTypedArrayterminalbabel-coreObservablesES2022protoruntimepropertiesgraphqlmockingframeworkswfshimgetterJSONES2023escapetoolkitstylingloadingarktypecallbindECMAScript 7ArrayBuffer#slicebinariesperformanceclassnamesajaxfigletfind-updirectorymatcheseventEmittertypedcomputed-types
2.7.103

16 days ago

2.7.102

17 days ago

2.7.101

18 days ago

2.7.100

19 days ago

2.7.99

20 days ago

2.7.98

21 days ago

2.7.97

22 days ago

2.7.96

23 days ago

2.7.95

24 days ago

2.7.94

25 days ago

2.7.93

26 days ago

2.7.92

27 days ago

2.7.91

28 days ago

2.7.90

29 days ago

2.7.89

30 days ago

2.7.88

1 month ago

2.7.87

1 month ago

2.7.86

1 month ago

2.7.85

1 month ago

2.7.84

1 month ago

2.7.83

1 month ago

2.7.82

1 month ago

2.7.81

1 month ago

2.7.80

1 month ago

2.7.79

1 month ago

2.7.78

1 month ago

2.6.78

1 month ago

2.6.77

1 month ago

2.6.76

1 month ago

2.6.75

1 month ago

2.5.75

2 months ago

2.5.74

2 months ago

2.5.73

2 months ago

2.5.72

2 months ago

2.5.71

2 months ago

2.5.70

2 months ago

2.5.69

2 months ago

2.5.68

2 months ago

2.5.67

2 months ago

2.5.66

2 months ago

2.5.65

2 months ago

2.5.64

2 months ago

2.5.63

2 months ago

2.4.63

2 months ago

2.4.62

2 months ago

2.4.61

2 months ago

2.4.60

2 months ago

2.4.59

2 months ago

2.4.58

2 months ago

2.4.57

2 months ago

2.4.56

2 months ago

2.4.55

2 months ago

2.4.54

2 months ago

2.4.53

2 months ago

2.4.52

2 months ago

2.4.51

2 months ago

2.4.50

2 months ago

2.4.49

2 months ago

2.4.48

2 months ago

2.3.48

2 months ago

2.3.47

3 months ago

2.3.46

3 months ago

2.3.45

3 months ago

2.3.44

3 months ago

2.3.43

3 months ago

2.3.42

3 months ago

2.3.41

3 months ago

2.3.40

3 months ago

2.3.39

3 months ago

2.3.38

3 months ago

2.3.37

3 months ago

2.3.36

3 months ago

2.3.35

3 months ago

2.3.34

3 months ago

2.2.34

3 months ago

2.2.33

3 months ago

2.2.32

3 months ago

2.2.31

3 months ago

2.2.30

3 months ago

2.2.29

3 months ago

2.2.28

3 months ago

2.2.27

3 months ago

2.2.26

3 months ago

2.2.25

3 months ago

2.2.24

3 months ago

2.2.23

3 months ago

2.2.22

3 months ago

2.2.21

3 months ago

2.2.20

3 months ago

2.2.19

3 months ago

2.2.18

4 months ago

2.1.18

4 months ago

2.1.17

4 months ago

2.1.16

4 months ago

1.1.16

4 months ago

1.1.15

4 months ago

1.1.14

4 months ago

1.1.13

4 months ago

1.1.10

4 months ago

1.1.9

4 months ago

1.1.8

4 months ago

1.1.7

4 months ago

1.1.6

4 months ago

1.1.5

4 months ago

1.1.4

4 months ago

1.1.3

4 months ago

1.1.2

4 months ago

1.1.1

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago