2.7.103 • Published 3 months ago

@taktikorg/ad-id v2.7.103

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

3 months ago

2.7.102

3 months ago

2.7.101

3 months ago

2.7.100

3 months ago

2.7.99

4 months ago

2.7.98

4 months ago

2.7.97

4 months ago

2.7.96

4 months ago

2.7.95

4 months ago

2.7.94

4 months ago

2.7.93

4 months ago

2.7.92

4 months ago

2.7.91

4 months ago

2.7.90

4 months ago

2.7.89

4 months ago

2.7.88

4 months ago

2.7.87

4 months ago

2.7.86

4 months ago

2.7.85

4 months ago

2.7.84

4 months ago

2.7.83

4 months ago

2.7.82

4 months ago

2.7.81

4 months ago

2.7.80

4 months ago

2.7.79

4 months ago

2.7.78

4 months ago

2.6.78

4 months ago

2.6.77

4 months ago

2.6.76

4 months ago

2.6.75

4 months ago

2.5.75

4 months ago

2.5.74

4 months ago

2.5.73

4 months ago

2.5.72

4 months ago

2.5.71

5 months ago

2.5.70

5 months ago

2.5.69

5 months ago

2.5.68

5 months ago

2.5.67

5 months ago

2.5.66

5 months ago

2.5.65

5 months ago

2.5.64

5 months ago

2.5.63

5 months ago

2.4.63

5 months ago

2.4.62

5 months ago

2.4.61

5 months ago

2.4.60

5 months ago

2.4.59

5 months ago

2.4.58

5 months ago

2.4.57

5 months ago

2.4.56

5 months ago

2.4.55

5 months ago

2.4.54

5 months ago

2.4.53

5 months ago

2.4.52

5 months ago

2.4.51

5 months ago

2.4.50

5 months ago

2.4.49

5 months ago

2.4.48

5 months ago

2.3.48

5 months ago

2.3.47

5 months ago

2.3.46

5 months ago

2.3.45

5 months ago

2.3.44

5 months ago

2.3.43

6 months ago

2.3.42

6 months ago

2.3.41

6 months ago

2.3.40

6 months ago

2.3.39

6 months ago

2.3.38

6 months ago

2.3.37

6 months ago

2.3.36

6 months ago

2.3.35

6 months ago

2.3.34

6 months ago

2.2.34

6 months ago

2.2.33

6 months ago

2.2.32

6 months ago

2.2.31

6 months ago

2.2.30

6 months ago

2.2.29

6 months ago

2.2.28

6 months ago

2.2.27

6 months ago

2.2.26

6 months ago

2.2.25

6 months ago

2.2.24

6 months ago

2.2.23

6 months ago

2.2.22

6 months ago

2.2.21

6 months ago

2.2.20

6 months ago

2.2.19

6 months ago

2.2.18

6 months ago

2.1.18

6 months ago

2.1.17

6 months ago

2.1.16

6 months ago

1.1.16

7 months ago

1.1.15

7 months ago

1.1.14

7 months ago

1.1.13

7 months ago

1.1.10

7 months ago

1.1.9

7 months ago

1.1.8

7 months ago

1.1.7

7 months ago

1.1.6

7 months ago

1.1.5

7 months ago

1.1.4

7 months ago

1.1.3

7 months ago

1.1.2

7 months ago

1.1.1

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago