Documentation Index
Fetch the complete documentation index at: https://docs.grain.inc/llms.txt
Use this file to discover all available pages before exploring further.
User Closes the Modal
When a customer closes the payment modal without completing, the SDK throws aCubePayClosedError. This is not a failure — it means the user chose to cancel.
Always check for
CubePayClosedError before treating a thrown error as a failure. This is the most common “error” you will encounter.Client-Side Errors
| Error | Cause | Resolution |
|---|---|---|
CubePayClosedError | User closed the payment modal | Let the user retry when ready |
| Missing merchant ID | NEXT_PUBLIC_CUBEPAY_MERCHANT_ID not set | Add the environment variable |
| Missing container | #cubepay-sdk-root element not in DOM | Add the mount point to your layout |
| Script load failure | SDK bundle not found at /vendor/cubist-pay-client-sdk.umd.js | Verify the file exists in your public/vendor/ directory |
| SDK initialization failure | window.CubePaySDK not available after script load | Check for script loading errors in the browser console |
Server-Side Errors
Session Creation Errors
| HTTP Status | Cause | Resolution |
|---|---|---|
400 | Invalid request body or missing fields | Check that amount is a positive number and currency is provided |
400 | Amount is not a valid number, is zero, or negative | Validate the amount before sending |
401 | Invalid or missing API key | Verify CUBEPAY_API_KEY in your environment |
500 | Internal server error | Retry with exponential backoff |
502 | Upstream API unavailable | The payment service is temporarily unreachable — retry shortly |
Handling Server Errors
Webhook Error Handling
Design your webhook handler to be idempotent and always return200: