> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dodopayments.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Charge (On-Demand)

> Create a charge for a subscription. This is useful for on-demand billing.



## OpenAPI

````yaml post /subscriptions/{subscription_id}/charge
openapi: 3.1.0
info:
  title: public
  description: ''
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0
  version: 1.102.0
servers:
  - url: https://test.dodopayments.com/
    description: Test Mode Server Host
  - url: https://live.dodopayments.com/
    description: Live Mode Server Host
security: []
tags:
  - name: Products
  - name: Payments
  - name: Subscriptions
  - name: Addons
  - name: Customers
  - name: Refunds
  - name: Disputes
  - name: Events
  - name: License Keys
  - name: Entitlements
  - name: Licenses
  - name: Discounts
  - name: Meters
  - name: Credit Entitlements
  - name: Credit Entitlement Balances
  - name: Outgoing Webhooks
  - name: Checkout
  - name: Webhook Events
paths:
  /subscriptions/{subscription_id}/charge:
    post:
      tags:
        - Subscriptions
      operationId: create_subscription_charge
      parameters:
        - name: subscription_id
          in: path
          description: Subscription Id
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateSubscriptionChargeRequest'
        required: true
      responses:
        '200':
          description: Subscription Charge successfully created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateSubscriptionChargeResponse'
        '422':
          description: Invalid Request Object or Parameters
        '500':
          description: Something went wrong :(
      security:
        - API_KEY: []
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import DodoPayments from 'dodopayments';


            const client = new DodoPayments({
              bearerToken: process.env['DODO_PAYMENTS_API_KEY'], // This is the default and can be omitted
            });


            const response = await
            client.subscriptions.charge('subscription_id', { product_price: 0
            });


            console.log(response.payment_id);
        - lang: Python
          source: |-
            import os
            from dodopayments import DodoPayments

            client = DodoPayments(
                bearer_token=os.environ.get("DODO_PAYMENTS_API_KEY"),  # This is the default and can be omitted
            )
            response = client.subscriptions.charge(
                subscription_id="subscription_id",
                product_price=0,
            )
            print(response.payment_id)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/dodopayments/dodopayments-go\"\n\t\"github.com/dodopayments/dodopayments-go/option\"\n)\n\nfunc main() {\n\tclient := dodopayments.NewClient(\n\t\toption.WithBearerToken(\"My Bearer Token\"),\n\t)\n\tresponse, err := client.Subscriptions.Charge(\n\t\tcontext.TODO(),\n\t\t\"subscription_id\",\n\t\tdodopayments.SubscriptionChargeParams{\n\t\t\tProductPrice: dodopayments.F(int64(0)),\n\t\t},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", response.PaymentID)\n}\n"
        - lang: Java
          source: >-
            package com.dodopayments.api.example;


            import com.dodopayments.api.client.DodoPaymentsClient;

            import com.dodopayments.api.client.okhttp.DodoPaymentsOkHttpClient;

            import
            com.dodopayments.api.models.subscriptions.SubscriptionChargeParams;

            import
            com.dodopayments.api.models.subscriptions.SubscriptionChargeResponse;


            public final class Main {
                private Main() {}

                public static void main(String[] args) {
                    DodoPaymentsClient client = DodoPaymentsOkHttpClient.fromEnv();

                    SubscriptionChargeParams params = SubscriptionChargeParams.builder()
                        .subscriptionId("subscription_id")
                        .productPrice(0)
                        .build();
                    SubscriptionChargeResponse response = client.subscriptions().charge(params);
                }
            }
        - lang: Kotlin
          source: >-
            package com.dodopayments.api.example


            import com.dodopayments.api.client.DodoPaymentsClient

            import com.dodopayments.api.client.okhttp.DodoPaymentsOkHttpClient

            import
            com.dodopayments.api.models.subscriptions.SubscriptionChargeParams

            import
            com.dodopayments.api.models.subscriptions.SubscriptionChargeResponse


            fun main() {
                val client: DodoPaymentsClient = DodoPaymentsOkHttpClient.fromEnv()

                val params: SubscriptionChargeParams = SubscriptionChargeParams.builder()
                    .subscriptionId("subscription_id")
                    .productPrice(0)
                    .build()
                val response: SubscriptionChargeResponse = client.subscriptions().charge(params)
            }
        - lang: Ruby
          source: >-
            require "dodopayments"


            dodo_payments = Dodopayments::Client.new(
              bearer_token: "My Bearer Token",
              environment: "test_mode" # defaults to "live_mode"
            )


            response = dodo_payments.subscriptions.charge("subscription_id",
            product_price: 0)


            puts(response)
        - lang: PHP
          source: |-
            <?php

            require_once dirname(__DIR__) . '/vendor/autoload.php';

            use Dodopayments\Client;
            use Dodopayments\Core\Exceptions\APIException;
            use Dodopayments\Misc\Currency;

            $client = new Client(
              bearerToken: getenv('DODO_PAYMENTS_API_KEY') ?: 'My Bearer Token',
              environment: 'test_mode',
            );

            try {
              $response = $client->subscriptions->charge(
                'subscription_id',
                productPrice: 0,
                adaptiveCurrencyFeesInclusive: true,
                customerBalanceConfig: [
                  'allowCustomerCreditsPurchase' => true,
                  'allowCustomerCreditsUsage' => true,
                ],
                metadata: ['foo' => 'string'],
                productCurrency: Currency::AED,
                productDescription: 'product_description',
              );

              var_dump($response);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: C#
          source: |-
            using System;
            using DodoPayments.Client;
            using DodoPayments.Client.Models.Subscriptions;

            DodoPaymentsClient client = new();

            SubscriptionChargeParams parameters = new()
            {
                SubscriptionID = "subscription_id",
                ProductPrice = 0,
            };

            var response = await client.Subscriptions.Charge(parameters);

            Console.WriteLine(response);
components:
  schemas:
    CreateSubscriptionChargeRequest:
      type: object
      required:
        - product_price
      properties:
        adaptive_currency_fees_inclusive:
          type:
            - boolean
            - 'null'
          description: >-
            Whether adaptive currency fees should be included in the
            product_price (true) or added on top (false).

            This field is ignored if adaptive pricing is not enabled for the
            business.
        customer_balance_config:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/CustomerBalanceConfig'
              description: Specify how customer balance is used for the payment
        metadata:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/Metadata'
              description: >-
                Metadata for the payment. If not passed, the metadata of the
                subscription will be taken
        product_currency:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/Currency'
              description: >-
                Optional currency of the product price. If not specified,
                defaults to the currency of the product.
        product_description:
          type:
            - string
            - 'null'
          description: >-
            Optional product description override for billing and line items.

            If not specified, the stored description of the product will be
            used.
        product_price:
          type: integer
          format: int32
          description: >-
            The product price. Represented in the lowest denomination of the
            currency (e.g., cents for USD).

            For example, to charge $1.00, pass `100`.
    CreateSubscriptionChargeResponse:
      type: object
      required:
        - payment_id
      properties:
        payment_id:
          type: string
    CustomerBalanceConfig:
      type: object
      properties:
        allow_customer_credits_purchase:
          type:
            - boolean
            - 'null'
          description: Allows Customer Credit to be purchased to settle payments
        allow_customer_credits_usage:
          type:
            - boolean
            - 'null'
          description: Allows Customer Credit Balance to be used to settle payments
    Metadata:
      type: object
      additionalProperties:
        type: string
      propertyNames:
        type: string
    Currency:
      type: string
      enum:
        - AED
        - ALL
        - AMD
        - ANG
        - AOA
        - ARS
        - AUD
        - AWG
        - AZN
        - BAM
        - BBD
        - BDT
        - BGN
        - BHD
        - BIF
        - BMD
        - BND
        - BOB
        - BRL
        - BSD
        - BWP
        - BYN
        - BZD
        - CAD
        - CHF
        - CLP
        - CNY
        - COP
        - CRC
        - CUP
        - CVE
        - CZK
        - DJF
        - DKK
        - DOP
        - DZD
        - EGP
        - ETB
        - EUR
        - FJD
        - FKP
        - GBP
        - GEL
        - GHS
        - GIP
        - GMD
        - GNF
        - GTQ
        - GYD
        - HKD
        - HNL
        - HRK
        - HTG
        - HUF
        - IDR
        - ILS
        - INR
        - IQD
        - JMD
        - JOD
        - JPY
        - KES
        - KGS
        - KHR
        - KMF
        - KRW
        - KWD
        - KYD
        - KZT
        - LAK
        - LBP
        - LKR
        - LRD
        - LSL
        - LYD
        - MAD
        - MDL
        - MGA
        - MKD
        - MMK
        - MNT
        - MOP
        - MRU
        - MUR
        - MVR
        - MWK
        - MXN
        - MYR
        - MZN
        - NAD
        - NGN
        - NIO
        - NOK
        - NPR
        - NZD
        - OMR
        - PAB
        - PEN
        - PGK
        - PHP
        - PKR
        - PLN
        - PYG
        - QAR
        - RON
        - RSD
        - RUB
        - RWF
        - SAR
        - SBD
        - SCR
        - SEK
        - SGD
        - SHP
        - SLE
        - SLL
        - SOS
        - SRD
        - SSP
        - STN
        - SVC
        - SZL
        - THB
        - TND
        - TOP
        - TRY
        - TTD
        - TWD
        - TZS
        - UAH
        - UGX
        - USD
        - UYU
        - UZS
        - VES
        - VND
        - VUV
        - WST
        - XAF
        - XCD
        - XOF
        - XPF
        - YER
        - ZAR
        - ZMW
  securitySchemes:
    API_KEY:
      type: http
      scheme: bearer

````