Developers Forum for XinFin XDC Network

Cover image for Accept XDC and XRC20 based tokens as payment methods in website or web application with Ease
jurjees ahamed
jurjees ahamed

Posted on • Updated on

Accept XDC and XRC20 based tokens as payment methods in website or web application with Ease

Hello XDC community,today i am come up with the solution to accept XDC and XRC20 based tokens as payment method any website like ecommerce,hotel booking,online payment,... etc with the simple steps.

Get your payment instantly in your wallet address.

This Pakage Support Web3modal Walletconnect

For Easy Integration checkout below npm package.
https://www.npmjs.com/package/pli-pay

Now the package currently supports XDC and PLI token only. In coming up days more tokens will be supported.

Check out the list of steps to integrate payment method:

Create sample react app by following command:

npx create-react-app sample-app
Enter fullscreen mode Exit fullscreen mode

Install neccessary Dependencies

npm install pli-pay --save
Enter fullscreen mode Exit fullscreen mode

Just install one package it takes care all the dependencies

import Paypli from 'pli-pay'
import 'pli-pay/dist/index.css'

function App() {
  return <Paypli
    chainId={50}
    paymethod={"XDC"}
    fiatcurrency={"usd"}
    style={`apple_pay_button apple_pay_button_black`}
    receiverAddress={"0x117c691d76c1d9c68e3709a87f7d496097f2b56f"}
    amount={"1"}
    onSuccess={(data) => console.log("onSuccess", data)}
    onFailure={(data) => console.log("onFailure", data)}
    onError={(data) => console.log("onError", data)}
  />
}

Enter fullscreen mode Exit fullscreen mode

Use Paypli component wherever you want in your application.This package supports currency conversion to convert fiat currency to crypto currency.

No need to do calculate any conversion in your application.Just pass amount,paymethod and fiatcurrency.

Receiver address must be valid XDC Address but replace xdc to 0x in your application.

You can easily capture the return response for onSuccess, onFailure and onError functions.

You can use own custom style class for payment button

*Only coingecko support fiat currencies accepted for conversion.
*

Success Response Object :

{
    "hash": "0x6ff4af9d1ed0545f43de7827360385b03b1d8105fa061d96a37e0e361499728f",
    "success": true,
    "fiatcurrency": "usd",
    "amount": "1",
    "paymethod": "XDC",
    "receiverAddress": "0x117c691d76c1d9c68e3709a87f7d496097f2b56f"
}
Enter fullscreen mode Exit fullscreen mode

Failure Response Object :

{
    "hash": "0x6ff4af9d1ed0545f43de7827360385b03b1d8105fa061d96a37e0e361499728f",
    "success": false,
}
Enter fullscreen mode Exit fullscreen mode

You can store it in your application Database for future reference.

Happy Coding!!!

Discussion (2)

Collapse
boris_xdc_b7b9a25940bb63d profile image
Boris XDC

Thank you for sharing! Keep up the Coding!

Collapse
jurjeesahamed profile image
jurjees ahamed Author

sure