swirepay-google-pay-sdk
v1.0.0
Published
A JavaScript SDK for integrating Swirepay Google Pay in React applications
Maintainers
Readme
SwirePay Google Pay SDK
A React-compatible JavaScript SDK for integrating Google Pay into your web applications.
Installation
npm install swirepay-google-pay-sdkUsage
Basic Usage with React Component
import { GooglePayButton } from 'swirepay-google-pay-sdk';
function App() {
const config = {
merchantId: 'YOUR_MERCHANT_ID',
merchantName: 'Your Store Name',
environment: 'TEST', // or 'PRODUCTION'
paymentGatewayId: 'YOUR_PAYMENT_GATEWAY_ID' // optional
};
const handleSuccess = (paymentData) => {
console.log('Payment successful:', paymentData);
// Handle successful payment
};
const handleError = (error) => {
console.error('Payment failed:', error);
// Handle payment error
};
return (
<GooglePayButton
config={config}
onSuccess={handleSuccess}
onError={handleError}
buttonType="buy"
buttonColor="default"
buttonHeight={40}
/>
);
}Using the SDK Directly
import GooglePaySDK from 'swirepay-google-pay-sdk';
const config = {
merchantId: 'YOUR_MERCHANT_ID',
merchantName: 'Your Store Name',
environment: 'TEST', // or 'PRODUCTION'
paymentGatewayId: 'YOUR_PAYMENT_GATEWAY_ID' // optional
};
const sdk = new GooglePaySDK(config);
// Check if Google Pay is available
const isAvailable = await sdk.isGooglePayAvailable();
if (isAvailable) {
try {
// Request payment
const paymentData = await sdk.requestPayment(100, 'USD');
console.log('Payment successful:', paymentData);
} catch (error) {
console.error('Payment failed:', error);
}
}Configuration Options
GooglePayConfig
| Option | Type | Required | Description | |--------|------|----------|-------------| | merchantId | string | Yes | Your Google Pay merchant ID | | merchantName | string | Yes | Your store/business name | | environment | 'TEST' | 'PRODUCTION' | Yes | The environment to use | | paymentGatewayId | string | No | Your payment gateway ID |
GooglePayButton Props
| Prop | Type | Required | Default | Description | |------|------|----------|---------|-------------| | config | GooglePayConfig | Yes | - | Configuration object | | onSuccess | function | Yes | - | Callback for successful payment | | onError | function | Yes | - | Callback for payment errors | | buttonType | 'buy' | 'checkout' | 'order' | 'subscribe' | No | 'buy' | Type of button to display | | buttonColor | 'default' | 'black' | 'white' | No | 'default' | Button color | | buttonHeight | number | No | 40 | Button height in pixels |
Browser Support
The SDK supports all modern browsers that are compatible with Google Pay.
License
MIT
