{
  "openapi": "3.1.0",
  "info": {
    "title": "Royal Pay API",
    "version": "1.0.0",
    "description": "Hosted-checkout pay-ins with signed webhooks, and payouts. Docs: https://docs.royalpe.site/ \u00b7 For LLMs: https://docs.royalpe.site/llms.txt"
  },
  "servers": [
    {
      "url": "https://api.royalpe.site"
    }
  ],
  "externalDocs": {
    "url": "https://docs.royalpe.site/"
  },
  "paths": {
    "/merchant/initial-payment": {
      "post": {
        "operationId": "createPayIn",
        "summary": "Create a pay-in",
        "description": "Creates a pay-in and returns the hosted checkout link. Idempotent on orderId: the same details return the same pay-in; different details answer 409.",
        "externalDocs": {
          "url": "https://docs.royalpe.site/payins/create"
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "accessKey",
                  "secretKey",
                  "amount",
                  "orderId",
                  "userId",
                  "webhookUrl",
                  "redirectUrl"
                ],
                "properties": {
                  "accessKey": {
                    "type": "string",
                    "description": "Your access key."
                  },
                  "secretKey": {
                    "type": "string",
                    "description": "Your secret key."
                  },
                  "amount": {
                    "type": "number",
                    "exclusiveMinimum": 0,
                    "multipleOf": 0.01,
                    "description": "Rupees.",
                    "example": 500
                  },
                  "orderId": {
                    "type": "string",
                    "maxLength": 2048,
                    "example": "ORDER-10045"
                  },
                  "userId": {
                    "type": "string",
                    "maxLength": 2048,
                    "example": "USER-881"
                  },
                  "webhookUrl": {
                    "type": "string",
                    "format": "uri",
                    "pattern": "^https://",
                    "example": "https://shop.example.com/royalpay/webhook"
                  },
                  "redirectUrl": {
                    "type": "string",
                    "format": "uri",
                    "pattern": "^https://",
                    "example": "https://shop.example.com/deposit/done"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Payment URL generated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "message": {
                      "const": "Payment URL generated successfully"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "paymentUrl": {
                          "type": "string",
                          "format": "uri",
                          "example": "https://pay.royalpe.site/gateway/Xq3v9KfP2mZt7LbR8sWn4cYd1HgJ6aEu0oTi5kNp"
                        },
                        "orderId": {
                          "type": "string"
                        },
                        "transactionId": {
                          "type": "string",
                          "example": "RP-7f3a9c21d84e5b02"
                        },
                        "amount": {
                          "type": "number"
                        },
                        "status": {
                          "const": "progress"
                        },
                        "userId": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Missing or invalid field",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Invalid access key or secret key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "orderId reused with different details, or payments paused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Body is not JSON",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/merchant/transaction-status": {
      "get": {
        "operationId": "getPayInStatus",
        "summary": "Pay-in status",
        "externalDocs": {
          "url": "https://docs.royalpe.site/payins/status"
        },
        "parameters": [
          {
            "name": "accessKey",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "secretKey",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "transactionId",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Transaction status retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "message": {
                      "const": "Transaction status retrieved successfully"
                    },
                    "data": {
                      "$ref": "#/components/schemas/PayIn"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Missing parameter",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Invalid access key or secret key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Transaction does not belong to this merchant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Transaction not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/merchant/manual-utr-upload": {
      "post": {
        "operationId": "submitUtr",
        "summary": "Submit a UTR",
        "externalDocs": {
          "url": "https://docs.royalpe.site/payins/manual-utr"
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "accessKey",
                  "secretKey",
                  "transactionId",
                  "utrNumber"
                ],
                "properties": {
                  "accessKey": {
                    "type": "string",
                    "description": "Your access key."
                  },
                  "secretKey": {
                    "type": "string",
                    "description": "Your secret key."
                  },
                  "transactionId": {
                    "type": "string"
                  },
                  "utrNumber": {
                    "type": "string",
                    "maxLength": 128,
                    "example": "531512345678"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "UTR number updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "message": {
                      "const": "UTR number updated successfully"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "transactionId": {
                          "type": "string"
                        },
                        "status": {
                          "const": "pending"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Already approved, UTR already used, or invalid",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Invalid access key or secret key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Transaction does not belong to this merchant",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Transaction not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Payment cannot be submitted in this state",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/payout/merchant/api/generate-payout": {
      "post": {
        "operationId": "createPayout",
        "summary": "Create a payout (enabled on request)",
        "externalDocs": {
          "url": "https://docs.royalpe.site/payouts"
        },
        "parameters": [
          {
            "name": "accessKey",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "secretKey",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "amount",
                  "accountNumber",
                  "accountHolderName",
                  "ifscCode",
                  "orderId"
                ],
                "properties": {
                  "amount": {
                    "type": "number",
                    "minimum": 1000
                  },
                  "accountNumber": {
                    "type": "string",
                    "pattern": "^[0-9]{9,18}$"
                  },
                  "accountHolderName": {
                    "type": "string",
                    "pattern": "^[A-Za-z .]{2,100}$"
                  },
                  "ifscCode": {
                    "type": "string",
                    "pattern": "^[A-Za-z]{4}0[A-Za-z0-9]{6}$"
                  },
                  "orderId": {
                    "type": "string"
                  },
                  "remarks": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "callbackUrl": {
                    "type": "string",
                    "format": "uri",
                    "pattern": "^https://"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Payout request generated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "const": true
                    },
                    "message": {
                      "const": "Payout request generated successfully"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "orderId": {
                          "type": "string"
                        },
                        "transactionId": {
                          "type": "string"
                        },
                        "amount": {
                          "type": "number"
                        },
                        "status": {
                          "type": "string",
                          "example": "processing"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request or insufficient balance",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid keys",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Payouts not enabled for this server address",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "orderId reused with different details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/payout/merchant/api/payout-status": {
      "get": {
        "operationId": "getPayoutStatus",
        "summary": "Payout status",
        "externalDocs": {
          "url": "https://docs.royalpe.site/payouts"
        },
        "parameters": [
          {
            "name": "accessKey",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "secretKey",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "transactionId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "orderId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Payout transaction status retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "const": true
                    },
                    "message": {
                      "const": "Payout transaction status retrieved successfully"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "transactionId": {
                          "type": "string"
                        },
                        "orderId": {
                          "type": "string"
                        },
                        "amount": {
                          "type": "number"
                        },
                        "status": {
                          "type": "string"
                        },
                        "remarks": {
                          "type": "string"
                        },
                        "utr": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "transactionId or orderId is required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid keys",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Payouts not enabled for this server address",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Payout transaction not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "webhooks": {
    "payInStatusChanged": {
      "post": {
        "summary": "A pay-in's status changed (pending, approved, rejected, cancelled)",
        "description": "Signed: X-Signature = hex HMAC-SHA256(webhook signing key, X-Event-Id + '.' + X-Timestamp + '.' + raw body). Reject timestamps older than 5 minutes. Answer 2xx within 8 s; otherwise retried with the same X-Event-Id for about 12 hours. Credit once per transactionId, on approved.",
        "externalDocs": {
          "url": "https://docs.royalpe.site/webhooks"
        },
        "parameters": [
          {
            "name": "X-Event-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-Timestamp",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Unix seconds"
            }
          },
          {
            "name": "X-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PayIn"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Received. Any 2xx stops retries."
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "PayInStatus": {
        "type": "string",
        "enum": [
          "progress",
          "pending",
          "approved",
          "rejected",
          "cancelled"
        ],
        "description": "progress: created; pending: proof submitted, verifying; approved: credit once; rejected: not accepted; cancelled: ended before proof (payer cancelled, left the checkout, or it timed out)."
      },
      "PayIn": {
        "type": "object",
        "required": [
          "transactionId",
          "status",
          "amount",
          "orderId",
          "userId",
          "updatedAt"
        ],
        "properties": {
          "transactionId": {
            "type": "string",
            "example": "RP-7f3a9c21d84e5b02"
          },
          "status": {
            "$ref": "#/components/schemas/PayInStatus"
          },
          "amount": {
            "type": "number",
            "description": "Rupees.",
            "example": 500
          },
          "remarks": {
            "type": [
              "string",
              "null"
            ],
            "example": "Payment successful"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "orderId": {
            "type": "string",
            "example": "ORDER-10045"
          },
          "userId": {
            "type": "string",
            "example": "USER-881"
          },
          "utrNumber": {
            "type": [
              "string",
              "null"
            ],
            "example": "531512345678"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "success",
          "message"
        ],
        "properties": {
          "success": {
            "const": false
          },
          "message": {
            "type": "string"
          }
        }
      }
    }
  }
}
