GithubHelp home page GithubHelp logo

yosle / tropipayjs Goto Github PK

View Code? Open in Web Editor NEW
12.0 4.0 2.0 1.27 MB

Typescript/Javascript SDK for Tropipay API

License: MIT License

JavaScript 1.36% TypeScript 98.64%
tropipay api ecomerce expressjs gateway javascript-library nextjs nodejs payment-gateway payments

tropipayjs's Introduction

TropipayJS - Typescript/Javascript SDK for Tropipay Payments API

NodeJS TypeScript JavaScript Next JS RollupJS

Explore the TropipayJS Documentation

TropiPay is an electronic wallet that allows you to execute the most common financial operations of the day to day. This is SDK for Typescript and Javacript that helps you build integrations with the Tropipay platform in an easier way. Can save you a lot of time and effort implementing all the API features. You can use this library with CommonJS system (node + express) or ES6 module system (NextJS).

Table of Contents

About the project

This library is a community effort. Tropipay may make some changes on the API specification. Use the test environment to make sure everything is working as expected.

Note: This library is provided as-is and serves as a client for the Tropipay API. While every effort has been made to ensure the accuracy and reliability of the library, Tropipay is solely responsible for maintaining and updating the API documentation.

The library is intended to simplify the integration process with Tropipay's services, but it is essential to consult the official documentation to ensure that you are using the API correctly and taking into account any recent changes or updates made by Tropipay.

Getting started

You can use npm or yarn to install this package:

npm install @yosle/tropipayjs

or

yarn add @yosle/tropipayjs

Setting up your app credentials

alt alt

In order to use the Tropipay API you'll need a client ID and a client secret. Sign up with your Tropipay account, go to the App Menu->Applications and credentials. You'll be asked to enter a confirmation code (use 123456 in the test enviroment). Make sure you test everything in the test environment first before using your real account. Create an app and configure the client id an client secret for the app.

Usage

The Tropipay instance, allows you to access all the method available in the API. This Object is meant to be used only in server side. Do not use the Tropipay object on the client side (browser). This would expose your app credentials (the client secret of your account). You can create an endpoint at your back-end using express and consume it in your front-end, or use SSR if you're using NextJS.

CommonJS

const { Tropipay } = require("@yosle/tropipayjs");

ES6

import { Tropipay } from "@yosle/tropipayjs";

Initialize the Tropipay class

You can instantiate the Tropipay class passing the client Id ,client secret and optionally the serverMode parameter, if no serverMode is provided, Development will be used as default. Make sure you use the test environment credentials when serverMode is on Development.

// test environment server tropipay-dev.herokuapp.com
const config = {
    clientId: process.env.TROPIPAY_CLIENT_ID,
    clientSecret: process.env.TROPIPAY_CLIENT_SECRET
    serverMode: 'Development' // it will be used as default if omited
}
const tpp = new Tropipay(config)

To use your live credentials (real account) you must explicity set serverMode to Production.

//real account credentials
const config = {
  clientId: process.env.TROPIPAY_CLIENT_ID,
  clientSecret: process.env.TROPIPAY_CLIENT_SECRET,
  serverMode: "Production", //live account
};
const tpp = new Tropipay(config);

Generating a Payment Link

/*
 * Example Payload
 */
const payload = {
  reference: "my-paylink-1",
  concept: "Bicycle",
  favorite: "true",
  amount: 3000,
  currency: "EUR",
  description: "Two wheels",
  singleUse: "true",
  reasonId: 4,
  expirationDays: 1,
  lang: "es",
  urlSuccess: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
  urlFailed: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
  urlNotification: "https://webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
  serviceDate: "2021-08-20",
  client: {
    name: "John",
    lastName: "McClane",
    address: "Ave. Guadí 232, Barcelona, Barcelona",
    phone: "+34645553333",
    email: "[email protected]",
    countryId: 1,
    termsAndConditions: "true",
  },
  directPayment: "true",
};
// Use inside an async function
const paylink = await tpp.paymentCards.create(payload);
console.log(paylink.shortUrl);

For more examples, please refer to the Documentation

Contributing

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature)
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

You can also make a small donation to the author of the library.

License

Distributed under the MIT License. See LICENSE.txt for more information.

tropipayjs's People

Contributors

dependabot[bot] avatar yosle avatar yosletpp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

jkamiphi linkinln

tropipayjs's Issues

Error : invalid credentials

Hola estoy presentado este errorl al integrar el plugin con mi servidor supongo que sea algo respecto al token de acceso estoy siguendo las intrucciones como se podria solucionar el pluging no maneja eso automaticamente esto sucede al generar el link del pago
Imagen de WhatsApp 2024-05-20 a las 08 44 24_3911876a

Error al configurar el parametro expirationDays

Al crear un paymentCard con el método create en el payload que se envía ,he probado mandar el valor 2 (number) , '2' (string) ya que necesito que el link generado tenga un tiempo de vida determinado. Al revisar esa transacción buscándola en el resultado del método list de la misma clase, se ve el campo expirationDays en 0 , lo mismo me pasa con el campo serviceDate (Esto me pasa en ambiente dev, no lo he probado en ambiente de producción , les aconsejo revisarlo también)

Buenas a la hora de crear un link de pago me sale este error en el servidor

Error del servidor:
\node_modules@yosle\tropipayjs\index.js:48
return new TropipayJSException(errorMessage, axiosResponse.status, axiosResponse.data.error);
^
TropipayJSException [Error]: Invalid Parameter
at handleExceptions (D:\Proyectos\Proyectos_VSC\Node.js\server-baraife\node_modules@yosle\tropipayjs\index.js:48:28)
at PaymentCard.create (D:\Proyectos\Proyectos_VSC\Node.js\server-baraife\node_modules@yosle\tropipayjs\index.js:234:19) at processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 400,
error: {
type: 'VALIDATION_ERROR',
code: 'INVALID_PARAM',
message: 'Invalid Parameter',
details: [ [Object] ],
i18n: 'Parámetros inválidos'
}
}

Invalid Parameter

Buenas se puede mejorar este error

{
"error": "Invalid Parameter"
}

{
"payload": {
"reference": "pago",
"concept": "baraife",
"favorite": "true",
"amount": "2000",
"currency": "EUR",
"description": "Son productos",
"singleUse": "true",
"reasonId": 10,
"expirationDays": 1,
"lang": "es",
"urlSuccess": "https: //webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
"urlFailed": "https: //webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
"urlNotification": "https: //webhook.site/680826a5-199e-4455-babc-f47b7f26ee7e",
"serviceDate": "2024-05-08",
"directPayment": "true"
}
}

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.