# Developer Integration Guide

Welcome to the **BagelPay Developer Interaction Guide** - built to help you seamlessly integrate secure, scalable, and customizable payment solutions into your stack.

{% hint style="info" %}
It is highly recommended that developers conduct initial testing in **Test Mode**.
{% endhint %}

## Integration Steps <a href="#integration-steps" id="integration-steps"></a>

Follow these steps to integrate BagelPay API:

<details>

<summary>Step1: <a href="../../getting-started/quick-start-guide#step-1-login-to-your-account">Set up your account</a></summary>

Log in using your email or sign in with Google. If you don’t have an account yet, you can create one at <https://app.bagelpay.io/login>.

<figure><img src="https://2715164374-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVrvPnQUpsDkMiL1jMEXt%2Fuploads%2FqnbhV7exZwJaTV9edLt9%2Fimage.png?alt=media&#x26;token=c2130cc6-7feb-42b5-b969-2d0528ab7dd4" alt=""><figcaption></figcaption></figure>

</details>

<details>

<summary>Step2: Switch to Test Mode</summary>

It is strongly recommended that you familiarize yourself with the product configuration and API integration in test mode before switching to the production environment.

&#x20;**In Test Mode, all the operations and transactions are in sandbox.**

<figure><img src="https://2715164374-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVrvPnQUpsDkMiL1jMEXt%2Fuploads%2FsRSufT8B6P5tAgYnIfBQ%2Fimage.png?alt=media&#x26;token=e1d0f152-4a76-4414-8171-d091f101a0f6" alt=""><figcaption></figcaption></figure>

</details>

<details>

<summary>Step3: <a href="../../getting-started/quick-start-guide#step-2-create-your-api-key">Get your API keys</a></summary>

API Keys are secret tokens used to authenticate your requests. They are unique to your account and should be kept confidential.

* **On the top navbar, navigate to the “Developer” section.**

<figure><img src="https://2715164374-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVrvPnQUpsDkMiL1jMEXt%2Fuploads%2FFIdZanNJ7dpCxelz1Zo9%2Fimage.png?alt=media&#x26;token=21687e96-0b47-44bf-9ff2-642d0d8dddcd" alt=""><figcaption></figcaption></figure>

* **Click on the "Create api key" button in the "API Keys" tab.**

<figure><img src="https://2715164374-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVrvPnQUpsDkMiL1jMEXt%2Fuploads%2FLZspJ7l9A8k9Cqo5aJGX%2Fimage.png?alt=media&#x26;token=ea6b83a7-feda-4ff2-832f-8c6a5bef0612" alt=""><figcaption></figcaption></figure>

* **Copy your API key and keep it safe.**

</details>

<details>

<summary>Step4: Create your first product</summary>

<figure><img src="https://2715164374-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVrvPnQUpsDkMiL1jMEXt%2Fuploads%2FZAha3zZMqusp1SKYUFIr%2Fimage.png?alt=media&#x26;token=af022030-cf7a-41db-977b-14ccde3c9793" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2715164374-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVrvPnQUpsDkMiL1jMEXt%2Fuploads%2FapMZUhI93h8lPLBBJmNK%2Fimage.png?alt=media&#x26;token=bbded2f2-5b4f-4c77-9aa0-8bfe46940e8d" alt=""><figcaption></figcaption></figure>

The step by step guides below will help you understand how to add **One Time Payment products** and **Subscription products**.

[**Add One Time Payment Product**](https://bagelpay.gitbook.io/docs/documentation/features/editor) **(**[editor](https://bagelpay.gitbook.io/docs/documentation/features/editor "mention"))

[**Add Subscription Product**](https://bagelpay.gitbook.io/docs/documentation/features/markdown) **(**[markdown](https://bagelpay.gitbook.io/docs/documentation/features/markdown "mention"))

</details>

<details>

<summary>Step5: List all the product</summary>

You can list all the products [through the API](https://bagelpay.gitbook.io/docs/documentation/products#list-products).

</details>

<details>

<summary>Step6: Get the product detail</summary>

You can get the product detail [through the API](https://bagelpay.gitbook.io/docs/documentation/products#get-product-detail).

</details>

<details>

<summary>Step7: <a href="../checkout-session#create-single-pay-checkout-session">Create checkout sessions</a> for each payment and user independently.</summary>

With checkout sessions generated dynamically instead of just using a product payment link, you are able to pass a `request_id` to the session. This allows you to track the payment status and the user that made the payment in your system in a more organized way, and gives you the flexibility to track that payment with any ID you choose instead of relying on BagelPay IDs.

* Create a new api key

<figure><img src="https://2715164374-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVrvPnQUpsDkMiL1jMEXt%2Fuploads%2FxjErMSwMpVQJKoNU3tW2%2Fimage.png?alt=media&#x26;token=8b822cef-f9c3-4329-a5aa-17b7b9f4d3bf" alt=""><figcaption></figcaption></figure>

* Copy the product id

<figure><img src="https://2715164374-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVrvPnQUpsDkMiL1jMEXt%2Fuploads%2FbNPVAfwxJA5y3UPAfVwI%2Fimage.png?alt=media&#x26;token=623e5281-d174-4536-bf2a-5ff5f5d42c2f" alt=""><figcaption></figcaption></figure>

* Request the payment gateway

```sh
curl --request POST \
  --url https://test.bagelpay.io/api/payments/checkouts \
  --header 'x-api-key: bagel_test_609C0CF4D5F64CC7910D26D9DF3A834B' \
  --header 'Content-Type: application/json' \
  --data '{
    "product_id": "prod_1961350758759763969",
    "request_id": "request_123456789",
    "units": 1,
    "customer": {
        "email": "user@example.com"
    },
    "metadata": {
        "key_1": "value_1",
        "key_2": "value_1",
        "key_N": "value_N"
    }
}'
```

The response is like below:

```json
{
	"msg": "Operation successful",
	"code": 200,
	"data": {
		"object": "checkout",
		"units": 1,
		"metadata": {
			"key_1": "value_1",
			"key_2": "value_1",
			"key_N": "value_N"
		},
		"status": "pending",
		"mode": "test",
		"payment_id": "ch_1961373726999154689",
		"product_id": "prod_1961350758759763969",
		"request_id": null,
		"success_url": "https://test.bagelpay.io/success?aggregateId=XXXX",
		"checkout_url": "https://test.bagelpay.io/checkout/prod_1961350758759763969/ch_1961373726999154689",
		"created_at": "2025-08-29T10:21:51.773+00:00",
		"updated_at": "2025-08-29T10:21:51.773+00:00",
		"expires_on": "2025-08-29T11:21:51.773+00:00"
	}
}
```

The above request will return a checkout session object with a `checkout_url` that you can use to redirect the user to the payment page.

{% hint style="info" %}
checkout\_url example:

```url
https://test.bagelpay.io/checkout/prod_1961350758759763969/ch_1961373726999154689
```

{% endhint %}

<figure><img src="https://2715164374-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVrvPnQUpsDkMiL1jMEXt%2Fuploads%2FefJVsGuBrvLIhzoSy4LP%2Fimage.png?alt=media&#x26;token=2afcaa8f-68de-4fc2-bf71-75b26103e3f7" alt=""><figcaption></figcaption></figure>

</details>

<details>

<summary>Step8: <a href="webhooks/webhook-user-guide">Set up webhooks</a> for real-time updates</summary>

BaygelPay uses webhooks to push real-time notifications to you about your payments, subscriptions and refund. All webhooks use HTTPS and deliver a JSON payload that can be used by your application.

For the API details, please refer to the "[Webhook User Guide](https://bagelpay.gitbook.io/docs/documentation/webhooks/webhook-user-guide#steps-to-receive-a-webhook)".

</details>

<details>

<summary>Step9: Testing the checkout session</summary>

For testing payments, you could use the test card `4242 4242 4242 4242` with any expiration and CVV.

<figure><img src="https://2715164374-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVrvPnQUpsDkMiL1jMEXt%2Fuploads%2FrH3BKndmY6sl2E6B2HkK%2Fimage.png?alt=media&#x26;token=76f408a3-3162-40ef-8c55-a40582e7f1df" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2715164374-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVrvPnQUpsDkMiL1jMEXt%2Fuploads%2FJl1ACCfCeq0HrogM4ts6%2Fimage.png?alt=media&#x26;token=b5bddb1c-5c67-438b-b395-eb10b5ce5b07" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2715164374-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVrvPnQUpsDkMiL1jMEXt%2Fuploads%2FilrbVBh2GE3MMEP7xfBX%2Fimage.png?alt=media&#x26;token=45253317-4e99-4e4e-89d3-2c235a7fbcf8" alt=""><figcaption></figcaption></figure>

</details>

<details>

<summary>Step13: Go through the Transactions and Balance</summary>

<figure><img src="https://2715164374-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVrvPnQUpsDkMiL1jMEXt%2Fuploads%2FFjEYedLaDA6C9xGq0M89%2Fimage.png?alt=media&#x26;token=5c1e41ec-80ad-4db5-a362-ce92f4bb062d" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2715164374-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVrvPnQUpsDkMiL1jMEXt%2Fuploads%2FTXc3tZnrj14GRR4d0teF%2Fimage.png?alt=media&#x26;token=d152db1e-6f02-4aae-9a84-bf466e3baec5" alt=""><figcaption></figcaption></figure>

</details>

<details>

<summary><strong>Step14: Switching from Sandbox Mode to Live Mode</strong></summary>

Once you've successfully completed the payment, payout processes, and API integration in Test Mode, you can begin moving your code to Live Mode.

You do not need to modify your existing business logic or code. Simply follow these steps:

1. **Recreate Product in Live Mode**

   * Copy the `product` you set up in Test Mode and recreate the same product configuration in Live Mode.

   <figure><img src="https://2715164374-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVrvPnQUpsDkMiL1jMEXt%2Fuploads%2FxfPIiT7Ql06ExtyhYjGJ%2Fimage.png?alt=media&#x26;token=cf9c6f58-916c-4a95-a3e9-47c977c880fe" alt=""><figcaption></figcaption></figure>
2. **Recreate New Webhook and API Keys**

* Create a `new Webhook` in Live mode.
* Generate a `new API Key` and Signing Secret.
* Replace the API Key and Signing Secret in your system with the newly generated credentials for the Live Mode.

<figure><img src="https://2715164374-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVrvPnQUpsDkMiL1jMEXt%2Fuploads%2F0ZfM5899fBwRoxgbMsSy%2Fimage.png?alt=media&#x26;token=700bca3c-1ad3-4075-8ced-5994359b0517" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2715164374-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVrvPnQUpsDkMiL1jMEXt%2Fuploads%2FBECgSbDSLeKqVnBDmtSq%2Fimage.png?alt=media&#x26;token=34a39218-9f9f-426c-a19f-22a910c5630e" alt=""><figcaption></figcaption></figure>

3. **Update the base URL**

Change the base URL in your code from `test.bagelpay.io` to `live.bagelpay.io`

<figure><img src="https://2715164374-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVrvPnQUpsDkMiL1jMEXt%2Fuploads%2Ft9P6C8bvgWfJwnRCA4RI%2Fimage.png?alt=media&#x26;token=64d3b33d-0437-4724-a163-26b05b64907b" alt=""><figcaption></figcaption></figure>

`Product IDs`, `API keys`, and `webhook URLs` are completely separate and isolated between Test Mode and Live Mode environments.

4. **Update the Webhook、API Key and Signing Secret**.

Replace the API Key and Signing Secret in your system with the newly generated API Key  for the Live Mode.

{% hint style="info" %}
👏🏻 Once the above steps are completed, your application will be fully operational in Live Mode — with no changes required to your existing code logic.
{% endhint %}

</details>

## Environment URLs

Use the appropriate base URL for your environment:

* Test Mode: [`https://test.bagelpay.io`](https://test.bagelpay.io/)
* Live Mode: [`https://live.bagelpay.io`](https://live.bagelpay.io/)

Learn more about [Test Mode vs Live Mode](https://bagelpay.gitbook.io/docs/documentation/testing-mode/test-mode-vs-live-mode).

## Response codes <a href="#response-codes" id="response-codes"></a>

Bagel uses standard HTTP codes to indicate the success or failure of your requests.

In general, 2xx HTTP codes correspond to success, 4xx codes are for user-related failures, and 5xx codes are for infrastructure issues.

| Status | Description                             |
| ------ | --------------------------------------- |
| 200    | Successful request.                     |
| 400    | Check that the parameters were correct. |
| 401    | The API key used was missing.           |
| 403    | The API key used was invalid.           |
| 404    | The resource was not found.             |
| 429    | The rate limit was exceeded.            |
| 500    | Indicates an error from servers.        |

## Need Help? <a href="#need-help-3f" id="need-help-3f"></a>

If you need more support or would like to talk to our experts, you can book a [Google meeting](https://calendar.app.google/9LWwo3taQm9syzCr8) or join our [Discord](https://discord.com/invite/9WZfxfzjb8) or join our [X](https://x.com/BagelPayment).

Feel free to join 3,000+ digital businesses using Bagel Payments to sell globally, without borders or bottlenecks.

[Request a Demo](https://calendar.app.google/iWMHiFpMhutQfmTt8) | [Talk to Sales](mailto:sales@bagelpayment.com)
