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

rebill-reactnative-sdk

v1.0.3

Published

Module card for payments

Downloads

7

Readme

Rebill React Native SDK

El React Native SDK es una herramienta que permite el procesamiento de pagos con tarjetas de crédito de forma segura.

Para más información acceda a la documentación oficial.

Instalación

npm install rebill-reactnative-sdk

Ejemplo de como crear un flujo de cobro de tarjeta de un producto/precio previamente creado

El SDK ofrece una funcionalidad de "Checkout" que te permite procesar pagos a través de tarjetas de crédito o débito. A continuación se muestra un ejemplo de cómo utilizar este componente en tu aplicación:


import React, { useEffect, useState } from 'react';
import { StyleSheet, ActivityIndicator, Text, Button, SafeAreaView } from 'react-native';
import { CreditCardInput, RebillSdk } from 'rebill-reactnative-sdk';

const merchantOrganizationId = 'your-merchant-organization-id';

const merchantApiKey = 'your-merchant-api-key';

const customer = {
  firstName: 'John',
  lastName: 'Doe',
  email: '[email protected]',
  personalId: {
    type: 'DNI',
    value: '38617261',
  },
  phone: {
    countryCode: '54',
    areaCode: '11',
    phoneNumber: '26423002',
  },
  address: {
    country: 'AR',
    street: 'Arenales',
    number: '554',
    zipCode: '1638',
    city: 'Vicente Lopez',
    state: 'Buenos Aires',
  },
};

const cardHolder = {
  identification: {
    type: 'DNI',
    value: '35094310',
  },
  name: 'John Doe',
};

const transaction = {
  prices: [
    {
      id: 'a-price-id',
      quantity: 2,
    },
  ],
};

const defaultValues = {
  number: '4509953566233704',
  expiry: '11/25',
  cvc: '123',
};

const App = () => {
  const [checkoutInProcess, setCheckoutInProcess] = useState(false);
  const [result, setResult] = useState();
  const [error, setError] = useState();
  const [price, setPrice] = useState(0);

  const checkout = new RebillSdk(merchantOrganizationId, merchantApiKey);

  # set 'Customer'
  checkout.setCustomer(customer);

  # set 'CardHolder'
  checkout.setCardHolder(cardHolder);

  # set 'Transaction'
  checkout.setTransaction(transaction);

  # set 'Callbacks'
  checkout.setCallbacks({
    onGetPricesSuccess: p => setPrice(p),
    onCheckoutSuccess: r => setResult(r),
    onCheckoutError: e => setError(e),
  });

  useEffect(() => {
    checkout.getPrices();
  }, []);

  useEffect(() => {
    if (checkoutInProcess) {
      setResult();
      setError();
    }
  }, [checkoutInProcess]);

  const handleOnPressCheckout = async () => {
    setCheckoutInProcess(true);
    await checkout.checkout();
    setCheckoutInProcess(false);
  };

  return (
    <View style={styles.container}>
      <CreditCardInput
        defaultValues={defaultValues}
        rebillSdk={checkout}
        validColor="black"
        invalidColor="red"
        placeholderColor="darkgray"
        labelButton="Pay"
        payOrCreate="pay"
      />
      {checkoutInProcess ? <ActivityIndicator /> : <Text>{`${price}`}</Text>}
      {result && <Text>{`Result: ${JSON.stringify(result)}`}</Text>}
      {error && <Text>{`Error: ${JSON.stringify(error)}`}</Text>}
    </View>
  );
};

export default App;

const styles = StyleSheet.create({
  safeArea: { marginHorizontal: 12, marginVertical: 16 },
});

Ejemplo de como crear un flujo para solicitar tarjeta y tokenizarla, pero sin generar cargo

En este ejemplo, se utiliza el componente CreditCardInput para capturar los detalles de la tarjeta de crédito del usuario. El SDK RebillSdk se inicializa con el ID de organización y la clave de API proporcionados. También se configuran los detalles del titular de la tarjeta, el correo electrónico del cliente y los callbacks para manejar el éxito y los errores al crear la tarjeta.

import {View, Alert} from 'react-native';
import {CreditCardInput, RebillSdk} from 'rebill-reactnative-sdk';

function App() {
  const merchantOrganizationId = 'your-merchant-organization-id';

  const merchantApiKey = 'your-merchant-api-key';

  const sdk = new RebillSdk(merchantOrganizationId, merchantApiKey);

  const customerEmail = '[email protected]';

  const cardholder = {
    identification: {
      type: 'DNI',
      value: '1111111',
    },
    name: 'Someone',
  };

  const defaultValues = {
    number: '4242424242424242',
    expiry: '11/28',
    cvc: '123',
  };

  const onAddCardSuccess = (cardId) => {
    Alert.alert('Card created', `Id: ${cardId}`, [{text: 'OK'}]);
  };

  const onAddCardError = (error) => {
    Alert.alert(
      'Error creating card',
      `Message: ${error.message}. Code: ${error.code}`,
      [{text: 'OK'}],
    );
  };

  return (
    <View style={{paddingTop: 100}}>
      <CreditCardInput
        defaultValues={defaultValues}
        rebillSdk={sdk}
        validColor="black"
        invalidColor="red"
        placeholderColor="darkgray"
        labelButton="Create"
        payOrCreate="create"
        cardholder={cardholder}
        customerEmail={customerEmail}
        onAddCardSuccess={onAddCardSuccess}
        onAddCardError={onAddCardError}
      />
    </View>
  );
}

export default App;

Ejemplo de como crear un flujo para solicitar la eliminación de una tarjeta

const merchantOrganizationId = process.env.organizationId;
const merchantApiKey = process.env.apiKey;

const sdk = new RebillSdk(merchantOrganizationId, merchantApiKey);

const cardId = 'some-card-id';

const customerEmail = '[email protected]';

const onRemoveCardSuccess = () => {
  console.log('Card removed');
};
const onRemoveCardError = (error) => {
  console.error('Error removing card', error);
};

await sdk.paymentMethods.removeCard(cardId, customerEmail, {
  onSuccess: onRemoveCardSuccess,
  onError: onRemoveCardError,
});

Atributos del componente CreditCardInput

| name | description | type | default | | :----------------------------- | :------------------------------------------- | --------: | :------- | | autoFocus | Open keyboard when show component | Boolean | true | | inputStyle | Styles input | ViewStyle | - | | buttonStyle | Styles button | ViewStyle | - | | buttonTextStyle | Styles text button | TextStyle | - | | validColor | String | String | black | | invalidColor | String | String | red | | placeholderColor | String | String | gray | | validButtonColor | String | String | black | | invalidButtonColor | String | String | darkgray | | additionalInputProps | Input props | Object | - | | additionalButtonInputProps | Input props | Object | - | | additionalTextButtonInputProps | Input props | Object | - | | iconStyle | Styles input | ViewStyle | - | | labelButton | String | String | - | | icon | View | View | - | | placeholders | String | String | - | | defaultValues | Object | Object | - | | rebillSdk | Object | RebillSdk | - | | cardholder | Cardholder user for create card | Object | - | | onAddCardSuccess | Callback for successful card creation | Function | - | | onAddCardError | Callback for failed card creation | Function | - | | payOrCreate | Indicate if button's action is pay or create | String | pay | | customerEmail | Customer email used for create card | String | null |