# Collect now

> For the complete machine-readable documentation index, see [llms.txt](https://apidocs.chargebee.com/llms.txt).


[Idempotency Supported](/docs/api/idempotency)

This API generates a hosted page URL to collect due payments for the customer.

Open the hosted page in a new browser tab or window using the `url` from this API's response. Do not embed it in your own [iframe](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/iframe).

**`openCheckout()` not supported**

The Chargebee.js [`openCheckout()`](https://www.chargebee.com/checkout-portal-docs/cbinstanceobj-api-ref.html#opencheckout-options) function does not support Collect Now hosted pages. To open a Collect Now page, open the `url` from this API's response in a new browser tab or window (for example, `window.open(response.hosted_page.url, '_blank')`).

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/hosted_pages/collect_now \
     -u {site_api_key}:\
     -d "customer[id]"="__test__KyVnGlSBWmHH82Pw" \
     -d "card[gateway_account_id]"="gw___test__KyVnGlSBWmAIk2Ph"
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = HostedPage.CollectNow()
		.CustomerId("__test__KyVnGlSBWmHH82Pw")
		.CardGatewayAccountId("gw___test__KyVnGlSBWmAIk2Ph")
		.Request();

HostedPage hostedPage = result.HostedPage;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    hostedpageAction "github.com/chargebee/chargebee-go/v3/actions/hostedpage"
    "github.com/chargebee/chargebee-go/v3/models/hostedpage"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := hostedpageAction.CollectNow(&hostedpage.CollectNowRequestParams{
        Customer : &hostedpage.CollectNowCustomerParams{
            Id : "__test__KyVnGlSBWmHH82Pw",
        },
        Card : &hostedpage.CollectNowCardParams{
            GatewayAccountId : "gw___test__KyVnGlSBWmAIk2Ph",
        },
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        HostedPage := res.HostedPage
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.HostedPageCollectNowRequest{
    Customer : &chargebee.HostedPageCollectNowCustomer{
        Id : "__test__KyVnGlSBWmHH82Pw",
    },
    Card : &chargebee.HostedPageCollectNowCard{
        GatewayAccountId : "gw___test__KyVnGlSBWmAIk2Ph",
    },
}
  res, err := client.HostedPage.CollectNow(req)
      if err != nil {
        fmt.Println(err)
    } else {
        HostedPage := res.HostedPage
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = HostedPage.collectNow()
            .customerId("__test__KyVnGlSBWmHH82Pw")
            .cardGatewayAccountId("gw___test__KyVnGlSBWmAIk2Ph")
            .request();

        HostedPage hostedPage = result.hostedPage();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.hostedPage.HostedPage;
import com.chargebee.v4.models.hostedPage.params.HostedPageCollectNowParams;
import com.chargebee.v4.models.hostedPage.responses.HostedPageCollectNowResponse;

public class HostedPageCollectNow {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        HostedPageCollectNowParams.CustomerParams customerParams =
            HostedPageCollectNowParams.CustomerParams.builder()
                .id("__test__KyVnGlSBWmHH82Pw")
                .build();

        HostedPageCollectNowParams.CardParams cardParams =
            HostedPageCollectNowParams.CardParams.builder()
                .gatewayAccountId("gw___test__KyVnGlSBWmAIk2Ph")
                .build();

        HostedPageCollectNowParams params = HostedPageCollectNowParams.builder()
            .customer(customerParams)
            .card(cardParams)
            .build();

        HostedPageCollectNowResponse response = client.hostedPages().collectNow(params);

        HostedPage hostedPage = response.getHostedPage();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.hostedPage.collectNow({
        customer: {
            id: "__test__KyVnGlSBWmHH82Pw"
        },
        card: {
            gateway_account_id: "gw___test__KyVnGlSBWmAIk2Ph"
        }
    });

    console.log(result);
    const hostedPage = result.hosted_page;
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->hostedPage()->collectNow([
    "customer" => [
        "id" => "__test__KyVnGlSBWmHH82Pw"
    ],
    "card" => [
        "gateway_account_id" => "gw___test__KyVnGlSBWmAIk2Ph"
    ]
]);
$hostedPage = $result->hosted_page;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.HostedPage.collect_now(
    cb_client.HostedPage.CollectNowParams(
        customer=cb_client.HostedPage.CollectNowCustomerParams(
            id="__test__KyVnGlSBWmHH82Pw"
        ),
        card=cb_client.HostedPage.CollectNowCardParams(
            gateway_account_id="gw___test__KyVnGlSBWmAIk2Ph"
        )
    )
)
hosted_page = response.hosted_page
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

result = ChargeBee::HostedPage.collect_now({
  :customer => {
    :id => "__test__KyVnGlSBWmHH82Pw"
  },
  :card => {
    :gateway_account_id => "gw___test__KyVnGlSBWmAIk2Ph"
  }
})

hosted_page = result.hosted_page
```

## Sample Response

```json
{
  "hosted_page": {
    "created_at": 1517506010,
    "embed": true,
    "expires_at": 1517592410,
    "id": "__test__4cq9mwW1cuoD085nSBLh0KUMKdphVO5cC",
    "object": "hosted_page",
    "resource_version": 1517506010000,
    "state": "created",
    "type": "collect_now",
    "updated_at": 1517506010,
    "url": "https://yourapp.chargebee.com/pages/v3/__test__4cq9mwW1cuoD085nSBLh0KUMKdphVO5cC/collect_now"
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/hosted_pages/collect_now

## Input Parameters

- `brand_id` (optional, string, max chars=50)
  The unique ID of the [brand](/docs/api/brands) this hosted page should be linked to. Applicable only when multiple brands have been created for the site. This need not match the brand of the customer or subscription in the request; when the two differ, the value provided here is used for the hosted page. An alternative way of passing this parameter is by means of the `chargebee-brand-id` custom HTTP header; when both are provided, they must specify the same brand.
  
  **Default behavior**
  
  -   When not provided, the hosted page is linked to the brand of the customer or subscription in the request.

- `redirect_url` (optional, string, max chars=250)
  Used to specify the destination URL to which a user is redirected after invoices are paid. The [transaction ID](/docs/api/transactions/transaction-object#id) of the transactions made through the Pay Now hosted page will be sent as return variables along with the URL.

- `currency_code` (optional, string, max chars=3)
  The currency code (ISO 4217 format) of the specified _credit amount_ .

- `payment_method_save_policy` (optional, enumerated string)
  Determines whether the payment method should be saved to the customer's account.
  Possible enum values:
    - `always`
      Automatically save the payment method to the customer's account for future use.
    - `ask`
      Let the customer choose whether to save the payment method.
    - `never`
      Do not save the payment method.

- `customer` (optional, string)
  Parameters for customer
  - `id` (required, string, max chars=50)
    Identifier of the customer.

- `card` (optional, string)
  Parameters for card
  - `gateway_account_id` (optional, string, max chars=50)
    The gateway account in which this payment source is stored.

## Returns

- `hosted_page` (Hosted page object)
  Resource object representing hosted\_page
