> For the complete documentation index, see [llms.txt](https://aplazo.gitbook.io/aplazo-integrations/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://aplazo.gitbook.io/aplazo-integrations/api-reference/online-api/create-a-payment.md).

# Create a payment

{% hint style="info" %}
Throughout this documentation, the terms "**payment**," "**loan**," and "**order**" are used interchangeably to refer to the same concept.
{% endhint %}

## Environments

{% tabs %}
{% tab title="Development" %}
<https://api.aplazo.net/api>
{% endtab %}

{% tab title="Production" %}
<https://api.aplazo.mx/api>
{% endtab %}
{% endtabs %}

## Create a loan or payment

> Initiates an Aplazo loan request or payment, generating a checkout URL for the merchant's customer.

```json
{"openapi":"3.0.3","info":{"title":"Aplazo Online API","version":"1.0.0"},"servers":[{"url":"https://api.aplazo.net/api"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}}},"paths":{"/loan":{"post":{"summary":"Create a loan or payment","description":"Initiates an Aplazo loan request or payment, generating a checkout URL for the merchant's customer.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["totalPrice","shopId","cartId","successUrl","errorUrl","cartUrl","webHookUrl","buyer","products","discount","shipping","taxes"],"properties":{"totalPrice":{"type":"number","description":"Total price of the cart or order."},"shopId":{"type":"string","description":"Identifier for the merchant's shop."},"cartId":{"type":"string","description":"Unique identifier for the shopping cart. Works as the merchant's external identifier."},"successUrl":{"type":"string","format":"uri","description":"URL to redirect the customer upon successful payment."},"errorUrl":{"type":"string","format":"uri","description":"URL to redirect the customer upon payment failure."},"cartUrl":{"type":"string","format":"uri","description":"URL for the customer's cart."},"webHookUrl":{"type":"string","format":"uri","description":"URL for webhook notifications related to the loan."},"buyer":{"type":"object","description":"Information about the buyer placing the order.","properties":{"addressLine":{"type":"string","description":"Buyer's address."},"email":{"type":"string","format":"email","description":"Buyer's email address."},"firstName":{"type":"string","description":"Buyer's first name."},"lastName":{"type":"string","description":"Buyer's last name."},"loan_id":{"type":"integer","description":"Identifier for the loan. Not necessary, use any value."},"phone":{"type":"string","description":"Buyer's phone number."},"postalCode":{"type":"string","description":"Buyer's postal code."}}},"products":{"type":"array","description":"List of products included in the loan.","items":{"type":"object","properties":{"count":{"type":"integer","description":"Quantity of the product."},"description":{"type":"string","description":"Description of the product."},"id":{"type":"string","description":"Product identifier."},"imageUrl":{"type":"string","format":"uri","description":"URL of the product image."},"price":{"type":"number","description":"Price of the product."},"title":{"type":"string","description":"Name of the product."}}}},"discount":{"type":"object","description":"Discount applied to the cart.","properties":{"price":{"type":"number","description":"Discount amount."},"title":{"type":"string","description":"Title or reason for the discount."}}},"shipping":{"type":"object","description":"Shipping details for the cart.","properties":{"price":{"type":"number","description":"Shipping cost."},"title":{"type":"string","description":"Shipping method or title."}}},"taxes":{"type":"object","description":"Taxes applied to the cart.","properties":{"price":{"type":"number","description":"Tax amount."},"title":{"type":"string","description":"Tax description."}}}}}}}},"responses":{"200":{"description":"Loan created successfully. Returns a checkout URL for the customer.","content":{"application/json":{"schema":{"type":"object","properties":{"url":{"type":"string","format":"uri","description":"Checkout URL for the customer to complete the BNPL process."},"loanId":{"type":"string","description":"UUID for the created loan."},"loanToken":{"type":"string","description":"Token associated with the created loan."}}}}}},"400":{"description":"Bad request. Missing or wrong required fields.","content":{"application/json":{}}}},"tags":["Loans"]}}}}
```

## Response Examples

### Success

<details>

<summary><mark style="color:green;">200</mark> - Successful Loan Creation</summary>

{% code title="Response: 200 OK" overflow="wrap" %}

```json
{
  "url": "https://checkout.aplazo.net/main/1777a4f6-da5e-4787-9956-40467dd0c37e",
  "loanId": 156123,
  "loanToken": "1777a4f6-da5e-4787-9956-40467dd0c37e"
}
```

{% endcode %}

</details>

### Errors

<details>

<summary><mark style="color:red;">400</mark> - An <code>ACTIVO</code> status loan with the same <code>cartId</code> already exists</summary>

{% code title="Response: 400 Bad Request" %}

```json
{
    "status": 0,
    "error": "OUTSTANDING_LOAN_ALREADY_EXISTS",
    "message": "Outstanding loan with cartId: cart-id-321 already exists"
}
```

{% endcode %}

</details>

<details>

<summary><mark style="color:red;">400</mark> - Invalid data type</summary>

{% code title="Response: 400 Bad Request" %}

```json
```

{% endcode %}

</details>

<details>

<summary><mark style="color:red;">403</mark> - Invalid Authentication token</summary>

{% code title="Response: 403 Forbidden" %}

```json
```

{% endcode %}

</details>

<details>

<summary><mark style="color:red;">500</mark> - Missing field or parameter</summary>

{% code title="Response: 500 Internal Server Error" %}

```json
{
    "timestamp": "2025-01-06T17:27:52.605+00:00",
    "status": 500,
    "error": "Internal Server Error",
    "path": "/api/loan"
}
```

{% endcode %}

</details>
