sawfish-payment-widget
v1.0.12-dev
Published
A payment widget for processing payments through the Sawfish API
Downloads
38
Readme
Sawfish Payments
A payment widget for processing payments through the Sawfish API.
Installation
To install the package, run:
npm install sawfish-payment-widgetUsage
PaymentForm Component
The PaymentForm component is used to process payments through the Sawfish API.
Props
environment(optional): The environment to use. Can be "production", "staging", or "dev". Default is "dev".endpoint: The GraphQL endpoint. this plugin make use of GraphQL to communicate with the Sawfish API.apiToken: The API token.clientId: The client ID.amount: The payment amount.contact: The contact information.metadata(optional): Additional data to send to the server.onPaymentSuccess(optional): Callback function to handle successful payments.onPaymentError(optional): Callback function to handle payment errors.
Example ReactJs Component
import React from "react";
import { PaymentForm } from "sawfish-payment-widget";
const App = () => {
const handlePaymentSuccess = (response: any) => {
console.log("Payment successful:", response);
};
const handlePaymentError = (error: any) => {
console.error("Payment error:", error);
};
return (
<PaymentForm
environment="staging"
endpoint="https://api.sawfish.2mm.io//graphql"
apiToken="your-api-token"
clientId="your-client-id"
amount={100}
contact={{
first_name: "",
last_name: "",
email: "",
description: "", // more like description of the payment
reference_no: "", // more like an internal reference number like invoice number
address_line1: "",
city: "",
state: "",
zip: "",
country: "",
}}
onPaymentSuccess={handlePaymentSuccess}
onPaymentError={handlePaymentError}
metadata={{
// any additional data you want to send to the server
// currently used to send the invoice id
invoice_id: "1234",
}}
/>
);
};
export default App;Example Payment Response
{
"amount": 604.72,
"application_fee_amount": 11.08,
"payment_gateway_fee": 11.08,
"payment_at": "2025-03-04 00:00:00",
"status": {
"name": "payment_initiated"
},
"uuid": "...-...-...-...-..",
}Development
To start the development server, run:
npm run devTo build the package, run:
npm run buildTo clean the build artifacts, run:
npm run cleanPublish
To publish the package, run:
npm run publishLicense
The Sprint Sawfish payments plugin is open-sourced software licensed under the MIT license.
