MethodsPayment Method | Fire Snippets Docs
Payment Method
Processes payments via Stripe when a button is clicked.
payment(snippetId, variables)
Description
Processes payments by creating a payment link via your backend and redirects the user to the payment page when a button is clicked. It can include additional metadata in the payment request.
Method Signature
payment(snippetId, variables)
Parameters
- snippetId: (string) The ID of the payment snippet configuration.
- variables: (Array) An array of objects containing variable names and values to include as metadata in the payment request.
Returns
- Promise: Resolves with the payment link URL upon successful creation, or rejects with an error.
Usage Example
// Initialize FireSnippets
const fireSnippets = new FireSnippets('your-api-key');
// Define variables to include in payment metadata
const variables = [
{ name: 'customerId', value: 'cust_123' },
{ name: 'orderId', value: 'order_456' }
];
// Call the payment method
fireSnippets.payment('your-payment-snippet-id', variables)
.then(paymentLink => {
// Payment link created and user is redirected
console.log('Redirecting to payment link:', paymentLink);
})
.catch(error => {
// Handle errors
console.error('Payment error:', error);
});
HTML Elements Required
Ensure your HTML includes the following element with the ID specified in your snippet configuration:
<button id="payment-button">Make Payment</button>
Note: The user is automatically redirected to the payment page upon successful creation of the payment link.
Was this helpful?