npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@adyen/react-native

v2.4.1

Published

Wraps Adyen Checkout Drop-In and Components for iOS and Android for convenient use with React Native

Downloads

25,764

Readme

npm version Adyen iOS Adyen Android Maintainability Rating

[!NOTE] Google will introduce new target API level requirements for Google Play apps starting August 31 2024.

For React-Native 73+ no action needed.

For React-Native 72:

  • update Android compileTarget to 34 in android/build.gradle
  • set classpath("com.android.tools.build:gradle:8.1.4") in android/build.gradle
  • enable buildConfig in android/app/build.gradle by adding android.buildFeatures.buildConfig = true

For React-Native before 72:

  • update Android compileTarget to 34 in android/build.gradle

React Native Logo

Adyen React Native

Adyen React Native provides you with the building blocks to create a checkout experience for your shoppers, allowing them to pay using the payment method of their choice.

You can integrate with Adyen React Native in two ways:

  • Drop-in: React Native wrapper for native iOS and Android Adyen Drop-in - an all-in-one solution, the quickest way to accept payments on your React Native app.
  • Components: React Native wrapper for native iOS and Android Adyen Components - one Component per payment method that can be combined with your own payments flow.

Contributing

We strongly encourage you to contribute to our repository. Find out more in our contribution guidelines

Prerequisites

Integration

Add @adyen/react-native to your react-native project.

yarn add @adyen/react-native

Expo integration (experimental)

❕ Please pay attention that this library is not compatible with ExpoGo. You can use it only with Expo managed workflow.

Add @adyen/react-native plugin to your app.json;

{
  "expo": {
    "plugins": ["@adyen/react-native"]
  }
}

In case you are facing issues with the plugin, please pre-build your app and investigate the files generated:

npx expo prebuild --clean

Expo plugin configuration

merchantIdentifier

Sets ApplePay Merchant ID to your iOS app's entitlment file. Empty by default.

useFrameworks

Adjust import on iOS in case your Podfile have use_frameworks! enabled.

Example

{
  "expo": {
    "plugins": [
      [
        "@adyen/react-native",
        {
          "merchantIdentifier": "merchant.com.my-merchant-id",
          "useFrameworks": true
        }
      ]
    ]
  }
}

Manual Integration

iOS integration

  1. run pod install
  2. add return URL handler to your AppDelegate.m(m)
#import <adyen-react-native/ADYRedirectComponent.h>

...

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
  return [ADYRedirectComponent applicationDidOpenURL:url];
}

In case you are using RCTLinkingManager or other deep-linking techniques, place ADYRedirectComponent.applicationDidOpenURL before them.

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
  return [ADYRedirectComponent applicationDidOpenURL:url] || [RCTLinkingManager application:application openURL:url options:options];
}

For Universal Link support, use:

- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
  if ([[userActivity activityType] isEqualToString:NSUserActivityTypeBrowsingWeb]) {
   NSURL *url = [userActivity webpageURL];
    if (![url isEqual:[NSNull null]] && [ADYRedirectComponent applicationDidOpenURL:url]) {
      return YES;
    }
  }
  return [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
}

❕ If your Podfile has use_frameworks!, then change import path in AppDelegate.m(m) to use underscore(_) instead of hyphens(-):

#import <adyen_react_native/ADYRedirectComponent.h>
  1. Add custom URL Scheme to your app.

For ApplePay

Follow general Enable ApplePay for iOS guide.

Android integration

  1. Provide your Checkout activity to AdyenCheckout in MainActivity.java.
import com.adyenreactnativesdk.AdyenCheckout;
import android.os.Bundle;

...

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(null);
  AdyenCheckout.setLauncherActivity(this);
}
For standalone components
  1. Add intent-filter to your Checkout activity:
<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="myapp" android:path="/payment" />
</intent-filter>
  1. To enable standalone redirect components, return URL handler to your Checkout activity onNewIntent in MainActivity.java:
import android.content.Intent;

...

@Override
public void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    AdyenCheckout.handleIntent(intent);
}
  1. To enable GooglePay, pass state to your Checkout activity onActivityResult in MainActivity.java:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);
  AdyenCheckout.handleActivityResult(requestCode, resultCode, data);
}
  1. Make sure your main app theme is decendent of Theme.MaterialComponents.
  <style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    <!-- Your configuration here -->
  </style>

Usage

For general understanding of how prebuilt UI components of Adyen work you can follow our documentation.

Configuration

To read more about other configuration, see the full list. Example of required configuration:

import { Configuration } from '@adyen/react-native';

const configuration: Configuration = {
  environment: 'test', // When you're ready to accept real payments, change the value to a suitable live environment.
  clientKey: '{YOUR_CLIENT_KEY}',
  countryCode: 'NL',
  amount: { currency: 'EUR', value: 1000 }, // Value in minor units
  returnUrl: 'myapp://payment', // Custom URL scheme of your iOS app. This value is overridden for Android by `AdyenCheckout`. You can also send this property from your backend.
};

Opening Payment component

To use @adyen/react-native you can use our helper component AdyenCheckout and helper functions from useAdyenCheckout with standalone component:

import { useAdyenCheckout } from '@adyen/react-native';

const MyCheckoutView = () => {
  const { start } = useAdyenCheckout();

  return (
    <Button
      title="Open DropIn"
      onPress={() => {
        start('dropIn');
      }}
    />
  );
};

Sessions flow

import { AdyenCheckout } from '@adyen/react-native';
import { useCallback } from 'react';

  const onComplete = useCallback( (result, nativeComponent ) => {
    /* When this callbeck executed, you must call `component.hide(true | false)` to dismiss the payment UI. */
  }, [some, dependency]);
  const onError = useCallback( (error, component) => {
    /* Handle errors or termination by shopper */
    /* When the API request is completed, you must now call `component.hide(false)` to dismiss the payment UI. */
  }, []);

<AdyenCheckout
  config={configuration}
  session={session}
  onComplete={onComplete}
  onError={onError}
>
  <MyCheckoutView />
</AdyenCheckout>;

Advanced flow

import { AdyenCheckout } from '@adyen/react-native';
import { useCallback } from 'react';

  const onSubmit = useCallback( (data, nativeComponent ) => {
    /* Call your server to make the `/payments` request, make sure you pass `returnUrl:data.returnUrl` to make redirect flow work cross platform */
    /* When the API request contains `action`, you should call `component.handle(response.action)` to dismiss the payment UI. */
    /* When the API request is completed, you must now call `component.hide(true | false)` to dismiss the payment UI. */
  }, [some, dependency]);
  const onAdditionalDetails = useCallback( (paymentData, component) => {
    /* Call your server to make the `/payments/details` request */
    /* When the API request is completed, you must now call `component.hide(true | false)` to dismiss the payment UI. */
  }, []);
  const onError = useCallback( (error, component) => {
    /* Handle errors or termination by shopper */
    /* When the API request is completed, you must now call `component.hide(false)` to dismiss the payment UI. */
  }, []);

<AdyenCheckout
  config={configuration}
  paymentMethods={paymentMethods}
  onSubmit={onSubmit}
  onAdditionalDetails={onAdditionalDetails}
  onError={onError}
>
  <MyCheckoutView />
</AdyenCheckout>;

Handling Actions

Some payment methods require additional action from the shopper such as: to scan a QR code, to authenticate a payment with 3D Secure, or to log in to their bank's website to complete the payment. To handle these additional front-end chalanges, use nativeComponent.handle(action) from onSubmit callback.

const handleSubmit = (paymentData, nativeComponent) => {
  server.makePayment(paymentData)
    .then((response) => {
      if (response.action) {
        nativeComponent.handle(response.action);
      } else {
        nativeComponent.hide(response.result);
      }
    });
};

<AdyenCheckout
  ...
  onSubmit={handleSubmit}
  >
    ...
</AdyenCheckout>

Standalone Action handling

In case of API-only integration AdyenAction.handle could be used. Before you begin, make sure you follow all iOS integration and Android integration steps.

Example:

import { AdyenAction } from '@adyen/react-native';

const data = await AdyenAction.handle(apiResponse.action, { environment: 'test', clientKey: '{YOUR_CLIENT_KEY}');
result = await ApiClient.paymentDetails(data);

Documentation

Support

If you have a feature request, or spotted a bug or a technical problem, create a GitHub issue. For other questions, contact our Support Team via Customer Area or via email: [email protected]

License

MIT license. For more information, see the LICENSE file.