@spankchain-dev/spankpay-sdk
v0.0.10
Published
Library that enable to use Spankpay payments
Downloads
4
Readme
spankpay-sdk
Made with create-react-library
Install
npm install --save @spankchain-dev/spankpay-sdk
Usage
- Import the library
import spankpay from 'spankpay-sdk';
- Init the SDK
- it needs to pass the local window object
spankpay.init(window);
- We have two way to use
- As HTML Button
<button>
data-spankpay-key="test_quickstart_key" data-amount={amount} data-currency="USD"
data-callback-url='<https://spankpay.com>' data-accepted-currencies="BTC,ETH,LTC,USDC" data-description="Test Invoice
Button" data-metadata={metadata} data-premium-pct="0.05" data-on-payment="onSpankPayPayment"
data-fiat-enabled={fiatEnabled} data-guest-only={guestOnly} disabled={+amount <= 0} > I use HTML Button tag
<span role="img" aria-label="smile">😄</span>
</button>
- As JS function
javascript code
const showSpankPay = async (fiatEnabled: boolean, guestOnly: boolean) => {
await spankpay.show({
apiKey: 'test_quickstart_key',
amount,
acceptedCurrencies: ['BTC', 'ETH', 'LTC', 'USDC'],
currency: 'USD',
callbackUrl: '<https://spankpay.com'>,
description: 'Test Invoice Show',
metadata: {},
onPayment: function(payment: any) {
console.log(`Payment: ${payment.status}`, payment)
},
fiatEnabled: fiatEnabled || false,
guestOnly: guestOnly || false,
allowPartial: false,
premiumPct: 0.04,
redirectUrl: null as any as string,
})
}
HTML code
<button onClick={() => showSpankPay(fiatEnabled, guestOnly)} >
I use the JS show method <span role="img" aria-label="smile">❤️</span>
</button>