Payment SDK
The Payment SDK provides methods to generate secure, embeddable payment URLs for in-app purchases on the GetJar platform.
Initialization
import { Configuration, Payment } from '@eightpointio/getjar-iap-sdk';
const config = new Configuration({
basePath: 'https://sdk-new.getjar.com',
baseOptions: {
headers: {
'x-api-key': 'your-api-key-here'
}
}
});
const paymentClient = new Payment(config);
Methods
generateEmbedUrl
Generates a secure, time-limited URL for embedding payment flows in your application. This URL allows users to complete purchases through an iframe or webview.
Parameters:
appId(string): Application IDpayload(GenerateEmbedUrlRequest): Payment request configurationuserId(string): User ID making the purchaseproductId(string): Product ID to purchasecurrency(string, optional): Currency code (e.g., 'USD', 'EUR')embedBaseUrl(string, optional): Custom base URL for the embedded payment page
Returns: Promise<EmbedUrlResponse>
const embedData = await paymentClient.generateEmbedUrl('app-456', {
userId: 'user-123',
productId: 'product-789',
currency: 'USD'
});
console.log(embedData.embedUrl);
console.log(embedData.token);
console.log(embedData.expiresAt);
console.log(embedData.product);
Usage Example
const embedData = await paymentClient.generateEmbedUrl('app-456', {
userId: 'user-123',
productId: 'premium-pack-001',
currency: 'USD',
embedBaseUrl: 'https://payments.myapp.com'
});
const iframe = document.createElement('iframe');
iframe.src = embedData.embedUrl;
iframe.width = '100%';
iframe.height = '600px';
document.body.appendChild(iframe);
console.log(`Payment expires at: ${embedData.expiresAt}`);
console.log(`Product: ${embedData.product.name} - $${embedData.product.amount}`);
Types
GenerateEmbedUrlRequest
interface GenerateEmbedUrlRequest {
userId: string;
productId: string;
currency?: string;
embedBaseUrl?: string;
}
EmbedUrlResponse
interface EmbedUrlResponse {
embedUrl: string;
token: string;
expiresAt: string;
product: {
productId: string;
name: string;
amount: number;
currency: string;
};
}
Security
- The generated embed URL is time-limited and expires at the timestamp provided in
expiresAt - Each URL includes a unique token that cannot be reused
- URLs are scoped to specific user, product, and app combinations
- Embed URLs should be generated server-side to protect your API key
Best Practices
- Generate URLs on demand - Create the embed URL immediately before displaying the payment flow to minimize exposure time
- Handle expiration - Check the
expiresAttimestamp and regenerate URLs if needed - Secure your API key - Never expose your API key in client-side code
- Use HTTPS - Always serve payment pages over HTTPS
- Validate callbacks - Verify payment completion through your backend before granting purchased items