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.

OptionTypeDescription
storeIdstringYour merchant store ID
storePasswordstringStore password from the merchant portal
keyIndexnumberKey index (e.g., 1)
privateKeystringRSA private key (PEM format)
publicKeystringmyPOS public key (PEM format)
isSandboxbooleantrue for the sandbox environment

Equivalent environment variables:

Environment variableMaps to
MYPOS_STORE_IDstoreId
MYPOS_STORE_PASSWORDstorePassword
MYPOS_KEY_INDEXkeyIndex
MYPOS_PRIVATE_KEYprivateKey
MYPOS_PUBLIC_KEYpublicKey
MYPOS_SANDBOXisSandbox ('true' / 'false')

MyPOSClient Methods

MethodParametersReturnsDescription
generateCheckoutFields(opts)CheckoutOptionsPromise<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)RefundOptionsPromise<Result<void>>Issue full or partial refund
reversal(opts)ReversalOptionsPromise<Result<void>>Void a transaction before settlement
iaPurchase(opts)IAPurchaseOptionsPromise<Result<IAPurchaseData>>Charge a stored card token directly
iaPreAuthorization(opts)IAPreAuthOptionsPromise<Result<IAPreAuthData>>Pre-authorize against a stored token
preAuthorizationCompletion(opts)PreAuthCompletionOptionsPromise<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 typeThrown byCondition
MyPOSConfigErrornew MyPOSClient(), generateCheckoutFields()Missing or invalid configuration
MyPOSSignatureErrorvalidateNotification()Signature on incoming notification does not match
MyPOSCartErrorrefund(), reversal(), cart-related methodsCart construction or transaction operation failure

React Sub-export (mypos-online-checkout/react)

PaymentForm Props

PropTypeRequiredDescription
checkoutFieldsRecord<string, string>YesSigned fields from generateCheckoutFields()
checkoutUrlstringYesForm POST target URL (client.checkoutUrl)
submitLabelstringNoButton text (default: 'Pay')
classNamestringNoCSS class on the form element
autoSubmitbooleanNoSubmit automatically on mount (default: false)

usePaymentForm Return Type

PropertyTypeDescription
formRefReact.RefObject<HTMLFormElement>Attach to a <form> element
submit() => voidProgrammatically trigger form submission
isSubmittingbooleantrue while the form is being submitted