Home > Web Front-end > JS Tutorial > How to Integrate ZinariPay with Your Application Using the NPM Package

How to Integrate ZinariPay with Your Application Using the NPM Package

PHPz
Release: 2024-09-04 20:30:38
Original
441 people have browsed it

Integrating cryptocurrency payments into your web application has never been easier. ZinariPay offers a robust NPM package that allows developers to seamlessly add USDT and USDC payment functionalities. In this guide, we will walk you through the steps to integrate ZinariPay into your application using the NPM package.

Step 1: Installation

First, you'll need to install the ZinariPay package. This can be done using either npm or yarn, depending on your preference.

Using npm
To install using npm, run the following command in your terminal:

npm install zinari-pay
Copy after login

Using yarn
Alternatively, you can use yarn to install the package:

yarn add zinari-pay
Copy after login

Step 2: Configuration

Once the package is installed, you need to configure it for your application. The configuration involves creating an instance of ZinariPay with your specific settings.

Example Configuration
Here's a basic configuration example using vanilla JavaScript:

import ZinariPay from 'zinari-pay';

const zinariPay = new ZinariPay({
  appId: 'your-app-id',
  publicKey: 'your-public-key',
  log: process.env.NODE_ENV === 'development', /** Recommendation: Only 
use for development to avoid exposing sensitive data to end users
   */
});
Copy after login

You can get you appId and publicKey from you dashboard

Step 3: Initiate a Transaction

With your configuration set up, you can now initiate a transaction. This can be done using the initiateTransaction method.

Vanilla JavaScript Example
Here's how you would initiate a transaction:

import ZinariPay from 'zinari-pay';

const zinariPay = new ZinariPay({...})

const payWithCryptoButton = document.getElementById("your-payment-button");

payWithCryptoButton.addEventListener("click", () => {
  zinariPay.initiateTransaction({
    amount: 10000,
    notificationEmailAddress: 'users@email.com',
    details: {
      /** Add all the extra details you need here,
       * we  call your webhook url with all this data included */
    },
    onConfirmed: (transactionDetails) => {
      /** Do something when the transaction is confirmed */
    }
  });
});
Copy after login

React Example
If you're using React, you can integrate ZinariPay as follows:

import ZinariPay from 'zinari-pay';

const zinariPay = new ZinariPay({
  appId: 'your-app-id',
  publicKey: 'your-public-key',
  log: process.env.NODE_ENV === 'development',
});

const App = () => {
  const handleClick = useCallback(({price, email}) => {
    zinariPay.initiateTransaction({
      amount: price,
      notificationEmailAddress: email,
      onConfirmed: (transactionDetails) => {
        /** Do something when the transaction is confirmed */
      },
      details: {
        /** Add all the extra details you need here,
         * we  call your webhook url with all this data included */
      },
    });
  }, []);

  return <button onClick={handleClick}>
    Pay with Cryptocurrency
  </button>
}
Copy after login

Conclusion
Integrating ZinariPay into your application using the NPM package is straightforward and efficient. With support for USDT and USDC, encrypted transactions, and easy-to-use methods, ZinariPay is the perfect solution for adding cryptocurrency payments to your web application.
For more detailed information, visit the official documentation and start building today!

How to Integrate ZinariPay with Your Application Using the NPM Package
How to Integrate ZinariPay with Your Application Using the NPM Package
How to Integrate ZinariPay with Your Application Using the NPM Package
How to Integrate ZinariPay with Your Application Using the NPM Package
How to Integrate ZinariPay with Your Application Using the NPM Package

The above is the detailed content of How to Integrate ZinariPay with Your Application Using the NPM Package. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template