首頁 > web前端 > js教程 > 主體

如何使用 NPM 套件將 ZinariPay 與您的應用程式集成

PHPz
發布: 2024-09-04 20:30:38
原創
371 人瀏覽過

將加密貨幣支付整合到您的網路應用程式中從未如此簡單。 ZinariPay 提供了強大的 NPM 包,允許開發人員無縫添加 USDT 和 USDC 支付功能。在本指南中,我們將引導您完成使用 NPM 套件將 ZinariPay 整合到您的應用程式中的步驟。

第1步:安裝

首先,您需要安裝 ZinariPay 軟體套件。這可以使用npm或yarn來完成,具體取決於您的喜好。

使用 npm
若要使用 npm 安裝,請在終端機中執行以下命令:

npm install zinari-pay
登入後複製

使用紗線
或者,您可以使用yarn來安裝套件:

yarn add zinari-pay
登入後複製

第2步:配置

安裝套件後,您需要為您的應用程式配置它。配置涉及使用您的特定設定建立 ZinariPay 實例。

設定範例
這是使用普通 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
   */
});
登入後複製

您可以從儀表板取得 appIdpublicKey

第三步:發起交易

配置完成後,您現在可以啟動交易。這可以使用 initiateTransaction 方法來完成。

原生 JavaScript 範例
以下是啟動交易的方式:

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 */
    }
  });
});
登入後複製

反應範例
如果您使用 React,您可以如下整合 ZinariPay

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>
}
登入後複製

結論
使用 NPM 套件將 ZinariPay 整合到您的應用程式中既簡單又高效。 ZinariPay 支援 USDT 和 USDC、加密交易和易於使用的方法,是向您的 Web 應用程式添加加密貨幣支付的完美解決方案。
如需更多詳細信息,請訪問官方文件並立即開始構建!

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

以上是如何使用 NPM 套件將 ZinariPay 與您的應用程式集成的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:dev.to
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!