@vti3/pay
v0.0.3
Published
```typescript import type { Config } from '@vti3/pay'
Readme
VTI3 turquoipay SDK
Config
import type { Config } from '@vti3/pay'
const config: Config = {
secretKey: '{{secretKey}}', // optional
turquoipayURL: '{{turquoipayURL}}', // optional
serverURL: '{{turquoipayURL}}', // optional
indiappId: '{{indiappId}}', // optional
}Create Checkout Transaction
Create a Checkout Transaction
import { createCheckout, CurrencySymbol } from '@vti3/pay'
import type { Checkout } from '@vti3/pay'
const tx: Checkout = await createCheckout(config, 100, CurrencySymbol.USD)Create a Checkout URL
import { createCheckoutURL, CurrencySymbol } from '@vti3/pay'
import type { Checkout } from '@vti3/pay'
const { tx, url } = await createCheckoutURL(config, 100, CurrencySymbol.USD)
window.open(url); // or iframeCreate a Subscription Checkout
import { createSubscriptionCheckout } from '@vti3/pay'
import type { Checkout } from '@vti3/pay'
const { tx_id, url } = await createSubscriptionCheckout(config, '{{success_redirect_url}}')
window.open(checkout_url); // or iframePolling Payment Status
If we use iframe mode, we can use this method to wait for the transaction to be completed.
import { pollingCheckoutStatus, TimeoutError } from '@vti3/pay'
try {
await pollingCheckoutStatus(config, '{{tx.tx_id}}')
} catch (error) {
if (error instanceof TimeoutError) {
// timeout
}
}Verify Webhook Request
import { verifyWebhookSignature } from '@vti3/pay'
const app = new Hono()
app.post('/webhook', async (c) => {
const secret = process.env.WEBHOOK_SECRET || ''
const signature = c.req.header('X-Signature') || ''
const buf = await c.req.raw.arrayBuffer()
const rawBody = new Uint8Array(buf)
const valid = verifyWebhookSignature(config, rawBody, signature)
})