GithubHelp home page GithubHelp logo

abreurapha / react-native-pagseguro-plugpag Goto Github PK

View Code? Open in Web Editor NEW

This project forked from brunodsazevedo/react-native-pagseguro-plugpag

0.0 0.0 0.0 1.34 MB

License: MIT License

JavaScript 4.33% Ruby 7.94% C 0.20% Objective-C 5.10% Java 57.18% TypeScript 22.79% Objective-C++ 2.32% Swift 0.14%

react-native-pagseguro-plugpag's Introduction

react-native-pagseguro-plugpag

React Native Pagseguro Plugpag

README PORTUGUESE-BR VERSION

React Native Pagseguro Plugpag is a library aimed at integrating with the native library PlugPagServiceWrapper, maintained by Pagseguro. The library's purpose is to integrate Android applications with smart terminals, such as Moderninha Smart (A930), Moderninha Smart 2 (P2), and other terminals provided by the company.

๐Ÿ’ป Prerequisites

  • NodeJS >= 18.0.0
  • React Native >= 0.72
  • Expo >= 47 (optional)

๐Ÿš€ Installation

Installing with Yarn:

yarn add react-native-pagseguro-plugpag

Installing with npm:

npm install react-native-pagseguro-plugpag

Configuration in React Native

Add this line to the file /android/build.gradle:

buildscript {
  dependencies {
    ...
    classpath 'com.google.gms:google-services:4.3.15'
  }
}

and add this dependency to the file /android/app/build.gradle:

dependencies {
    // ... other dependencies
    implementation 'br.com.uol.pagseguro.plugpagservice.wrapper:wrapper:1.7.6'
    ...
}

Configuration in Expo

NOTE: The library does not support running on Expo Go due to its handling of libraries. The PlugPag Wrapper library is designed for use with Pagseguro's Android devices. Therefore, you need to use expo-dev-client to expose the android folder of your Expo project.

Add the react-native-pagseguro-plugpag plugin to app.json or app.config.js:

{
  "expo": {
    "plugins": [
      "react-native-pagseguro-plugpag"
    ]
  }
}

And to finalize, execute the prebuild step of expo to complete the configuration:

npx expo prebuild -p android --clean

๐Ÿ“– Usage

initializeAndActivatePinPad: initializes and activates the pin pad.

doPayment: performs communication and execution of financial transactions (debit card, credit card, voucher, and PIX).

refundPayment: performs refunds of financial transactions.

print: does customized printing from a JPEG/PNG file.

useTransactionPaymentEvent: hook for native events related to financial transactions.

Usage Examples

Example for activating a pin pad terminal.

NOTE: For development terminals, the code 403938 is commonly used. If it doesn't work, contact Pagseguro support.

import { initializeAndActivatePinPad } from 'react-native-pagseguro-plugpag';

async function handleInitializeAndActivatePinPad() {
  try {
    const data = await initializeAndActivatePinPad('403938');

    if (data.result !== 0) {
      Alert.alert('Error activating terminal', data.errorMessage);
      return;
    }

    Alert.alert('Terminal activated successfully!');
  } catch (error) {
    console.log(error);
    Alert.alert('Error activating terminal');
  }
}

Example for making credit card transactions with R$ 25.00:

import { plugPag, doPayment } from 'react-native-pagseguro-plugpag';

async function handleDoPaymentCreditType() {
  try {
    const data = await doPayment({
      amount: 2500, // Amount to be paid in cents
      type: plugPag.paymentTypes.CREDIT, // Payment type option
      printReceipt: true, // Print or not from the establishment
      installments: 1, // Number of installments
      installmentType: plugPag.installmentTypes.BUYER_INSTALLMENT, // In case of installments, define whether the fee will be charged to the buyer or the seller
      userReference: 'test', // External code to identify the transaction in the future.
    });

    Alert.alert('Transaction completed successfully');
  } catch (error) {
    console.log(error);
    setIsModalVisible(false);

    Alert.alert('Error completing transaction');
  }
}

Example for making debit card transactions with R$ 25.00:

import { plugPag, doPayment } from 'react-native-pagseguro-plugpag';

async function handleDoPaymentDebitType() {
  try {
    const data = await doPayment({
      amount: 2500, // Amount to be paid in cents
      type: plugPag.paymentTypes.DEBIT, // Payment type option
      printReceipt: true, // Print or not from the establishment
      installments: 1, // Number of installments
      installmentType: plugPag.installmentTypes.BUYER_INSTALLMENT, // In case of installments, define whether the fee will be charged to the buyer or the seller
      userReference: 'test', // External code to identify the transaction in the future.
    });

    Alert.alert('Transaction completed successfully');
  } catch (error) {
    console.log(error);
    setIsModalVisible(false);

    Alert.alert('Error completing transaction');
  }
}

Example for refunding a transaction:

async function handleRefundLastTransaction() {
  try {
    const response = await refundPayment({
      transactionCode: '123dwqwd5465sdas',
      transactionId: '78911qweqwdw7de44dd7qweqwed7d1qwe',
      printReceipt: true,
    });

    if (response.result !== 0) {
      Alert.alert('Refund', 'An error occurred while processing the refund');
      return;
    }

    Alert.alert('Refund completed successfully');
  } catch (error) {
    console.log(error);

    setIsModalVisible(false);
    Alert.alert('Refund', 'An error occurred while processing the refund');
  }
}

For more examples, see the demo app in this repository.

Contributing

See the contributing guide to learn how to contribute to the repository and the development flow.

License

MIT


Made with create-react-native-library

react-native-pagseguro-plugpag's People

Contributors

brunodsazevedo avatar abreurapha avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.