2.7.103 • Published 2 months ago

@taktikorg/ad-id v2.7.103

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months 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

2 months ago

2.7.102

2 months ago

2.7.101

2 months ago

2.7.100

2 months ago

2.7.99

2 months ago

2.7.98

2 months ago

2.7.97

2 months ago

2.7.96

2 months ago

2.7.95

2 months ago

2.7.94

3 months ago

2.7.93

3 months ago

2.7.92

3 months ago

2.7.91

3 months ago

2.7.90

3 months ago

2.7.89

3 months ago

2.7.88

3 months ago

2.7.87

3 months ago

2.7.86

3 months ago

2.7.85

3 months ago

2.7.84

3 months ago

2.7.83

3 months ago

2.7.82

3 months ago

2.7.81

3 months ago

2.7.80

3 months ago

2.7.79

3 months ago

2.7.78

3 months ago

2.6.78

3 months ago

2.6.77

3 months ago

2.6.76

3 months ago

2.6.75

3 months ago

2.5.75

3 months ago

2.5.74

3 months ago

2.5.73

3 months ago

2.5.72

3 months ago

2.5.71

3 months ago

2.5.70

3 months ago

2.5.69

3 months ago

2.5.68

3 months ago

2.5.67

3 months ago

2.5.66

4 months ago

2.5.65

4 months ago

2.5.64

4 months ago

2.5.63

4 months ago

2.4.63

4 months ago

2.4.62

4 months ago

2.4.61

4 months ago

2.4.60

4 months ago

2.4.59

4 months ago

2.4.58

4 months ago

2.4.57

4 months ago

2.4.56

4 months ago

2.4.55

4 months ago

2.4.54

4 months ago

2.4.53

4 months ago

2.4.52

4 months ago

2.4.51

4 months ago

2.4.50

4 months ago

2.4.49

4 months ago

2.4.48

4 months ago

2.3.48

4 months ago

2.3.47

4 months ago

2.3.46

4 months ago

2.3.45

4 months ago

2.3.44

4 months ago

2.3.43

4 months ago

2.3.42

4 months ago

2.3.41

4 months ago

2.3.40

4 months ago

2.3.39

4 months ago

2.3.38

5 months ago

2.3.37

5 months ago

2.3.36

5 months ago

2.3.35

5 months ago

2.3.34

5 months ago

2.2.34

5 months ago

2.2.33

5 months ago

2.2.32

5 months ago

2.2.31

5 months ago

2.2.30

5 months ago

2.2.29

5 months ago

2.2.28

5 months ago

2.2.27

5 months ago

2.2.26

5 months ago

2.2.25

5 months ago

2.2.24

5 months ago

2.2.23

5 months ago

2.2.22

5 months ago

2.2.21

5 months ago

2.2.20

5 months ago

2.2.19

5 months ago

2.2.18

5 months ago

2.1.18

5 months ago

2.1.17

5 months ago

2.1.16

5 months ago

1.1.16

5 months ago

1.1.15

5 months ago

1.1.14

5 months ago

1.1.13

5 months ago

1.1.10

6 months ago

1.1.9

6 months ago

1.1.8

6 months ago

1.1.7

6 months ago

1.1.6

6 months ago

1.1.5

6 months ago

1.1.4

6 months ago

1.1.3

6 months ago

1.1.2

6 months ago

1.1.1

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago