@solidgate/react-sdk
v1.45.0
Published
Solidgate react sdk loader
Readme
Solidgate react-sdk
This repository is a React wrapper for the Solidgate Client Software Development Kit (SDK).
It supports rendering payment forms and resign forms, including custom container elements for Google Pay, Apple Pay, or alternative payment method (APM) buttons (PayPal, Pix, UPI, Pix QR, Bizum, Blik, MB WAY).
Check our
- Payment guide to understand business value better
- API Reference to find more examples of usage
Structure
Installation
Run the following command in your React project:
npm install --save @solidgate/react-sdkUsage
Payment form
Render a payment form component in your React project.
import React, { useRef } from 'react'
import { createRoot } from 'react-dom/client'
import Payment, { SdkMessage, MessageType, ClientSdkInstance} from "@solidgate/react-sdk"
/**
* Configuration, as it described here
* https://docs.solidgate.com/payments/integrate/payment-form/create-your-payment-form/
*/
const merchantData = {
merchant: '<<--YOUR MERCHANT ID-->>',
signature: '<<--YOUR SIGNATURE OF THE REQUEST-->>',
paymentIntent: '<<--YOUR PAYMENT INTENT-->>'
}
const App = () => {
const appleContainerRef = useRef(null)
const googleContainerRef = useRef(null)
const paypalContainerRef = useRef(null)
const mbwayContainerRef = useRef(null)
const pixQrContainerRef = useRef(null)
const handleOnError = (e: SdkMessage[MessageType.Error]) => {}
const handleOnFail = (e: SdkMessage[MessageType.Fail]) => {}
const handleOnMounted = (e: SdkMessage[MessageType.Mounted]) => {}
const handleOrderStatus = (e: SdkMessage[MessageType.OrderStatus]) => {}
const handleOnResize = (e: SdkMessage[MessageType.Resize]) => {}
const handleOnSuccess = (e: SdkMessage[MessageType.Success]) => {}
const handleOnSubmit = (e: SdkMessage[MessageType.Submit]) => {}
const handleOnInteraction = (e: SdkMessage[MessageType.Interaction]) => {}
const handleOnVerify = (e: SdkMessage[MessageType.Verify]) => {}
const handleOnProcessing = (e: SdkMessage[MessageType.Processing]) => {}
const handleOnRedirectMessage = (e: SdkMessage[MessageType.Redirect]) => {}
const handleOnCustomStylesAppended = (e: SdkMessage[MessageType.CustomStylesAppended]) => {}
const handleCard = (e: SdkMessage[MessageType.Card]) => {}
const handleOnReadyPaymentInstance = (form: ClientSdkInstance) => {
// eslint-disable-next-line no-console
console.log('form', form)
}
return (
<div>
<div ref={appleContainerRef} />
<div ref={paypalContainerRef} />
<div ref={mbwayContainerRef} />
<div ref={pixQrContainerRef} />
<Payment
googlePayButtonParams={googlePayButtonParams}
applePayButtonParams={applePayButtonParams}
paypalButtonParams={paypalButtonParams}
mbwayButtonParams={mbwayButtonParams}
pixQrButtonParams={pixQrButtonParams}
googlePayContainerRef={googleContainerRef}
applePayContainerRef={appleContainerRef}
paypalContainerRef={paypalContainerRef}
mbwayContainerRef={mbwayContainerRef}
pixQrContainerRef={pixQrContainerRef}
merchantData={merchantData}
styles={customFormStyles}
formParams={formParams}
onError={handleOnError}
onFail={handleOnFail}
onCard={handleCard}
onMounted={handleOnMounted}
onOrderStatus={handleOrderStatus}
onResize={handleOnResize}
onSuccess={handleOnSuccess}
onSubmit={handleOnSubmit}
onInteraction={handleOnInteraction}
onVerify={handleOnVerify}
onProcessing={handleOnProcessing}
onFormRedirect={handleOnRedirectMessage}
onCustomStylesAppended={handleOnCustomStylesAppended}
onReadyPaymentInstance={handleOnReadyPaymentInstance}
/>
<div ref={googleContainerRef} />
</div>
)
}
createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>
)
Wallet card type
Apple Pay and Google Pay report the payer's card funding type before the charge. Handle
onWalletCardType to inspect it and, optionally, pause the wallet flow with pauseUntil
while you call an update intent method (update, updateCheckout). The side effect has
a 25 s budget, measured from the moment the event fired.
import { useState } from 'react'
import Payment, {
ClientSdkInstance,
InitConfig,
WalletCardTypeCallback
} from '@solidgate/react-sdk'
const App = () => {
const [form, setForm] = useState<ClientSdkInstance | null>(null)
// required when you update the intent inside the event
const googlePayButtonParams: InitConfig['googlePayButtonParams'] = {
totalPriceStatus: 'TOTAL_PRICE_STATUS_ESTIMATED'
}
const handleWalletCardType: WalletCardTypeCallback = (data, pauseUntil) => {
if (data.card.type === 'unknown') {
return // no intent update - the wallet continues immediately
}
pauseUntil(async () => {
await form?.update({ partialIntent: intentFor(data.card.type) })
})
}
return (
<Payment
merchantData={merchantData}
googlePayButtonParams={googlePayButtonParams}
onWalletCardType={handleWalletCardType}
onReadyPaymentInstance={setForm}
/>
)
}Checkout updates
Change the checkout line items, discounts or subscription data after the form is mounted
with updateCheckout.
The invoice preview itself arrives through the onInvoicePreview callback. It is sent by
the SDK during the form initialization process.
import { useState } from 'react'
import Payment, {
ClientSdkInstance,
InvoicePreviewMessage,
UpdateCheckoutConfig
} from '@solidgate/react-sdk'
const App = () => {
const [form, setForm] = useState<ClientSdkInstance | null>(null)
const handleInvoicePreview = (e: InvoicePreviewMessage) => {
console.log(e.invoicePreview.total, e.invoicePreview.currency)
}
const changeQuantity = async (quantity: number) => {
const config: UpdateCheckoutConfig = {
lineItems: [{ productPriceId: 'price_id', quantity }]
}
await form!.updateCheckout(config)
}
return (
<Payment
merchantData={merchantData}
onInvoicePreview={handleInvoicePreview}
onReadyPaymentInstance={setForm}
/>
)
}Resign form
Render a resign payment form component in your React project.
const resignRequest = {
merchant: '<<--YOUR MERCHANT ID-->>',
signature: '<<--YOUR SIGNATURE OF THE REQUEST-->>',
resignIntent: '<<--YOUR RESIGN INTENT-->>'
}
function App () {
const handleOnError = (e: SdkMessage[MessageType.Error]) => {}
const handleOnFail = (e: SdkMessage[MessageType.Fail]) => {}
const handleOnMounted = (e: SdkMessage[MessageType.Mounted]) => {}
const handleOrderStatus = (e: SdkMessage[MessageType.OrderStatus]) => {}
const handleOnResize = (e: SdkMessage[MessageType.Resize]) => {}
const handleOnSuccess = (e: SdkMessage[MessageType.Success]) => {}
const handleOnSubmit = (e: SdkMessage[MessageType.Submit]) => {}
const handleOnInteraction = (e: SdkMessage[MessageType.Interaction]) => {}
const handleOnVerify = (e: SdkMessage[MessageType.Verify]) => {}
const handleOnProcessing = (e: SdkMessage[MessageType.Processing]) => {}
const handleOnRedirectMessage = (e: SdkMessage[MessageType.Redirect]) => {}
const handleOnCustomStylesAppended = (e: SdkMessage[MessageType.CustomStylesAppended]) => {}
const handleOnReadyResignInstance = (form: ClientSdkInstance) => {
// eslint-disable-next-line no-console
console.log('resign form', form)
}
return (
<Resign
resignRequest={resignRequest}
appearance={appearanceConfig}
styles={customStyles}
onError={handleOnError}
onFail={handleOnFail}
onMounted={handleOnMounted}
onOrderStatus={handleOrderStatus}
onResize={handleOnResize}
onSuccess={handleOnSuccess}
onSubmit={handleOnSubmit}
onInteraction={handleOnInteraction}
onVerify={handleOnVerify}
onProcessing={handleOnProcessing}
onFormRedirect={handleOnRedirectMessage}
onCustomStylesAppended={handleOnCustomStylesAppended}
onReadyResignInstance={handleOnReadyResignInstance}
/>
)
}Development server
cd playgroundnpm inpm run startNavigateto http://localhost:3000/
Build
Run npm run build to build the project.
The build artifacts will be stored in the dist/ directory.
Looking for help? Contact us Want to contribute? Submit a pull request
