react-native-cielolio

1.3.7 • Public • Published

react-native-cielolio

React Native CieloLio

Installation

  1. Install a package

from npm

npm install react-native-cielolio --save
  1. Download SDK Cielo

After download SDK clone in your mavenLocal repository .m2/repository:

  • Windows: C:\Users\<user>\.m2
  • Linux: /home/<user>/.m2
  • Mac: /Users/<user>/.m2
  1. Add at end of file /android/build.gradle
allprojects {
  repositories {
    mavenLocal()
  }
}
  1. Add dependency in build.gradle:
dependencies {
  implementation 'com.cielo.lio:order-manager:2.1.7'
}
  1. Change or add in android/app/src/main/AndroidManifest.xml allowBackup to true
android:allowBackup="true"

Usage

- initialize(clientID: string, accessToken: string): Promise

Load library with client ID, accessToken.

  • Client-Id Access identification;
  • Access-Token Access token identification, which stores the access rules allowed to the Client ID;

createDraftOrder(orderId: string): void

Create a draft order.

addItem(sku: string, name: string, unitPrice: number, quantity: number, unitOfMeasure: string): void

Add items to order.

placeOrder(): void

Place order.

requestPayment(amount: number, orderId: string): Promise

Request Payment.

Example

import {
  initialize,
  createDraftOrder,
  addItem,
  placeOrder,
  requestPayment,
} from 'react-native-cielolio';

const total = 1000;

const sku = 'sku-123';

const clientID = 'your-client-id';
const accessToken = 'your-access-token';
const orderId = 'your-invoice-code';
const productName = 'Product Name';
const productQuantity = 1;
const unitOfMeasure = 'UN';

initialize(clientID, accessToken)
  .then(() => {
    createDraftOrder(orderId);

    addItem(
      sku,
      productName,
      total,
      productQuantity,
      unitOfMeasure,
    );

    placeOrder();

    requestPayment(total, orderId)
      .then(res => {
        const paymentData = transformCieloPaymentResponse(JSON.parse(res));

        resolve(paymentData);
      })
      .catch(e => {
        const error = handleResponseError(e);

        reject(error || 'PAYMENT_ERROR');
      });
  })
  .catch((e) => {
    reject(e || 'INITIALIZE_ERROR');
  });

Contributing

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

License

MIT


Made with create-react-native-library

Package Sidebar

Install

npm i react-native-cielolio

Weekly Downloads

0

Version

1.3.7

License

MIT

Unpacked Size

31.6 kB

Total Files

26

Last publish

Collaborators

  • rodrigoangelovalentini