>  기사  >  웹 프론트엔드  >  NPM 패키지를 사용하여 ZinariPay를 애플리케이션과 통합하는 방법

NPM 패키지를 사용하여 ZinariPay를 애플리케이션과 통합하는 방법

PHPz
PHPz원래의
2024-09-04 20:30:38367검색

암호화폐 결제를 웹 애플리케이션에 통합하는 것이 그 어느 때보다 쉬워졌습니다. ZinariPay는 개발자가 USDT 및 USDC 결제 기능을 원활하게 추가할 수 있는 강력한 NPM 패키지를 제공합니다. 이 가이드에서는 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를 얻을 수 있습니다

3단계: 거래 시작

구성이 설정되면 이제 거래를 시작할 수 있습니다. 이는itirateTransaction 메소드를 사용하여 수행할 수 있습니다.

바닐라 자바스크립트 예시
거래를 시작하는 방법은 다음과 같습니다.

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를 애플리케이션에 통합하는 것은 간단하고 효율적입니다. USDT 및 USDC 지원, 암호화된 거래, 사용하기 쉬운 방법을 갖춘 ZinariPay는 웹 애플리케이션에 암호화폐 결제를 추가하기 위한 완벽한 솔루션입니다.
자세한 내용을 보려면 공식 문서를 방문하여 지금 바로 구축을 시작하세요!

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 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.