React widget
Supported React versions
This wrapper requires React ≥ 18.2.
Overview
<Payment> is a thin React wrapper around the <openhive-pay> custom element. It exposes the same features through camelCase props and React callback functions, with full TypeScript support.
It handles:
- Payment form rendering
- Payment request creation
- Success callbacks
For framework-agnostic usage, see Vanilla widget.
Installation
- npm
- yarn
- pnpm
npm install @openhive-eu/payment
yarn add @openhive-eu/payment
pnpm add @openhive-eu/payment
Styling
Import the stylesheet once in your application entry point (e.g. main.tsx, App.tsx):
import "@openhive-eu/payment/styles.css";
Then import the component wherever you need it:
import { Payment } from "@openhive-eu/payment/react";
Theming
The widget's appearance is controlled via CSS custom properties on the openhive-pay element:
openhive-pay {
--pay-primary: #7c3aed;
--pay-primary-foreground: #ffffff;
--pay-radius: 0.5rem;
}
See Custom element → Theming for the full variable reference.
Usage examples
Standard
Loading…
import "@openhive-eu/payment/styles.css"; // import once in your app entry
import { Payment } from "@openhive-eu/payment/react";
const MyPaymentPage = () => (
<Payment
token="pk_xxx"
defaultReference="ORDER-12345"
defaultAmount="5000"
productName="Abonnement Premium"
customerName="John Doe"
customerEmail="john.doe@example.com"
locale="en"
onRequestToPay={(requestToPay) => {
// Send the payment request to your backend to process the payment
console.log(requestToPay);
}}
/>
);
export default MyPaymentPage;
Modal / dialog
Loading…
import React, { useRef } from "react";
import "@openhive-eu/payment/styles.css"; // import once in your app entry
import { Payment } from "@openhive-eu/payment/react";
const MyPaymentModal = () => {
const dialogRef = useRef(null);
const handleRequestToPay = (requestToPay) => {
// Send the payment request to your backend to process the payment
console.log(requestToPay);
};
return (
<>
<button onClick={() => dialogRef.current.showModal()}>
Open Payment Modal
</button>
<dialog ref={dialogRef}>
<button onClick={() => dialogRef.current.close()}>Close</button>
<Payment
token="pk_xxx"
defaultReference="ORDER-12345"
defaultAmount="5000"
productName="Abonnement Premium"
customerName="John Doe"
customerEmail="john.doe@example.com"
locale="en"
onRequestToPay={handleRequestToPay}
/>
</dialog>
</>
);
};
export default MyPaymentModal;
Custom payment methods
Override the payment client to supply custom payment methods or bypass the default fetching logic. See Get payment methods API.
import "@openhive-eu/payment/styles.css"; // import once in your app entry
import { Payment } from "@openhive-eu/payment/react";
import type { PayClientInterface } from "@openhive-eu/payment";
const customPayClient: PayClientInterface = {
getPaymentMethods: async () => {
const response = await fetch("/api/payment-methods", {
headers: { Authorization: "Bearer <token>" },
});
if (!response.ok) throw new Error(`HTTP error! Status: ${response.status}`);
return response.json();
},
};
const MyControlledWidget = () => (
<Payment
token="pk_xxx"
defaultReference="ORDER-12345"
defaultAmount="5000"
productName="Abonnement Premium"
customerName="John Doe"
customerEmail="john.doe@example.com"
locale="en"
payClient={customPayClient}
onRequestToPay={(requestToPay) => {
console.log(requestToPay);
}}
/>
);
export default MyControlledWidget;
API
- Properties
- Callbacks
| Name | Type | Description |
|---|---|---|
token required | String | OpenHive token "pk_xxx" used to retrieve the payment methods configuration. |
defaultReference | String | Pre-fills the reference field. Links the request to an order (e.g., "ORDER-1234"). |
defaultAmount | String | Pre-fills the amount field. Value is in cents as a string (e.g., "5000" = €50.00). |
readOnlyAmount | Boolean | Locks the amount field to defaultAmount if true. |
customerName | String | Pre-fills the customer name. |
customerEmail | String | Pre-fills the customer e-mail. |
customerPhone | String | Pre-fills the customer phone number. |
locale | String | UI language. Supported values: "fr" (default), "en". Controls all labels, error messages, and success screen text. |
productName | String | Product label shown on the Stripe checkout page and customer receipts. Falls back to defaultReference if omitted. Has no effect on Fintecture. |
payClient | Object | Inject a custom payment client to override how payment methods are fetched. Useful for testing or custom backends. Must implement PayClientInterface. |
| Name | Signature | Description |
|---|---|---|
onRequestToPay | (requestToPay: RequestToPay) => void | Called when the user submits the payment form. Receives the RequestToPay payload. |
onClose | () => void | Called when the user closes the widget after a successful payment link submission. |
RequestToPay payload
| Field | Type | Description |
|---|---|---|
amount | Number | Amount in cents (e.g., 5000 = €50.00) |
currency | String | ISO 4217 currency code (e.g., "EUR") |
method | String | Payment method: "credit_card", "bank_transfer", "installments_3x" |
channel | String | Delivery channel: "email", "sms", "link" |
partner | String | Payment provider: "stripe", "fintecture" |
customer_contact | String | Customer email or phone number depending on the channel |
order_reference | String | Merchant order reference (e.g., "ORDER-1234") |
product_name | String | (optional) Product label forwarded to the backend |
metadata | Object | (optional) Key/value pairs of custom metadata |