API Reference
Lightweight quick-reference for mypos-online-checkout. For full examples see Sample Code.
Configuration
Pass a config object to MyPOSClient or supply individual environment variables.
| Option | Type | Description |
|---|---|---|
storeId | string | Your merchant store ID |
storePassword | string | Store password from the merchant portal |
keyIndex | number | Key index (e.g., 1) |
privateKey | string | RSA private key (PEM format) |
publicKey | string | myPOS public key (PEM format) |
isSandbox | boolean | true for the sandbox environment |
Equivalent environment variables:
| Environment variable | Maps to |
|---|---|
MYPOS_STORE_ID | storeId |
MYPOS_STORE_PASSWORD | storePassword |
MYPOS_KEY_INDEX | keyIndex |
MYPOS_PRIVATE_KEY | privateKey |
MYPOS_PUBLIC_KEY | publicKey |
MYPOS_SANDBOX | isSandbox ('true' / 'false') |
MyPOSClient Methods
| Method | Parameters | Returns | Description |
|---|---|---|---|
generateCheckoutFields(opts) | CheckoutOptions | Promise<Record<string, string>> | Generate signed fields for hosted-page form submission |
validateNotification(params) | Record<string, string> | Promise<Result<NotificationData>> | Validate and parse a payment webhook |
getTransactionStatus(opts) | { orderId: string } | Promise<Result<TransactionStatus>> | Query transaction status by order ID |
refund(opts) | RefundOptions | Promise<Result<void>> | Issue full or partial refund |
reversal(opts) | ReversalOptions | Promise<Result<void>> | Void a transaction before settlement |
iaPurchase(opts) | IAPurchaseOptions | Promise<Result<IAPurchaseData>> | Charge a stored card token directly |
iaPreAuthorization(opts) | IAPreAuthOptions | Promise<Result<IAPreAuthData>> | Pre-authorize against a stored token |
preAuthorizationCompletion(opts) | PreAuthCompletionOptions | Promise<Result<void>> | Capture a pre-authorization |
checkoutUrl — string property on MyPOSClient instance; the target URL for hosted-page form POST.
Result Pattern
Most methods return a Result<T> discriminated union — check result.success before accessing data:
if (result.success) {
// result.data is typed T
} else {
// result.error contains the failure reason
console.error(result.error)
}
Only generateCheckoutFields() and validateNotification() can throw — see Error Types below.
Error Types
| Error type | Thrown by | Condition |
|---|---|---|
MyPOSConfigError | new MyPOSClient(), generateCheckoutFields() | Missing or invalid configuration |
MyPOSSignatureError | validateNotification() | Signature on incoming notification does not match |
MyPOSCartError | refund(), reversal(), cart-related methods | Cart construction or transaction operation failure |
React Sub-export (mypos-online-checkout/react)
PaymentForm Props
| Prop | Type | Required | Description |
|---|---|---|---|
checkoutFields | Record<string, string> | Yes | Signed fields from generateCheckoutFields() |
checkoutUrl | string | Yes | Form POST target URL (client.checkoutUrl) |
submitLabel | string | No | Button text (default: 'Pay') |
className | string | No | CSS class on the form element |
autoSubmit | boolean | No | Submit automatically on mount (default: false) |
usePaymentForm Return Type
| Property | Type | Description |
|---|---|---|
formRef | React.RefObject<HTMLFormElement> | Attach to a <form> element |
submit | () => void | Programmatically trigger form submission |
isSubmitting | boolean | true while the form is being submitted |